eta_nexus.connections.modbus_connection module
Utilities for connecting to modbus servers.
- class eta_nexus.connections.modbus_connection.ModbusConnection(url: str, usr: str | None = None, pwd: str | None = None, *, nodes: Nodes[ModbusNode] | None = None)[source]
Bases:
Connection[ModbusNode],StatusReadable[ModbusNode],StatusWritable[ModbusNode],StatusSubscribable[ModbusNode]The Modbus Connection class allows reading and writing from and to Modbus servers and clients. Additionally, it implements a subscription service, which reads continuously in a specified interval.
- Parameters:
url – URL of the Modbus Server.
usr – No login supported, only here to satisfy the interface
pwd – No login supported, only here to satisfy the interface
nodes – List of nodes to use for all operations.
- logger: Logger = <Logger eta_nexus.connections.modbus_connection (WARNING)>
- read(nodes: ModbusNode | Nodes[ModbusNode] | None = None) pd.DataFrame[source]
Read some manually selected nodes from Modbus server.
- Parameters:
nodes – Single node or list/set of nodes to read from.
- Returns:
Dictionary containing current values of the Modbus variables.
- write(values: Mapping[ModbusNode, Primitive]) None[source]
Write some manually selected values on Modbus capable controller.
- Parameters:
values – Dictionary of nodes and data to write {node: value}.
- subscribe(handler: SubscriptionHandler, nodes: ModbusNode | Nodes[ModbusNode] | None = None, interval: TimeStep = 1) None[source]
Subscribe to nodes and call handler when new data is available. Basic architecture of the subscription is the client- server communication. This function works asynchronously.
- Parameters:
nodes – Single node or list/set of nodes to subscribe to.
handler – SubscriptionHandler object with a push method that accepts node, value pairs.
interval – Interval for receiving new data. It is interpreted as seconds when given as an integer.