5.3.1.17.4.1. cli.com.modbus_com.Modbus
- class cli.com.modbus_com.Modbus(name: str, parameter: ModbusParameter)
Bases:
ComInterfaceHigh-level adapter for Modbus process-based communication.
This class manages the lifecycle of a ModbusProcess and provides queue-based read/write methods for commands and results.
- read(block: bool = False, timeout: float | None = None) dict | None
Read a result dictionary from the output queue.
- Parameters:
block (bool) – Whether to block until a result is available.
timeout (float | None) – Optional timeout (seconds) when blocking.
- Returns:
A command/result dictionary (including ‘values’) if available, otherwise None.
- Return type:
dict | None
Notes
Returns None if the process is not alive and the output queue is empty, to avoid blocking forever.
- write(command: dict) None
Send a Modbus command to the input queue for execution.
- Parameters:
command (dict) – The Modbus command as a dictionary. Expected keys: ‘date’, ‘code’, ‘address’, ‘length’, ‘values’.
- Raises:
RuntimeError – If the Modbus process is not running.