Skip to content

OPC UA Client Manager API

The OPCUAClientManager handles multiple OPC UA client connections. It abstracts connection logic, node browsing, and reading/writing values, providing a unified interface for the rest of the application.

class automation.managers.opcua_client.OPCUAClientManager()

Manages multiple OPC UA Client connections and their subscriptions.

It handles client lifecycle (add, remove, connect, disconnect), server discovery, and reading/writing values to OPC UA nodes.

discovery(self, host='127.0.0.1', port=4840)

Discovers available OPC UA servers on a given host and port.

Parameters:

  • host (str): IP address or hostname.
  • port (int): Port number.

Returns:

  • list[dict]: Discovery results.
add(self, client_name, host, port)

Adds and connects a new OPC UA Client.

Parameters:

  • client_name (str): Unique name for the client.
  • host (str): Server host.
  • port (int): Server port.

Returns:

  • tuple: (Success boolean, Message string).
remove(self, client_name)

Disconnects and removes an OPC UA Client.

Parameters:

  • client_name (str): The name of the client to remove.

Returns:

  • bool: True if successful, False otherwise.
connect(self, client_name)

Connects a specific client.

Parameters:

  • client_name (str): Client name.
disconnect(self, client_name)

Disconnects a specific client.

Parameters:

  • client_name (str): Client name.
get(self, client_name)

Retrieves a client instance by name.

Parameters:

  • client_name (str): Client name.

Returns:

  • Client: The client object.
get_opcua_tree(self, client_name, *, mode='generic', max_depth=10, max_nodes=50000, include_properties=True, include_property_values=False)

Browses the OPC UA address space tree starting from the root folder.

Parameters:

  • client_name (str): Client name.

Returns:

  • tuple: (Tree dict, HTTP status code).
get_node_values(self, client_name, namespaces)

Reads values from multiple nodes.

Parameters:

  • client_name (str): Client name.
  • namespaces (list): List of node namespaces/IDs.

Returns:

  • list: Values.
get_client_by_address(self, opcua_address)

Retrieves a client by its server address URL.

Parameters:

  • opcua_address (str): OPC UA Server URL (e.g., "opc.tcp://localhost:4840").

Returns:

  • Client: The connected client object or None.
get_node_value_by_opcua_address(self, opcua_address, namespace)

Reads a node value using the server address to find the client.

Parameters:

  • opcua_address (str): Server URL.
  • namespace (str): Node ID.
get_node_attributes(self, client_name, namespaces)

Reads attributes (Description, DataType, etc.) for a list of nodes.

Parameters:

  • client_name (str): Client name.
  • namespaces (list): List of Node IDs.

Returns:

  • list: List of attribute dictionaries.
serialize(self, client_name=None)

Serializes client configurations.

Parameters:

  • client_name (str, optional): Specific client to serialize.

Returns:

  • dict: Dictionary of serialized client data.