moddef.pymodbus module¶
pymodbus adapter: implements the moddef [Transport] protocol over a pymodbus 3.x async client (spec §32.3). Install with pip install moddef[pymodbus].
Constructors: [PymodbusTransport.tcp], [PymodbusTransport.serial] (RTU), or wrap any connected pymodbus async client directly.
Reads are chunked to honor [Options.max_read_words] (Modbus caps a read at 125 registers; devices like the SDM630/EM24 need less — the same knob as the TS/Rust adapters).
Every request runs under [Options.timeout] (asyncio.timeout).
Modbus exception responses raise [ModbusExceptionError] carrying the device’s exception code.
One in-flight request per transport: Modbus is a serial request/response channel; concurrent access is a caller decision (e.g. an asyncio.Lock).
- exception moddef.pymodbus.ModbusExceptionError(exception_code: int)[source]¶
Bases:
ModDefErrorThe device answered a Modbus exception (illegal address, busy, …).
- exception moddef.pymodbus.ModbusTimeoutError[source]¶
Bases:
ModDefError[Options.timeout] elapsed before the device answered.
- class moddef.pymodbus.Options(unit_id: int = 1, timeout: float | None = 5.0, max_read_words: int = 125)[source]¶
Bases:
objectConnection options shared by all constructors.
- max_read_words: int = 125¶
- timeout: float | None = 5.0¶
- unit_id: int = 1¶
- class moddef.pymodbus.PymodbusTransport(client, options: Options | None = None)[source]¶
Bases:
objectmoddef Transport over a pymodbus async client.
- async classmethod serial(port: str, baudrate: int = 9600, options: Options | None = None, **serial_kwargs) PymodbusTransport[source]¶
Modbus RTU over a serial port (parity/stopbits via serial_kwargs).
- async classmethod tcp(host: str, port: int = 502, options: Options | None = None) PymodbusTransport[source]¶