eta_utility.connectors.opc_ua module
The OPC UA module provides utilities for the flexible creation of OPC UA connections.
- class eta_utility.connectors.opc_ua.OpcUaConnection(url: str, usr: str | None = None, pwd: str | None = None, *, nodes: Nodes[NodeOpcUa] | None = None, key_cert: KeyCertPair | None = None, **kwargs: Any)[source]
Bases:
Connection
[NodeOpcUa
]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.
- 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: Nodes[NodeOpcUa] | None = None) pd.DataFrame [source]
Read some manually selected values from OPC UA capable controller.
- Parameters:
nodes – List 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[NodeOpcUa, Any]) 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.
- 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.
- Raises:
ConnectionError – When an error occurs during node creation.
- 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.
- Raises:
ConnectionError – If deletion of nodes fails.
- subscribe(handler: SubscriptionHandler, nodes: Nodes[NodeOpcUa] | 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 – 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.