ModbusDevice#
- class ModbusDevice(
- config: ModbusConfig | dict | Path | str,
- connection: ModbusTransport | dict | None = None,
- name: str | None = None,
- publishers: list[Publisher] | None = None,
- autostart: bool = False,
- unit_id: int | None = None,
- **kwargs,
Bases:
InstrumentConfig-driven Modbus client. Semantic access by register alias from a
ModbusConfig.Initialize a ModbusDevice.
- Parameters:
config – A
ModbusConfig, a dict (validated via Pydantic), or a path to a JSON config.connection – Overrides
config.connection. Accepts aModbusTransport(pass the same instance to several devices to share one line;unit_idis then required), or a dict (withtransport="tcp"/"rtu"), which builds a private transport. Required if the config has noconnectionsection.name – Channel-name prefix; falls back to
config.device.name.publishers – Publishers that receive emitted Measurement/Command data.
autostart – When True, open the connection and start background polling. Requires a
timingsection (withpoll_interval) — passingautostart=Truewithout one is an error.unit_id – Modbus unit/slave address (0-255; 0-247 on serial). May also come from the connection block’s
unit_idfield; values given in both places must agree. Required alongside a shared transport; defaults to 1 when this device builds its own private transport.**kwargs – Default tags applied to every emitted Measurement/Command.
- Raises:
ValueError – No connection in args or config, an address that is missing, conflicting, or out of range, or
autostart=Truewith notimingsection.
Attributes
Seconds between background daemon iterations (0 = no wait). |
|
Return an insertion-ordered snapshot of all published channel names. |
|
set once at construction, via the constructor kwarg or the config. |
Methods
Append |
|
Register a publisher to receive this instrument's Measurement/Command data. |
|
Release this device's hold on the transport and stop the daemon; the line closes when the last device leaves. |
|
Replace all daemon functions with a single |
|
Return the most recent |
|
Return the most recent sample for |
|
Open the Modbus TCP/RTU connection, registering this device as an owner of the transport. |
|
Fan |
|
Read the register named |
|
Start the background daemon thread. |
|
Signal the background daemon to stop and join it. |
|
Write |