OPC UA
Open Platform Communications Unified Architecture is a standardized and secure communication protocol specifically designed for industrial automation.
For a more detailed explanation of its architecture and benefits, refer to the OPC UA (opens in a new tab) website.
If you're new to OPC UA, we recommend to use UA Expert (opens in a new tab). It simplifies learning about and interacting with OPC UA servers and provides useful monitoring and debugging functions. Additionally, it provides the server information required for using OPC UA with Wandelscript.
Supported by Wandelscript
Wandelscript currently supports the following client functionalities:
Request-Response interaction
- Read data
- Write data
- Call methods
- Wait for OPC UA signals
Write Wandelscript using OPC UA
Since 24.5, communication to an OPC UA server can be established by a built-in Wandelscript function. Support for OPC UA as a device
via the settings or NOVA API was discontinued with 24.6.
Read a value
Read a device value with opcua_read(host, node_id, options)
function.
-
host
is the address of the OPC UA server, e.g.opc.tcp://0.0.0.0:4840
. -
node_id
represents the string notation of the OPC UA node id, e.g.ns=2;s=my_node
. Read more about the OPC UA node id here (opens in a new tab). -
options
is an optional parameter you can provide to configure the OPC UA client. Has to be passed as the last argument. Currently supported options are:request_timeout_seconds
: The time in seconds to wait for the response from the server.
host = "opc.tcp://0.0.0.0:4840"
node_id = "ns=2;s=my_node"
options = {
request_timeout_seconds: 10
}
result = opcua_read(host, node_id, options)
print(result) // prints the value
Write a value
Write a value to the OPC UA node with opcua_write(host, node_id, value)
.
host
is the address of the OPC UA server, e.g.opc.tcp://0.0.0.0:4840
.node_id
represents the string notation of the OPC UA node id, e.g.ns=2;s=my_node
. Read more about the OPC UA node id here (opens in a new tab).value
is any primitive data type supported by Wandelscript.options
is an optional parameter you can provide to configure the OPC UA client. Has to be passed as the last argument. Currently supported options are:request_timeout_seconds
: The time in seconds to wait for the response from the server.
host = "opc.tcp://0.0.0.0:4840"
node_id = "ns=2;s=my_node"
options = {
request_timeout_seconds: 10
}
opcua_write(host, node_id, True, options)
Call method
Call a function defined on the opcua server using opcua_call(host, object_id, function_id, argument1, argument2, ..., options)
.
Pass any number of arguments. It returns the function return from the OPC UA server.
-
host
is the address of the OPC UA server, e.g.opc.tcp://0.0.0.0:4840
. -
object_id
represents the string notation of the OPC UAnode_id
where the function is defined on, e.gns=2;s=my_node
. -
function_id
represents the string notation of the OPC UAnode_id
, e.gns=2;s=my_node
. -
Arguments can be parameters, 0, 1 or more primitive data types to pass to the OPC UA function. The values are sent in the order they are defined.
-
options
is an optional parameter you can provide to configure the OPC UA client. Has to be passed as the last argument. Currently supported options are:request_timeout_seconds
: The time in seconds to wait for the response from the server.
host = "opc.tcp://0.0.0.0:4840"
object_id = "ns=2;s=my_object"
function_id = "ns=2;s=my_function"
options = {
request_timeout_seconds: 10
}
opcua_call(host, object_id, function_id, True, options)
Get the value returned by the OPC UA function with result
. The value returned will be assigned to result
.
host = "opc.tcp://0.0.0.0:4840"
object_id = "ns=2;s=my_object"
function_id = "ns=2;s=my_function"
options = {
request_timeout_seconds: 10
}
result = opcua_call(host, object_id, function_id, True, options)
print(result)
Wait for the OPC UA signal
Wait until a node has the desired value using wait_for_opcua_value(host, node_id, value, config)
.
The function will equality check the provided value against the node value until both values are equal.
Equality checks are executed whenever the OPC UA server sends a data change notification.
This is the default configuration:
host
is the address of the OPC UA server, e.g.opc.tcp://0.0.0.0:4840
.node_id
represents the string notation of the OPC UA node id, e.g.ns=2;s=my_node
. Read more about the OPC UA node id here (opens in a new tab).value
is any primitive data type supported by Wandelscript.
This script will wait until the node specified with node_id has the True value:
host = "opc.tcp://0.0.0.0:4840"
node_id = "ns=2;s=my_node"
result = wait_for_opcua_value(host, node_id, True)
print(result) // prints the value
Configure data exchange with config
parameter
Wandelscript provides several options to configure the data exchange between the server and client:
config
is a Wandelscript parameter that allows for several configuration options of the data exchange. Optional input.
Those options are provided via an OPC UA subscription. When subscribing to a data exchange, the server informs the client about all data changes happening for the respective node. The provided information can be monitored and received by the client.
Use the official OPC UA documentation to
- subscribe to a data exchange (opens in a new tab) and
- monitor data exchanges successfully (opens in a new tab)
Available options
Available configuration options and their default values are:
Option | Default |
---|---|
requested_publishing_interval | 1000 |
requested_lifetime_count | 10000 |
max_notifications_per_publish | 1000 |
priority | 0 |
queue_size | 1 |
sampling_interval | 0.0 |
request_timeout_seconds | 4 |
Options can either be set completely, partially or not at all. If not set, default values are used.
config = {
requested_publishing_interval: 1000
requested_lifetime_count: 10000
max_notifications_per_publish: 1000
priority: 0
queue_size: 1
sampling_interval: 0.0
request_timeout_seconds: 4
}
wait_for_opcua_value(host, node_id, node_value, config)
Server responses
Servers can still respond to the requested configuration with their set configuration, e.g. if certain restrictions are in place. In this case, the subscription will be created with the modified configuration and you'll be notified in the logs.
Your desired configuration might request a publishing interval at 1000 ms:
config = {
requested_publishing_interval: 1000
sampling_interval: 0.0
}
wait_for_opcua_value(host, node_id, node_value, config)
The server configuration might set the publishing interval to 200 ms and thus overrule the requested configuration:
To minimize the risk of such a scenario, we recommend to configure your subscription settings on the OPC UA server side as close as possible to the desired values.
If this is not possible due to restrictions, set the requested configuration values as close as possible to the server's configuration.

