Contents
This topic describes the use of the OPC UA Adapter suite in a sample application to query and update data in an OPC UA server. For more information about this operator, see OPC UA Adapters.
Note
The OPC UA adapters are provided for Microsoft Windows systems only.
In order to run correctly, the adapters in this sample require that the Microsoft .NET Framework 4.8 or later be installed on your machine.
The sample is configured by default to access a public OPC UA server for demonstration purposes — the Eclipse Milo Project's demo server — (described here) and should run out of the box. If you wish to connect to other servers, you may need to provide a properly signed and installed X.509 certificate for your client, and possibly install the server's certificate as well (depending on the level of security the server requires). Consult the OPC UA server's administrator for details on how to properly perform these steps.
To configure the sample to connect to a different server, modify the discovery-uri
entry of src/main/configurations/OPC-UA.conf
to point to the discovery server of your choice. If this server requires authentication, you will also need to modify these
values as applicable:
-
use-maximum-security
-
application-certificate-store-path
-
application-certificate-subject-name
-
application-certificate-thumbprint
-
username
-
password
This sample demonstrates the adapters in the OPC UA adapter suite:
-
Reader
-
Writer
-
Subscriber
-
Browser
-
Historical Data Reader
Note
The Eclipse Milo Project's public server does not support historical data queries so it cannot be used to exercise the Historical Data Reader adapter.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
> . -
Enter
opc
to narrow the list of options. -
Select OPC UA adapters from the IoT Adapters category.
-
Click
.
StreamBase Studio creates a project for the OPC UA adapter sample in your current Studio workspace.
The steps to run this sample in Studio are as follows:
-
In the Project Explorer view, open the sample you just loaded.
if you see red marks on a project folder, wait a moment for the project to load its features.
If the red marks do not resolve themselves after a minute, select the project, right-click, and select
> from the context menu. -
Open the
src/main/eventflow/
folder.packageName
-
Open the
opcua-sample.sbapp
file and click theRun button. This opens the SB Test/Debug perspective and starts the module. All the adapters are configured to connect to the OPC UA server at startup.
-
Wait for the Control operator to issue a status tuple indicating the connection was successful. If a connection problem occurs the console will provide more information.
-
In the Manual Input view, select the
BrowseCmd
input stream, and enter a list of OPC nodes to query. Send a tuple withNodeList
set to a list containing a single null entry to browse the root node. If connected to the server configured by default, you can use entries such as:-
ns=2;s=Dynamic
-
ns=2;s=CTT/Static/DA Profile/Analog Type
Click
, and observe that the output stream that received the data is theBrowserResult
stream. The emitted tuple'sNodes
field has one entry for every requested node, listing its metadata and referenced child nodes. -
-
In the Manual Input view, select the ReaderCmd input stream, and enter a list of nodes to query. Using the default server you can query for nodes like:
-
ns=2;s=Dynamic/RandomFloat
-
ns=2;s=CTT/Statuc/DA Profile/Double
Click
, and observe that the output stream that received the data is theReaderResult
stream. The tupleValues
field contains one entry for every requested node, detailing the node's value and associated metadata. -
-
In the Manual Input view, select the
WriterCmd
input stream, and enter a list of nodes to update, with the value you wish to set for them. On the default server you could send:-
NodeID
=ns=2;s=CTT/Static/DA Profile/Double
,Value
=123.456
-
NodeID
=ns=2;s=CTT/Static/DA Profile/Int32
,Value
=42
Click
, and observe that the output stream that received the data is theWriterResult
stream. The tuple contains the status of the write operation for every requested node.You may wish to use the Reader adapter again to confirm that the values have been modified on the server.
-
-
In the Manual Input view, select the
SubCmd
input stream, set theAction
field tosubscribe
, and enter a list of tag names to monitor. For example on the default server:-
ns=2;s=Dynamic/RandomDouble
-
ns=2;s=Dynamic/RandomInt32
Click
, and observe that theSubStatus
port has sent one tuple to indicate that the subscription has been successfully created (and in that tuple, the SubscriptionID assigned by the server to this subscription will be mentioned), and that theSubResult
output stream is now emitting periodical tuples containing the updated values for the specified nodes.You may cancel this subscription by sending a new tuple to the
SubCmd
input stream withAction
set tounsubscribe
and setting SubscriptionID to the value given by the status tuple'sSubscriptionID
entry, or any result tuple'sSubscriptionID
field. -
-
When done, press F9 or click the
Terminate EventFlow Fragment button.
This sample has the following files:
-
The sample EventFlow application and its layout file,
opcua-sample.sbapp
andopcua-sample.sblayout
, respectively, both located insrc/eventflow
. -
The adapter configuration file,
OPC-UA.conf
, located insrc/main/configurations
. -
This
Readme
file, in plain text and HTML formats.
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.
Important
Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.
Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:
studio-workspace
/sample_opcua
See Default Installation Directories for the default location of studio-workspace
on your system.