OPC UA Adapter Sample

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.

Prerequisites

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 — Apache Project Milo'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

Sample Overview

This sample demonstrates the adapters in the OPC UA adapter suite:

  • Reader

  • Writer

  • Subscriber

  • Browser

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, select File>Load StreamBase Sample.

  • Enter opc to narrow the list of options.

  • Select OPC UA adapters from the IoT Adapters category.

  • Click Import Now.

StreamBase Studio creates a project for the OPC UA adapter sample in your current Studio workspace.

Running This Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. 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 Maven>Update Project from the context menu.

  2. Open the src/main/eventflow/packageName folder.

  3. Open the opcua-sample.sbapp file and click the Run 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.

  4. 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.

  5. In the Manual Input view, select the BrowseCmd input stream, and enter a list of OPC nodes to query. Send a tuple with NodeList 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 Send Data, and observe that the output stream that received the data is the BrowserResult stream. The emitted tuple's Nodes field has one entry for every requested node, listing its metadata and referenced child nodes.

  6. 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 Send Data, and observe that the output stream that received the data is the ReaderResult stream. The tuple Values field contains one entry for every requested node, detailing the node's value and associated metadata.

  7. 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 Send Data, and observe that the output stream that received the data is the WriterResult 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.

  8. In the Manual Input view, select the SubCmd input stream, set the Action field to subscribe, 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 Send Data, and observe that the SubStatus 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 the SubResult 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 with Action set to unsubscribe and setting SubscriptionID to the value given by the status tuple's SubscriptionID entry, or any result tuple's SubscriptionID field.

  9. When done, press F9 or click the Terminate EventFlow Fragment button.

This Sample's Files

This sample has the following files:

  • The sample EventFlow application and its layout file, opcua-sample.sbapp and opcua-sample.sblayout, respectively, both located in src/eventflow.

  • The adapter configuration file, OPC-UA.conf, located in src/main/configurations.

  • This Readme file, in plain text and HTML formats.

Sample Location

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.