Introduction to OPC UA scripts
- Last UpdatedJun 18, 2025
- 2 minute read
The Application Server script library lets you invoke methods in OPC UA servers, via the OPC UA client in the Gateway Communication Driver.
The script library provides a high-level abstraction to enable calling OPC UA methods in scripts, without the need to know the details of the underlying OPC UA method call mechanism.
In general, an OPC UA client calls a method on an OPC UA server by specifying the method name (including the node id of the OPC UA object containing the method) and an array of input arguments. Once the method call completes, the OPC UA server returns an array of output arguments to the client. The input and output arguments may be either primitive data types, or complex user-defined types exposed by the OPC UA server, or a mixture of both.
The OPC UA client retries a call to the server up to 12 times, with each connection attempt separated by an interval of 25 seconds. If the specified OPC UA server name does not exist, or if the client cannot connect for another reason, the client shows a message that it is unable to connect to the endpoint. If you have specified an invalid OPC UA server name, you must close the connection to the invalid server name and create a new connection using the correct server name. Be sure to verify the server name to avoid retrying with the wrong server name.
-
To initialize a connection:
public bool Initialize(string ScopeName, string serverMachineName)
-
To close a connection:
public void Close()
For more information about initializing and closing connections, and the required parameters, refer to Client class.
Since the Gateway Communication Driver does not currently support browsing methods or user-defined types in the OPC UA server, you must know the name of each method to be called, the OPC UA node id of the object hosting the method, its input arguments and their types to be supplied in the method call, as well as the output arguments and their types returned by the OPC UA server.
Third-party tools, such the UaExpert from Unified Automation, will let you browse the OPC UA server and thus can help you with scripting.