Servers

The servers module in eta_utility can be used to easily create servers. For example, the OPC UA Server class enables the creation of an OPC UA server with simple variable access. The server interface is similar to the connection interface, which makes it easy to access a server instead of a connection, for example to publish values directly.

class eta_utility.servers.OpcUaServer(namespace: str | int, ip: str | None = None, port: int = 4840)[source]

Provides an OPC UA server with a number of specified nodes. Each node can contain single values or arrays.

Parameters:
  • namespace – Namespace of the OPC UA Server.

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

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

url: str

URL of the OPC UA Server.

idx: int

idx: Namespace of the OPC UA _server

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

Write some values directly to the OPC UA server.

Parameters:

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

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

Read some manually selected values directly from the OPC UA server.

Parameters:

nodes – List of nodes to read from.

Returns:

pandas.DataFrame containing current values of the OPC UA-variables.

Raises:

RuntimeError – When an error occurs during reading.

create_nodes(nodes: Nodes[NodeOpcUa]) None[source]

Create nodes on the server from a list of nodes. This will try to create the entire node path.

Parameters:

nodes – List or set of nodes to create.

delete_nodes(nodes: Nodes[NodeOpcUa]) None[source]

Delete the given nodes and their parents (if the parents do not have other children).

Parameters:

nodes – List or set of nodes to be deleted.

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
allow_remote_admin(allow: bool) None[source]

Allow remote administration of the server.

Parameters:

allow – Set to true to enable remote administration of the server.

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

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