eta_utility.connectors.modbus module

Utilities for connecting to modbus servers

class eta_utility.connectors.modbus.ModbusConnection(url: str, usr: str | None = None, pwd: str | None = None, *, nodes: Nodes[NodeModbus] | None = None)[source]

Bases: Connection[NodeModbus]

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.

read(nodes: Nodes[NodeModbus] | None = None) pd.DataFrame[source]

Read some manually selected nodes from Modbus server.

Parameters:

nodes – List of nodes to read from.

Returns:

Dictionary containing current values of the Modbus variables.

write(values: Mapping[NodeModbus, Any]) None[source]

Write some manually selected values on Modbus capable controller.

Warning

This is not implemented.

Parameters:

values – Dictionary of nodes and data to write {node: value}.

subscribe(handler: SubscriptionHandler, nodes: Nodes[NodeModbus] | 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 – Identifiers for the 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.

close_sub() None[source]

Close the subscription.