OpcUaConnection
OpcUaConnection
- class eta_utility.connectors.OpcUaConnection(url: str, usr: str | None = None, pwd: str | None = None, *, nodes: Nodes | None = None, key_cert: KeyCertPair | None = None, **kwargs: Any)[source]
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 | 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[AnyNode, 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) 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) 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 | 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.
NodeOpcUa
- class eta_utility.connectors.node.NodeOpcUa(name: str, url: str, protocol: str, *args: Any, **kwargs: Any)[source]
Node for the OPC UA protocol.
- opc_id_type: str
Type of the OPC UA Node ID Specification.
- opc_name: str
Name of the OPC UA Node.
- opc_path: list[NodeOpcUa]
Path to the OPC UA node in list representation. Nodes in this list can be used to access any parent objects.
- 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’.