Modbus Connection
ModbusConnection
- class eta_nexus.connections.ModbusConnection(url: str, usr: str | None = None, pwd: str | None = None, *, nodes: Nodes[ModbusNode] | 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.
- logger: Logger = <Logger eta_nexus.connections.modbus_connection (WARNING)>
- connection: ModbusClient
- 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.
- url_parsed: ParseResult
URL of the server to connect to
- exc: BaseException | None
ModbusNode
- class eta_nexus.nodes.ModbusNode(name: str, url: str, protocol: str, *args: Any, **kwargs: Any)[source]
Node for the Modbus protocol.
- 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
- decode_modbus_value(value: Sequence[int]) Any[source]
Decode incoming modbus values.
Strings are always decoded as utf-8 values. If you do not want this behaviour, specify ‘bytes’ as the data type for the Node.
- Parameters:
value – Current value to be decoded
- Returns:
Decoded value as the Node’s data type.
- encode_bits(value: Primitive) list[int][source]
Encode python data type to modbus value. This means an array of bytes to send to a modbus server.
- Parameters:
value – Current value to be decoded into float.
- Returns:
Decoded value as a python type.
- connection_identifier() str
Unique identifier for the connection that is associated with the node (i.e. would be created by Connection.from_node())
- 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).
- 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’.