Use NOVA authentication with OPC UA
The Wandelbots NOVA OPC UA client supports username and password based authentication.
Provide the username and password together with host
:
host = "opc.tcp://username:password@0.0.0.0:4840"
Example: Communicate with a camera
This example shows the process of communicating with a Cognex camera that is set up to detect a pattern.
# - - - - - Load a job onto the camera: - - - - -
host = "your server host"
job_name = "07_pattern_detection.job"
object_id = "ns=2;s=VisionSystem"
function_id = "ns=2;s=LoadJob"
opcua_call(host, object_id, function_id, job_name)
# - - - - - Write a value to the camera: - - - - -
host="your server host"
node_id = "ns=2;s=Pattern_1.Tool_Enabled""
value = 1
opcua_write(host, node_id, value)
# - - - - - Trigger an image acquisition: - - - - -
opcua_call(host, "ns=2;s=VisionSystem", "ns=2;s=TriggerManualAcquisition")
# - - - - - Read values from the camera: - - - - -
opc_tags = ["ns=2;s=Pattern_1.Tool_Enabled", "ns=2;s=Pattern_1.Fixture.X", "ns=2;s=Pattern_1.Fixture.Y", "ns=2;s=Pattern_1.Fixture.Angle"]
for i = 0..<len(opc_tags):
opc_tag = opc_tags[i]
result = opcua_read(host, opc_tag)
print(opc_tag)
print(result)
But there is more to OPC UA with Wandelbots NOVA: Learn how to trigger a program with a physical button by using an OPC UA node.