eta_utility.servers.modbus module

class eta_utility.servers.modbus.ModbusServer(ip: str | None = None, port: int = 502, big_endian: bool = True)[source]

Bases: object

Provides a Modbus server with a number of specified nodes.

When building a data structure make sure to consider the following. Numbers (integers and flaots) will be stored depending on the byte_length setting of the Modbus node. This is 2 by default and means that each number will take up 16 bits. This affects, how many “channels” are needed for each number. You have to ensure not to overwrite parts of a number by leaving enough channels after the start of a number empty.

Parameters:
  • ip – IP Address to listen on (default: None).

  • port – Port to listen on (default: 502).

  • big_endian – The server will encode values as big endian by default. If you would like to have little endian encoding instead, set this to False.

url: str

URL of the Modbus Server.

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

Write some values directly to the Modbus server. This function supports writing int, float and string objects. If you have another object, convert it to bytes before writing.

Parameters:

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

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

Read some manually selected values directly from the Modbusserver.

Parameters:

nodes – List of nodes to read from.

Returns:

pandas.DataFrame containing current values of the Modbus-variables.

Raises:

RuntimeError – When an error occurs during reading.

start() None[source]

Restart the server after it was stopped.

stop() None[source]

This should always be called, when the server is not needed anymore. It stops the server.

property active: bool