drivers.PyModbus.PyModbus

Modbus client wrapper for Oizom IoT sensor drivers.

Centralizes Modbus communications for all driver consumers in the Oizom firmware by wrapping the pymodbus library. Exposes a Modbus server (TCP or RTU over RS-485) that holds a configurable bank of 32-bit IEEE-754 float registers which the firmware updates on every sensing cycle so that external SCADA, PLC, and gateway clients can poll the latest sensor values.

This module is a utility (not a sensor driver) and is shared by all Modbus-based sensor drivers in drivers that need to publish data to upstream Modbus masters.

Example

>>> from drivers.PyModbus.PyModbus import PyModbus
>>> server = PyModbus(size=20)
>>> ctx = server.build_context(slaveId=1, fixId=True)
>>> server.update_data(1, 3, 0, 23.5)
>>> server.run_tcp_server("0.0.0.0", 5020)

Note

Two transports are supported and chosen at runtime by the consumer:

Four common Modbus register types are pre-allocated by PyModbus.build_context():

  • di - Discrete Inputs (read-only bits, function code 0x02).

  • co - Coils (read/write bits, function codes 0x01 / 0x05 / 0x0F).

  • hr - Holding Registers (read/write 16-bit words, codes 0x03 / 0x06 / 0x10). Used to publish 32-bit floats as register pairs.

  • ir - Input Registers (read-only 16-bit words, code 0x04).

See pymodbus for the underlying protocol implementation and consumer drivers under drivers for usage patterns.

Attributes

Classes

PyModbus

Modbus server wrapper for exposing sensor data over TCP or RTU.

Module Contents

drivers.PyModbus.PyModbus.basic_logger
drivers.PyModbus.PyModbus.context_logger
drivers.PyModbus.PyModbus.pymodbus