eta_nexus.connections.opcua_connection module
The OPC UA module provides utilities for the flexible creation of OPC UA connections.
- class eta_nexus.connections.opcua_connection.OpcuaConnection(url: str, usr: str | None = None, pwd: str | None = None, *, nodes: Nodes[OpcuaNode] | None = None, key_cert: KeyCertPair | None = None, **kwargs: Any)[source]
Bases:
Connection[OpcuaNode],StatusReadable[OpcuaNode],StatusWritable[OpcuaNode],StatusSubscribable[OpcuaNode]The OPC UA Connection class allows reading and writing from and to OPC UA servers. Additionally, it implements a subscription method, which reads continuously in a specified interval.
- Parameters:
url – URL of the OPC UA Server.
usr – Username in OPC UA for login.
pwd – Password in OPC UA for login.
nodes – List of nodes to use for all operations.
- logger: Logger = <Logger eta_nexus.connections.opcua_connection (WARNING)>
- classmethod from_ids(ids: Sequence[str], url: str, usr: str | None = None, pwd: str | None = None) OpcuaConnection[source]
Initialize the connection object from an OPC UA protocol through the node IDs.
- Parameters:
ids – Identification of the Node.
url – URL for connection.
usr – Username in OPC UA for login.
pwd – Password in OPC UA for login.
- Returns:
OpcuaConnection object.
- read(nodes: OpcuaNode | Nodes[OpcuaNode] | None = None) pd.DataFrame[source]
Read some manually selected values from OPC UA capable controller.
- Parameters:
nodes – Single node or list/set of nodes to read from.
- Returns:
pandas.DataFrame containing current values of the OPC UA-variables.
- Raises:
ConnectionError – When an error occurs during reading.
- write(values: Mapping[OpcuaNode, Primitive]) None[source]
Writes some manually selected values on OPC UA capable controller.
- Parameters:
values – Dictionary of nodes and data to write {node: value}.
- Raises:
ConnectionError – When an error occurs during reading.
- subscribe(handler: SubscriptionHandler, nodes: OpcuaNode | Nodes[OpcuaNode] | 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 via subscription notify. This function works asynchronously. Subscriptions must always be closed using the close_sub function (use try, finally!).
- 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.