ModbusConnection

ModbusConnection

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

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 | 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[AnyNode, 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 | 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 subsription.

NodeModbus

class eta_utility.connectors.node.NodeModbus(name: str, url: str, protocol: str, *args: Any, **kwargs: Any)[source]

Node for the Modbus protocol.

mb_slave: int | None

Modbus Slave ID

mb_register: str

Modbus Register name. One of input, discrete_input, coils and holding. Note that only coils and holding can be written to.

mb_channel: int

Modbus Channel (Address of the value)

mb_bit_length: int

Length of the value in bits (default 32). This determines, how much data is read from the server. The value must be a multiple of 16.

mb_byteorder: str

Byteorder of values returned by modbus

mb_wordorder: str

Wordorder of values returned by modbus

name: str

Name for the node.

url: str

URL of the connection.

url_parsed: ParseResult

Parse result object of the URL (in case more post-processing is required).

usr: str | None

Username for login to the connection (default: None).

pwd: str | None

Password for login to the connection (default: None).

interval: str | None

Interval

dtype: Callable | None

Data type of the node (for value conversion). Note that strings will be interpreted as utf-8 encoded. If you do not want this behaviour, use ‘bytes’.