Files
Martin Regen defd048d13 Fix macOS build, move https client transport back to core and other maintenance, (#2659)
- change macOS 11 ci builds to newer ones, macOS 11 is deprecated
- fix Opc.Ua.Client EventSource message numbering
- bump nerdgit to 3.6.139
- include .NET Standard 2.0 builds back in Nuget packages for client and server (complex type support requires netcoreapp2.1 which is end of life)
- include .NET Framework 4.7.2 as lowest supported .NET Framework platform
- move https client channel back to core library, as it requires only netstandard2.0 and has no other dependencies. 
- Opc.Ua.Https is now only needed for a https server with kestrel.
- fix security warning for system.private.uri
- upload Quickstarts.Servers to the preview feed to allow use in the samples repo and avoid duplicate codebase
2024-06-28 11:00:17 +02:00
..

OPC Foundation UA .NET Standard Library - Console Reference Subscriber

Introduction

This OPC application was created to provide the sample code for creating Subscriber applications using the OPC Foundation UA .NET Standard PubSub Library. There is a .NET Core 3.1 (2.1) console version of the Subscriber which runs on any OS supporting .NET Standard. The Reference Subscriber is configured to run in parallel with the Console Reference Publisher

How to build and run the Windows OPC UA Reference Server from Visual Studio

  1. Open the solution UA Reference.sln with Visual Studio 2019.
  2. Choose the project ConsoleReferenceSubscriber in the Solution Explorer and set it with a right click as Startup Project.
  3. Hit F5 to build and execute the sample.

How to build and run the console OPC UA Reference Subscriber on Windows, Linux and iOS

This section describes how to run the ConsoleReferenceSubscriber.

Please follow instructions in this article to setup the dotnet command line environment for your platform.

Start the Subscriber

  1. Open a command prompt.
  2. Navigate to the folder Applications/ConsoleReferenceSubscriber.
  3. To run the Subscriber sample type

dotnet run --project ConsoleReferenceSubscriber.csproj --framework netcoreapp3.1.

The Subscriber will start and listen for network messages sent by the Reference Publisher.

Command Line Arguments for ConsoleReferenceSubscriber

ConsoleReferenceSubscriber can be executed using the following command line arguments:

  • -h|help - Shows usage information
  • -m|mqtt_json - Creates a connection using there MQTT with Json encoding Profile. This is the default option.
  • -u|udp_uadp - Creates a connection using there UDP with UADP encoding Profile.

To run the Subscriber sample using a connection with MQTT with Json encoding execute:

	dotnet run --project ConsoleReferenceSubscriber.csproj --framework netcoreapp3.1 

	or 

	dotnet run --project ConsoleReferenceSubscriber.csproj --framework netcoreapp3.1 -m

To run the Subscriber sample using a connection with the UDP with UADP encoding execute:

	dotnet run --project ConsoleReferenceSubscriber.csproj --framework netcoreapp3.1 -u

Programmer's Guide

To create a new OPC UA Subscriber application:

Subscriber Initialization

The following four steps are required to implement a functional Subscriber:

  1. Create Subscriber Configuration.

    // Create configuration using UDP protocol and UADP Encoding 
    PubSubConfigurationDataType pubSubConfiguration = CreateSubscriberConfiguration_UdpUadp();
    

    Or use the alternative configuration object for MQTT with JSON encoding

    // Create configuration using MQTT protocol and JSON Encoding
    PubSubConfigurationDataType pubSubConfiguration = CreateSubscriberConfiguration_MqttJson();
    

    The CreateSubscriberConfiguration methods can be found in ConsoleReferenceSubscriber/Program.cs file.

  2. Create an instance of the UaPubSubApplication Class using the configuration data from step 1.

    // Subscribe to data events 
    UaPubSubApplication uaPubSubApplication = UaPubSubApplication.Create(pubSubConfiguration);
    
  3. Provide the event handler for the DataReceived event. This event will be raised when data sets matching the subscriber configuration arrive over the network. See the DataReceived Event section for more details.

    // Create an instance of UaPubSubApplication
    uaPubSubApplication.DataReceived += PubSubApplication_DataReceived;
    
  4. Start PubSub application

    // Start the publisher
    uaPubSubApplication.Start();
    

After this step the Subscriber will listen for NetworkMessages as configured.

Subscriber Configuration

The Subscriber configuration is a subset of the PubSub Configuration. A functional Subscriber application needs to have a configuration (PubSubConfigurationDataType instance) that contains at least one connection (PubSubConnectionDataType instance) with at least one reader group configuration (ReaderGroupDataType instance). The reader group contains at least one data set reader (DataSetReaderDataType instance) that describes a published data set that can be processed and retrieved by the Subscriber application. The diagram shows the subset of classes involved in an OPC UA Publisher configuration.

SubscriberConfigClasses