Code-Beispiele Opc Ua Sdk

Die Einbindung des PLCcom.Opc.Ua.Sdk ist sehr einfach und benutzerfreundlich.
Die nachfolgenden Beispiele veranschaulichen die wichtigsten Funktionalitäten.

Weiterführende umfangreiche Dokumentationen mit direkt ausführbaren Code-Beispielen finden sie in der Beispielanwendung in unserem Downloadpaket oder online:

.Net:
https://www.plccom.de/help_opcua_toolkit/help/index.html

Java:
https://www.plccom.de/help_opc_ua_client_sdk/java/javadoc/index.html


Discover OPC UA Server

Die bereitgestellten Endpoints eines OPC UA Servers lassen sich mit dem Befehl GetDiscoveryUrls (.net) oder discoverEndpoints (Java) ermitteln. 

Einfaches Beispiel wenn der OPC UA Server seine Endpoints bei einem Discovery-Server registriert hat:
string[] Endpoints = OpcUaClient.GetDiscoveryUrls("127.0.0.1");

oder direktes Ermitteln der Endpoints bei einem Server ohne Discovery-Server
string[] Endpoints = OpcUaClient.GetDiscoveryUrls("127.0.0.1", 50520);

Nachfolgend ein komplettes ausführbares Beispiel:

  • C#
  • Visual Basic
  • Java
using System;
using PLCcom.Opc.Ua;
using PLCcom.Opc.Ua.Toolkit;
using PLCcom.Opc.Ua.Client;

class Program
{
    static void Main(string[] args)
    {
        Program program = new Program();
        program.Start();
    }
    void Start()
    {
        try
        {
            //TODO
            //Submit your license information from your license e-mail
            //Note: with invalid license information the client will be disconnected after 15 minutes
            string LicenseUserName = "<Enter your UserName here>";
            string LicenseSerial = "<Enter your Serial here>";


            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')");
            string Hostname = Console.ReadLine();
            if (string.IsNullOrEmpty(Hostname))
            {
                Hostname = "localhost";
                Console.WriteLine("localhost");
            }

            Console.WriteLine("please enter the port number (nothing when discover discovery server)");
            string Port = Console.ReadLine();
            Console.WriteLine("");
            int iPort = 4840;

            EndpointDescriptionCollection Endpoints = null;
            if (int.TryParse(Port, out iPort) && iPort > 0)
            {
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname, iPort);
            }
            else
            {
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname);
            }

            if (Endpoints.Count > 0)
            {
                Console.WriteLine("endpoints found:");
                int counter = 0;
                foreach (EndpointDescription Endpoint in Endpoints)
                {
                    Console.WriteLine(counter++.ToString() + " => " + Endpoint.ToString());
                }

                Console.WriteLine("please enter index of desired endpoint");
                string NumberOfEndpoint = Console.ReadLine();
                int iNumberOfEndpoint = -1;
                if (int.TryParse(NumberOfEndpoint, out iNumberOfEndpoint) && iNumberOfEndpoint > -1 && iNumberOfEndpoint < Endpoints.Count)
                {
                    //create a a SessionConfiguration with the selected endpoint and application name
                    SessionConfiguration sessionConfiguration = SessionConfiguration.Build(System.Reflection.Assembly.GetEntryAssembly().GetName().Name, 
                                                                                            Endpoints[iNumberOfEndpoint]);

                    //output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath);

                    //Create a new opc client instance and pass your license information
                    DataAccessClient client = new DataAccessClient(LicenseUserName, LicenseSerial, sessionConfiguration, false);
                    Console.WriteLine("Info: license state => " + client.GetLicenceMessage());

                    //register events
                    client.ServerConnectionLost += Client_ServerConnectionLost;
                    client.ServerConnected += Client_ServerConnected;
                    client.InternalSubscription_StateChanged += InternalSubscription_StateChanged;
                    client.KeepAlive += Client_KeepAlive;
                    try
                    {
                        //connect client
                        client.AutoConnect = false;
                        client.ConnectSession();
                        Console.WriteLine(client.GetSessionState().ToString());

                        Console.WriteLine();
                        Console.WriteLine("press enter for exit");
                        Console.ReadLine();
                        return;
                    }
                    finally
                    {
                        if (client.GetSessionState() == SessionState.Connected) client.DisconnectSession();
                    }

                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("invalid number of Endpoint");
                }
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("no endpoints found");
            }

            Console.WriteLine();
            Console.WriteLine("press enter for exit");
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine("press enter for exit");
            Console.ReadLine();
        }

    }
    private void InternalSubscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " State of InternalSubscription changed to => " + e.Status.ToString());
    }

    private void Client_ServerConnected(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connected");
    }

    private void Client_ServerConnectionLost(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connection lost");
    }

    void Client_KeepAlive(Session session, KeepAliveEventArgs e)
    {
        //catch the keepalive event
    }
}
Imports PLCcom.Opc.Ua
Imports PLCcom.Opc.Ua.Client
Imports PLCcom.Opc.Ua.Toolkit

Module Program
    Sub Main()
        Try

            'TODO
            'Submit your license information from your license e-mail
            'Note: with invalid license information the client will be disconnected after 15 minutes
            Dim LicenseUserName As String = "<Enter your UserName here>"
            Dim LicenseSerial As String = "<Enter your Serial here>"

            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')")
            Dim Hostname As String = Console.ReadLine()
            If String.IsNullOrEmpty(Hostname) Then
                Hostname = "localhost"
                Console.WriteLine("localhost")
            End If

            Console.WriteLine("please enter the port number (nothing when discover discovery server)")
            Dim Port As String = Console.ReadLine()
            Console.WriteLine("")
            Dim iPort As Integer = 4840

            Dim Endpoints As EndpointDescriptionCollection = Nothing
            If Integer.TryParse(Port, iPort) AndAlso iPort > 0 Then
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname, iPort)
            Else
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname)
            End If

            If Endpoints.Count > 0 Then
                Console.WriteLine("endpoints found:")
                Dim counter As Integer = 0
                For Each Endpoint As EndpointDescription In Endpoints
                    Console.WriteLine(counter.ToString() & " => " & Endpoint.ToString)
                    counter += 1
                Next

                Console.WriteLine("please enter index of desired endpoint")
                Dim NumberOfEndpoint As String = Console.ReadLine()
                Console.WriteLine("")

                Dim iNumberOfEndpoint As Integer = -1
                If Integer.TryParse(NumberOfEndpoint, iNumberOfEndpoint) AndAlso iNumberOfEndpoint > -1 AndAlso iNumberOfEndpoint < Endpoints.Count Then
                    'create a a SessionConfiguration with the selected endpoint and application name
                    Dim sessionConfiguration As SessionConfiguration = SessionConfiguration.Build(System.Reflection.Assembly.GetEntryAssembly().GetName().Name, Endpoints(iNumberOfEndpoint))

                    'output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath)

                    'Create a New opc client instance and pass your license information
                    Dim client As New DataAccessClient(LicenseUserName, LicenseSerial, sessionConfiguration, False)
                    Console.WriteLine("Info: license state => " & client.GetLicenceMessage())

                    'register events
                    AddHandler client.ServerConnectionLost, AddressOf Client_ServerConnectionLost
                    AddHandler client.ServerConnected, AddressOf Client_ServerConnected
                    AddHandler client.InternalSubscription_StateChanged, AddressOf InternalSubscription_StateChanged
                    AddHandler client.KeepAlive, AddressOf Client_KeepAlive

                    Try
                        'connect client
                        client.ConnectSession()

                        Console.WriteLine(client.GetSessionState().ToString())
                        Console.WriteLine()
                        Console.WriteLine("press enter for exit")
                        Console.ReadLine()
                    Finally
                        If Not IsNothing(client) AndAlso client.GetSessionState().Equals(SessionState.Connected) Then
                            client.DisconnectSession()
                        End If
                    End Try
                Else
                    Console.WriteLine("invalid number of Endpoint")
                    Console.WriteLine("press enter for exit")
                    Console.ReadLine()
                End If
            Else
                Console.WriteLine("no endpoints found")
                Console.WriteLine("press enter for exit")
                Console.ReadLine()
            End If
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.WriteLine("press enter for exit")
            Console.ReadLine()
        End Try

    End Sub
    Private Sub InternalSubscription_StateChanged(subscription As Subscription, e As SubscriptionStateChangedEventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " State of InternalSubscription changed to => " & e.Status.ToString())
    End Sub

    Private Sub Client_ServerConnected(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connected")
    End Sub

    Private Sub Client_ServerConnectionLost(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connection lost")
    End Sub

    Private Sub Client_KeepAlive(session As Session, e As KeepAliveEventArgs)
        'catch the keepalive event
    End Sub
End Module
package tutorials.t01_firstSteps;

import plccom.opc.ua.sdk.client.application.SortDirection;
import plccom.opc.ua.sdk.client.application.UaClient;
import java.net.URI;
import org.opcfoundation.ua.core.EndpointDescription;

public class Tutorial01_discover_endpoints {
	public static void main(String[] args) {

		Tutorial01_discover_endpoints prog = new Tutorial01_discover_endpoints();
		prog.start();
	}

	private void start() {
		try {
			System.out.println("Start discover discovery server");
			String hostname = "localhost";
			int port = 4840;

			// create a discovery uri
			URI discoveryUri = new URI(String.format("opc.tcp://%s:%s", hostname, port));
			System.out.println(String.format("reading Endports from discoveryUri %s", discoveryUri.toString()));

			// Get endpoints from ua Server with discovery url
			EndpointDescription[] endpoints = UaClient.discoverEndpoints(discoveryUri);

			endpoints = UaClient.sortBySecurityLevel(endpoints, SortDirection.Asc);

			for (EndpointDescription endpoint : endpoints) {
				System.out.println(endpoint.toString());
			}

			System.out.println();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}
	}
}

Example: Discover OPC UA Server

Connect to endpoint

 

Das Verbinden eines zu einem OPC UA Server kann auf Wunsch automatisch oder manuell durchgeführt werden.

Per Default-Einstellung verbindet sich ein Client automatisch zum Server wenn eine Verbindung benötigt wird. Auch der Reconnect nach einem Verbindungsabriss findet automatisch statt.

Das Verhalten kann über die AutoConnect Eigenschaft des Clientobjekt eingestellt werden.

DataAccessClient client = new DataAccessClient("<Enter your UserName here>", "<Enter your Serial here>", sessionConfiguration, false);
oder
client.AutoConnect = false;

Nachfolgend ein komplettes ausführbares Beispiel zum manuellen Verbinden:

  • C#
  • Visual Basic
  • Java
using PLCcom.Opc.Ua.Toolkit;
using System;
using PLCcom.Opc.Ua.Client;

class Program
{
    static void Main(string[] args)
    {
        Program program = new Program();
        program.Start();
    }
    void Start()
    {
        try
        {
            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')");
            string Hostname = Console.ReadLine();
            if (string.IsNullOrEmpty(Hostname))
            {
                Hostname = "localhost";
                Console.WriteLine("localhost");
            }

            Console.WriteLine("please enter the port number (nothing when discover discovery server)");
            string Port = Console.ReadLine();
            Console.WriteLine("");
            int iPort = 4840;
            string[] Endpoints;
            if (int.TryParse(Port, out iPort) && iPort > 0)
            {
                Endpoints = OpcUaClient.GetDiscoveryUrls(Hostname, iPort);
            }
            else
            {
                Endpoints = OpcUaClient.GetDiscoveryUrls(Hostname);
            }

            if (Endpoints.Length > 0)
            {
                Console.WriteLine("endpoints found:");
                int counter = 0;
                foreach (string Endpoint in Endpoints)
                {
                    Console.WriteLine(counter++.ToString() + " => " + Endpoint);
                }

                Console.WriteLine("please enter index of desired endpoint");
                string NumberOfEndpoint = Console.ReadLine();
                int iNumberOfEndpoint = -1;
                if (int.TryParse(NumberOfEndpoint, out iNumberOfEndpoint) && iNumberOfEndpoint > -1 && iNumberOfEndpoint < Endpoints.Length)
                {
                    //create a a SessionConfiguration with the selected endpoint and application name
                    SessionConfiguration sessionConfiguration = new SessionConfiguration(System.Reflection.Assembly.GetEntryAssembly().GetName().Name,
                                                                                         Endpoints[iNumberOfEndpoint]);

                    //output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath);

                    //create a new opc client instance and enter your license informations from your license email,
                    //Note: with invalid license information the client will be disconnected after 15 minutes
                    DataAccessClient client = new DataAccessClient("<Enter your UserName here>", "<Enter your Serial here>", sessionConfiguration, false);
                    Console.WriteLine("Info: license state => " + client.GetLicenceMessage());

                    //register events
                    client.ServerConnectionLost += Client_ServerConnectionLost;
                    client.ServerConnected += Client_ServerConnected;
                    client.InternalSubscription_StateChanged += InternalSubscription_StateChanged;
                    client.KeepAlive += Client_KeepAlive;
                    try
                    {
                        //connect client
                        client.AutoConnect = false;
                        client.ConnectSession();
                        Console.WriteLine(client.GetSessionState().ToString());

                        Console.WriteLine();
                        Console.WriteLine("press enter for exit");
                        Console.ReadLine();
                        return;
                    }
                    finally
                    {
                        if (client.GetSessionState() == SessionState.Connected) client.DisconnectSession();
                    }

                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("invalid number of Endpoint");
                }
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("no endpoints found");
            }

            Console.WriteLine();
            Console.WriteLine("press enter for exit");
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine("press enter for exit");
            Console.ReadLine();
        }

    }
    private void InternalSubscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " State of InternalSubscription changed to => " + e.Status.ToString());
    }

    private void Client_ServerConnected(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connected");
    }

    private void Client_ServerConnectionLost(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connection lost");
    }

    void Client_KeepAlive(Session session, KeepAliveEventArgs e)
    {
        //catch the keepalive event
    }
}
Imports PLCcom.Opc.Ua.Toolkit
Imports PLCcom.Opc.Ua.Client

Module Program
    Sub Main()
        Try
            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')")
            Dim Hostname As String = Console.ReadLine()
            If String.IsNullOrEmpty(Hostname) Then
                Hostname = "localhost"
                Console.WriteLine("localhost")
            End If

            Console.WriteLine("please enter the port number (nothing when discover discovery server)")
            Dim Port As String = Console.ReadLine()
            Console.WriteLine("")
            Dim iPort As Integer = 4840

            Dim Endpoints As String()
            If Integer.TryParse(Port, iPort) AndAlso iPort > 0 Then
                Endpoints = OpcUaClient.GetDiscoveryUrls(Hostname, iPort)
            Else
                Endpoints = OpcUaClient.GetDiscoveryUrls(Hostname)
            End If

            If Endpoints.Length > 0 Then
                Console.WriteLine("endpoints found:")
                Dim counter As Integer = 0
                For Each Endpoint As String In Endpoints
                    Console.WriteLine(counter.ToString() & " => " & Endpoint)
                    counter += 1
                Next

                Console.WriteLine("please enter index of desired endpoint")
                Dim NumberOfEndpoint As String = Console.ReadLine()
                Console.WriteLine("")

                Dim iNumberOfEndpoint As Integer = -1
                If Integer.TryParse(NumberOfEndpoint, iNumberOfEndpoint) AndAlso iNumberOfEndpoint > -1 AndAlso iNumberOfEndpoint < Endpoints.Length Then
                    'create a a SessionConfiguration with the selected endpoint and application name
                    Dim sessionConfiguration As New SessionConfiguration(System.Reflection.Assembly.GetEntryAssembly().GetName().Name, Endpoints(iNumberOfEndpoint))

                    'output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath)

                    'create a new opc client instance and enter your license informations from your license email,
                    'Note: with invalid license information the client will be disconnected after 15 minutes
                    Dim client As New DataAccessClient("<Enter your UserName here>", "<Enter your Serial here>", sessionConfiguration, False)
                    Console.WriteLine("Info: license state => " & client.GetLicenceMessage())

                    'register events
                    AddHandler client.ServerConnectionLost, AddressOf Client_ServerConnectionLost
                    AddHandler client.ServerConnected, AddressOf Client_ServerConnected
                    AddHandler client.InternalSubscription_StateChanged, AddressOf InternalSubscription_StateChanged
                    AddHandler client.KeepAlive, AddressOf Client_KeepAlive

                    Try
                        'connect client
                        client.ConnectSession()

                        Console.WriteLine(client.GetSessionState().ToString())
                        Console.WriteLine()
                        Console.WriteLine("press enter for exit")
                        Console.ReadLine()
                    Finally
                        If Not IsNothing(client) AndAlso client.GetSessionState().Equals(SessionState.Connected) Then
                            client.DisconnectSession()
                        End If
                    End Try
                Else
                    Console.WriteLine("invalid number of Endpoint")
                    Console.WriteLine("press enter for exit")
                    Console.ReadLine()
                End If
            Else
                Console.WriteLine("no endpoints found")
                Console.WriteLine("press enter for exit")
                Console.ReadLine()
            End If
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.WriteLine("press enter for exit")
            Console.ReadLine()
        End Try

    End Sub
    Private Sub InternalSubscription_StateChanged(subscription As Subscription, e As SubscriptionStateChangedEventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " State of InternalSubscription changed to => " & e.Status.ToString())
    End Sub

    Private Sub Client_ServerConnected(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connected")
    End Sub

    Private Sub Client_ServerConnectionLost(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connection lost")
    End Sub

    Private Sub Client_KeepAlive(session As Session, e As KeepAliveEventArgs)
        'catch the keepalive event
    End Sub
End Module
package tutorials.t01_firstSteps;

import java.net.URI;
import plccom.opc.ua.sdk.client.application.ClientConfiguration;
import plccom.opc.ua.sdk.client.application.EndpointProtocol;
import plccom.opc.ua.sdk.client.application.UaClient;
import plccom.opc.ua.sdk.client.application.listener.SessionConnectionStateChangeListener;
import plccom.opc.ua.sdk.client.application.listener.SessionKeepAliveListener;
import org.opcfoundation.ua.builtintypes.LocalizedText;
import org.opcfoundation.ua.core.EndpointDescription;
import org.opcfoundation.ua.core.MessageSecurityMode;
import org.opcfoundation.ua.core.ServerState;
import org.opcfoundation.ua.core.ServerStatusDataType;

public class Tutorial02_simple_connect_to_server
		implements SessionKeepAliveListener, SessionConnectionStateChangeListener {

	// Developer's TODO
	// Submit your license information from your license e-mail
	private final String LicenseUserName = "<Enter your UserName here>";
	private final String LicenseSerial = "<Enter your Serial here>";

	public static void main(String[] args) {
		Tutorial02_simple_connect_to_server prog = new Tutorial02_simple_connect_to_server();
		prog.start();
	}

	private void start() {
		try {

			// find endpoint at server by discovery url, protocol and security mode
			EndpointDescription endpoint = UaClient.findBestEndpoint(
					new URI("opc.tcp://localhost:50520/UA/DataAccessServer"), EndpointProtocol.opc_tcp,
					MessageSecurityMode.None);

			if (endpoint != null) {

				System.out.println("endpoint found:");

				// create Sessionconfiguration
				ClientConfiguration clientConfiguration = new ClientConfiguration(
						new LocalizedText(this.getClass().getSimpleName(), "en"), endpoint);
				
				clientConfiguration.setAutoConnectEnabled(true);

				// Create new OPCUAClient
				UaClient myClient = new UaClient(LicenseUserName, LicenseSerial, clientConfiguration);

				// print license informations
				System.out.println(myClient.getLicenceMessage());

				// add events for monitoring session
				myClient.addSessionKeepAliveListener(this);
				myClient.addSessionConnectionStateChangeListener(this);

				// Connect client
				myClient.connect();
				
				System.in.read();

				// shutdown client
				myClient.close();

				// remove events for monitoring session
				myClient.removeSessionKeepAliveListener(this);
				myClient.removeSessionConnectionStateChangeListener(this);

			} else {
				System.out.println("no endpoints found");
			}

		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

	@Override
	public void onSessionKeepAlive(ServerStatusDataType serverStatusDataType, ServerState serverState) {
		System.out.println("incoming Keepalive => Serverstate: " + serverState.toString());
	}

	@Override
	public void onSessionConnectionStateChanged(boolean isConnected) {
		System.out.println("incoming SessionConnectionState => Session Connected = " + isConnected);
	}
}

Example: Connect to endpoint

Browse nodes

Die Knoten eines OPC UA Servers lassen sich mit dem Befehl "Browse" durchsuchen.

Einfaches Beispiel:
ReferenceDescription rd = client.Browse("Objects.Server.Data.Static") ;

Nachfolgend ein komplettes ausführbares Beispiel:

  • C#
  • Visual Basic
  • Java
using System;
using PLCcom.Opc.Ua;
using PLCcom.Opc.Ua.Client;
using PLCcom.Opc.Ua.Toolkit;

class Program
{
    static void Main(string[] args)
    {
        Program program = new Program();
        program.Start();
    }
    void Start()
    {
        try
        {
            //TODO
            //Submit your license information from your license e-mail
            //Note: with invalid license information the client will be disconnected after 15 minutes
            string LicenseUserName = "<Enter your UserName here>";
            string LicenseSerial = "<Enter your Serial here>";

            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')");
            string Hostname = Console.ReadLine();
            if (string.IsNullOrEmpty(Hostname))
            {
                Hostname = "localhost";
                Console.WriteLine("localhost");
            }
            Console.WriteLine("please enter the port number (nothing when discover discovery server)");
            string Port = Console.ReadLine();
            Console.WriteLine("");
            int iPort = 4840;

            EndpointDescriptionCollection Endpoints = null;
            if (int.TryParse(Port, out iPort) && iPort > 0)
            {
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname, iPort);
            }
            else
            {
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname);
            }

            if (Endpoints.Count > 0)
            {
                Console.WriteLine("endpoints found:");
                int counter = 0;
                foreach (EndpointDescription Endpoint in Endpoints)
                {
                    Console.WriteLine(counter++.ToString() + " => " + Endpoint);
                }

                Console.WriteLine("please enter index of desired endpoint");
                string NumberOfEndpoint = Console.ReadLine();
                Console.WriteLine("");
                int iNumberOfEndpoint = -1;
                if (int.TryParse(NumberOfEndpoint, out iNumberOfEndpoint) && iNumberOfEndpoint > -1 && iNumberOfEndpoint < Endpoints.Count)
                {
                    //create a a SessionConfiguration with the selected endpoint and application name
                    SessionConfiguration sessionConfiguration =  SessionConfiguration.Build(System.Reflection.Assembly.GetEntryAssembly().GetName().Name,
                                                                                            Endpoints[iNumberOfEndpoint]);

                    //output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath);

                    //Create a new opc client instance and pass your license information
                    using (DataAccessClient client = new DataAccessClient(LicenseUserName, LicenseSerial, sessionConfiguration))
                    {
                        Console.WriteLine("Info: license state => " + client.GetLicenceMessage());

                        //register events
                        client.ServerConnectionLost += Client_ServerConnectionLost;
                        client.ServerConnected += Client_ServerConnected;
                        client.InternalSubscription_StateChanged += InternalSubscription_StateChanged;
                        client.KeepAlive += Client_KeepAlive;

                        string browsePath = string.Empty;
                        do
                        {
                            Console.WriteLine("");
                            Console.WriteLine("please enter browse path (nothing for root or 'exit' for exit program)");
                            browsePath = Console.ReadLine();
                            if (!browsePath.ToUpper().Equals("EXIT"))
                            {
                                try
                                {
                                    //Browse the server
                                    foreach (ReferenceDescription rd in client.Browse(browsePath))
                                    {
                                        Console.WriteLine("Child NodeID found => " + rd.NodeId + " " +
                                            rd.DisplayName.ToString() + " NodeClass => " + rd.NodeClass.ToString() +
                                            " FullPath => " + client.GetPathFromNodeId(rd.NodeId)[0]);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                            }
                        }
                        while (!browsePath.ToUpper().Equals("EXIT"));
                    }
                }
                else
                {
                    Console.WriteLine("invalid number of Endpoint");
                    Console.WriteLine();
                    Console.WriteLine("press enter for exit");
                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("no endpoints found");
                Console.WriteLine();
                Console.WriteLine("press enter for exit");
                Console.ReadLine();
            }


        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine("press enter for exit");
            Console.ReadLine();
        }

    }

    private void InternalSubscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " State of InternalSubscription changed to => " + e.Status.ToString());
    }

    private void Client_ServerConnected(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connected");
    }

    private void Client_ServerConnectionLost(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connection lost");
    }

    void Client_KeepAlive(Session session, KeepAliveEventArgs e)
    {
        //catch the keepalive event
    }

}
Imports PLCcom.Opc.Ua
Imports PLCcom.Opc.Ua.Client
Imports PLCcom.Opc.Ua.Toolkit

Module Program

#Region "private member"
    Private client As DataAccessClient = Nothing
#End Region

    Sub Main()
        Try

            'TODO
            'Submit your license information from your license e-mail
            'Note: with invalid license information the client will be disconnected after 15 minutes
            Dim LicenseUserName As String = "<Enter your UserName here>"
            Dim LicenseSerial As String = "<Enter your Serial here>"

            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')")
            Dim Hostname As String = Console.ReadLine()
            If String.IsNullOrEmpty(Hostname) Then
                Hostname = "localhost"
                Console.WriteLine("localhost")
            End If
            Console.WriteLine("please enter the port number (nothing when discover discovery server)")
            Dim Port As String = Console.ReadLine()
            Console.WriteLine("")
            Dim iPort As Integer = 4840

            Dim Endpoints As EndpointDescriptionCollection = Nothing
            If Integer.TryParse(Port, iPort) AndAlso iPort > 0 Then
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname, iPort)
            Else
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname)
            End If

            If Endpoints.Count > 0 Then
                Console.WriteLine("endpoints found:")
                Dim counter As Integer = 0
                For Each Endpoint As EndpointDescription In Endpoints
                    Console.WriteLine(counter.ToString() & " => " & Endpoint.ToString)
                    counter += 1
                Next

                Console.WriteLine("please enter index of desired endpoint")
                Dim NumberOfEndpoint As String = Console.ReadLine()
                Console.WriteLine("")

                Dim iNumberOfEndpoint As Integer = -1
                If Integer.TryParse(NumberOfEndpoint, iNumberOfEndpoint) AndAlso iNumberOfEndpoint > -1 AndAlso iNumberOfEndpoint < Endpoints.Count Then
                    'create a a SessionConfiguration with the selected endpoint and application name
                    Dim sessionConfiguration As SessionConfiguration = SessionConfiguration.Build(System.Reflection.Assembly.GetEntryAssembly().GetName().Name, Endpoints(iNumberOfEndpoint))

                    'output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath)

                    'Create a New opc client instance and pass your license information
                    client = New DataAccessClient(LicenseUserName, LicenseSerial, sessionConfiguration)
                    Console.WriteLine("Info: license state => " & client.GetLicenceMessage())

                    'register events
                    AddHandler client.ServerConnectionLost, AddressOf Client_ServerConnectionLost
                    AddHandler client.ServerConnected, AddressOf Client_ServerConnected
                    AddHandler client.InternalSubscription_StateChanged, AddressOf InternalSubscription_StateChanged
                    AddHandler client.KeepAlive, AddressOf Client_KeepAlive

                    Console.WriteLine(client.GetSessionState().ToString())
                    Console.WriteLine()

                    Dim browsePath As String = String.Empty
                    Do

                        Console.WriteLine("please enter browse path (nothing for root or 'exit' for exit program)")
                        browsePath = Console.ReadLine()
                        If Not browsePath.ToUpper().Equals("EXIT") Then
                            Try
                                For Each rd As ReferenceDescription In client.Browse(browsePath)
                                    Console.WriteLine(("Child NodeID found => " & rd.NodeId.ToString() & " " & rd.DisplayName.ToString() & " NodeClass => " & rd.NodeClass.ToString() & " FullPath => ") + client.GetPathFromNodeId(rd.NodeId)(0))
                                Next
                            Catch ex As Exception
                                Console.WriteLine(ex.Message)
                            End Try
                        End If
                    Loop While Not browsePath.ToUpper().Equals("EXIT")
                Else
                    Console.WriteLine("invalid number of Endpoint")
                    Console.WriteLine()
                    Console.WriteLine("press enter for exit")
                    Console.ReadLine()
                End If
            Else
                Console.WriteLine("no endpoints found")
                Console.WriteLine()
                Console.WriteLine("press enter for exit")
                Console.ReadLine()


            End If
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.WriteLine("press enter for exit")
            Console.ReadLine()
        Finally
            If Not IsNothing(client) AndAlso client.GetSessionState().Equals(SessionState.Connected) Then
                client.DisconnectSession()
            End If
        End Try

    End Sub

    Private Sub InternalSubscription_StateChanged(subscription As Subscription, e As SubscriptionStateChangedEventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " State of InternalSubscription changed to => " & e.Status.ToString())
    End Sub

    Private Sub Client_ServerConnected(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connected")
    End Sub

    Private Sub Client_ServerConnectionLost(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connection lost")
    End Sub

    Private Sub Client_KeepAlive(session As Session, e As KeepAliveEventArgs)
        'catch the keepalive event
    End Sub
End Module
package tutorials.t01_firstSteps;

import java.net.URI;
import plccom.opc.ua.sdk.client.application.ClientConfiguration;
import plccom.opc.ua.sdk.client.application.SortDirection;
import plccom.opc.ua.sdk.client.application.UaClient;
import plccom.opc.ua.sdk.client.application.listener.SessionConnectionStateChangeListener;
import plccom.opc.ua.sdk.client.application.listener.SessionKeepAliveListener;
import org.opcfoundation.ua.builtintypes.LocalizedText;
import org.opcfoundation.ua.core.BrowseDescription;
import org.opcfoundation.ua.core.BrowseDirection;
import org.opcfoundation.ua.core.BrowseRequest;
import org.opcfoundation.ua.core.BrowseResponse;
import org.opcfoundation.ua.core.BrowseResult;
import org.opcfoundation.ua.core.BrowseResultMask;
import org.opcfoundation.ua.core.EndpointDescription;
import org.opcfoundation.ua.core.Identifiers;
import org.opcfoundation.ua.core.NodeClass;
import org.opcfoundation.ua.core.ReferenceDescription;
import org.opcfoundation.ua.core.ServerState;
import org.opcfoundation.ua.core.ServerStatusDataType;

public class Tutorial05_Browse_by_Path implements SessionKeepAliveListener, SessionConnectionStateChangeListener {

	// Developer's TODO
	// Submit your license information from your license e-mail
	private final String LicenseUserName = "<Enter your UserName here>";
	private final String LicenseSerial = "<Enter your Serial here>";

	public static void main(String[] args) {
		Tutorial05_Browse_by_Path prog = new Tutorial05_Browse_by_Path();
		prog.start();
	}

	private void start() {
		try {

			String hostname = "localhost";

			int port = 4840;

			// create a discovery uri
			URI discoveryUri = new URI(String.format("opc.tcp://%s:%s", hostname, port));

			System.out.println(String.format("reading Endports from discoveryUri %s", discoveryUri.toString()));

			// Get endpoints from ua Server with discovery url
			EndpointDescription[] endpoints = UaClient.discoverEndpoints(discoveryUri);

			// sort endpoint by message security mode
			endpoints = UaClient.sortBySecurityLevel(endpoints, SortDirection.Asc);

			if (endpoints.length > 0) {

				// create Sessionconfiguration
				ClientConfiguration clientConfiguration = new ClientConfiguration(
						new LocalizedText(this.getClass().getSimpleName(), "en"), endpoints[0]);

				// enable auto connect functionality
				// set automatic reconnect after 1000 milliseconds in case of losing connection
				clientConfiguration.setAutoConnectEnabled(true, 1000);

				// Create new OPCUAClient with Sessionconfiguration
				UaClient myClient = new UaClient(LicenseUserName, LicenseSerial, clientConfiguration);
				try {
					// print license informations
					System.out.println(myClient.getLicenceMessage());

					// add events for monitoring session
					myClient.addSessionKeepAliveListener(this);
					myClient.addSessionConnectionStateChangeListener(this);

							try {
								// Create a BrowseDescription object
								// find all of the components of the node.
								BrowseDescription browseDescription1 = new BrowseDescription();
								browseDescription1.setReferenceTypeId(Identifiers.Aggregates);
								browseDescription1.setBrowseDirection(BrowseDirection.Forward);
								browseDescription1.setIncludeSubtypes(true);
								browseDescription1.setNodeClassMask(NodeClass.Object, NodeClass.Variable);
								browseDescription1.setResultMask(BrowseResultMask.All);
								// Set start nodeId
								browseDescription1.setNodeId(myClient.getNodeIdByPath("Objects.Server"));

								// Create a BrowseRequest or browse the BrowseDescription direct
								BrowseRequest browseRequest = new BrowseRequest(null, null, null,
										new BrowseDescription[] { browseDescription1 });

								// Browse the node
								BrowseResponse results = myClient.browse(browseRequest);
								for (BrowseResult res : results.getResults()) {
									if (res.getStatusCode().isGood()) {
										// evaluate references
										for (ReferenceDescription rd : res.getReferences()) {
											System.out.println("Child NodeID found => " + rd.getNodeId() + " "
													+ rd.getDisplayName().toString() + " NodeClass => "
													+ rd.getNodeClass().toString());

										}
									} else {
										System.out.println("operation return bad status code => " + res.getStatusCode().toString());
									}
								}

							} catch (Exception ex) {
								System.out.println(ex.getMessage());
							}

				} finally {
					// shutdown client
					myClient.close();
				}

				// remove events for monitoring session
				myClient.removeSessionKeepAliveListener(this);
				myClient.removeSessionConnectionStateChangeListener(this);

			} else {
				System.out.println("no endpoints found");
			}

		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

	@Override
	public void onSessionConnectionStateChanged(boolean isConnected) {
		System.out.println("incoming SessionConnectionState => Session Connected =: " + isConnected);
	}

	@Override
	public void onSessionKeepAlive(ServerStatusDataType serverStatusDataType, ServerState serverState) {
		System.out.println("incoming Keepalive => Serverstate: " + serverState.toString());

	}
}

Example: Browse nodes

Read or write values

Das Lesen oder Schreiben von Werten kann entweder über die NodeId oder direkt über den kompletten Namen/Pfad des Knotens erfolgen:

Beispiel zum Lesen eines Knotens:
DataValue value = client.ReadValue("Objects.Server.Data.Static.Scalar.Int64Value");

Beispiel zum Schreiben des Wertes 123 auf einen Knoten:
StatusCode sc = client.Write("Objects.Server.Data.Static.Scalar.Int64Value",123);

Nachfolgend ein komplettes ausführbares Beispiel:

  • C#
  • Visual Basic
  • Java
using System;
using PLCcom.Opc.Ua.Toolkit;
using PLCcom.Opc.Ua.Client;
using PLCcom.Opc.Ua;

class Program
{

    static void Main(string[] args)
    {
        Program program = new Program();
        program.Start();
    }
    void Start()
    {
        try
        {
            //TODO
            //Submit your license information from your license e-mail
            //Note: with invalid license information the client will be disconnected after 15 minutes
            string LicenseUserName = "<Enter your UserName here>";
            string LicenseSerial = "<Enter your Serial here>";

            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')");
            string Hostname = Console.ReadLine();
            if (string.IsNullOrEmpty(Hostname))
            {
                Hostname = "localhost";
                Console.WriteLine("localhost");
            }
            Console.WriteLine("please enter the port number (nothing when discover discovery server)");
            string Port = Console.ReadLine();
            Console.WriteLine("");
            int iPort = 4840;

            EndpointDescriptionCollection Endpoints = null;
            if (int.TryParse(Port, out iPort) && iPort > 0)
            {
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname, iPort);
            }
            else
            {
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname);
            }

            if (Endpoints.Count > 0)
            {
                Console.WriteLine("endpoints found:");
                int counter = 0;
                foreach (EndpointDescription Endpoint in Endpoints)
                {
                    Console.WriteLine(counter++.ToString() + " => " + Endpoint);
                }

                Console.WriteLine("please enter index of desired endpoint");
                string NumberOfEndpoint = Console.ReadLine();
                Console.WriteLine("");
                int iNumberOfEndpoint = -1;
                if (int.TryParse(NumberOfEndpoint, out iNumberOfEndpoint) && iNumberOfEndpoint > -1 && iNumberOfEndpoint < Endpoints.Count)
                {
                    //create a a SessionConfiguration with the selected endpoint and application name
                    SessionConfiguration sessionConfiguration = SessionConfiguration.Build(System.Reflection.Assembly.GetEntryAssembly().GetName().Name,
                                                                                          Endpoints[iNumberOfEndpoint]);

                    //output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath);

                    //Create a new opc client instance and pass your license information
                    using (DataAccessClient client = new DataAccessClient(LicenseUserName, LicenseSerial, sessionConfiguration))
                    {
                        Console.WriteLine("Info: license state => " + client.GetLicenceMessage());
                        Console.WriteLine("");

                        //register events
                        client.ServerConnectionLost += Client_ServerConnectionLost;
                        client.ServerConnected += Client_ServerConnected;
                        client.InternalSubscription_StateChanged += InternalSubscription_StateChanged;
                        client.KeepAlive += Client_KeepAlive;

                        string browsePath = string.Empty;
                        string mode = string.Empty;
                        do
                        {
                            Console.WriteLine("please enter 'r' for read or 'w' for write or return for exit");
                            mode = Console.ReadLine();
                            if (string.IsNullOrEmpty(mode)) break;
                            try
                            {
                                switch (mode.ToLower())
                                {
                                    case "r":
                                        Console.WriteLine("please enter browse path (e.g. 'Objects.Server.Data.Static.Scalar.Int64Value')");
                                        browsePath = Console.ReadLine();
                                        if (!string.IsNullOrEmpty(browsePath)) Console.WriteLine(browsePath + " Value => " + client.ReadValue(browsePath));
                                        break;
                                    case "w":
                                        Console.WriteLine("please enter browse path (e.g. 'Objects.Server.Data.Static.Scalar.Int64Value') ");
                                        browsePath = Console.ReadLine();
                                        if (!string.IsNullOrEmpty(browsePath))
                                        {
                                            Console.WriteLine("please input value for writing");
                                            string value = Console.ReadLine();
                                            Console.WriteLine(browsePath + " Result => " + client.Write(browsePath, value));
                                        }
                                        break;
                                    default:
                                        Console.WriteLine("unknown command " + mode);
                                        break;
                                }
                                Console.WriteLine();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                        while (!string.IsNullOrEmpty(mode));
                    }
                }
                else
                {
                    Console.WriteLine("invalid number of Endpoint");
                    Console.WriteLine();
                    Console.WriteLine("press enter for exit");
                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("no endpoints found");
                Console.WriteLine();
                Console.WriteLine("press enter for exit");
                Console.ReadLine();
            }


        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine("press enter for exit");
            Console.ReadLine();
        }

    }

    private void InternalSubscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " State of InternalSubscription changed to => " + e.Status.ToString());
    }

    private void Client_ServerConnected(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connected");
    }

    private void Client_ServerConnectionLost(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connection lost");
    }

    void Client_KeepAlive(Session session, KeepAliveEventArgs e)
    {
        //catch the keepalive event
    }

}
Imports PLCcom.Opc.Ua.Toolkit
Imports PLCcom.Opc.Ua.Client
Imports PLCcom.Opc.Ua

Module Program

    Sub Main()
        Try

            'TODO
            'Submit your license information from your license e-mail
            'Note: with invalid license information the client will be disconnected after 15 minutes
            Dim LicenseUserName As String = "<Enter your UserName here>"
            Dim LicenseSerial As String = "<Enter your Serial here>"

            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')")
            Dim Hostname As String = Console.ReadLine()
            If String.IsNullOrEmpty(Hostname) Then
                Hostname = "localhost"
                Console.WriteLine("localhost")
            End If
            Console.WriteLine("please enter the port number (nothing when discover discovery server)")
            Dim Port As String = Console.ReadLine()
            Console.WriteLine("")
            Dim iPort As Integer = 4840

            Dim Endpoints As EndpointDescriptionCollection = Nothing
            If Integer.TryParse(Port, iPort) AndAlso iPort > 0 Then
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname, iPort)
            Else
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname)
            End If

            If Endpoints.Count > 0 Then
                Console.WriteLine("endpoints found:")
                Dim counter As Integer = 0
                For Each Endpoint As EndpointDescription In Endpoints
                    Console.WriteLine(counter.ToString() & " => " & Endpoint.ToString)
                    counter += 1
                Next

                Console.WriteLine("please enter index of desired endpoint")
                Dim NumberOfEndpoint As String = Console.ReadLine()
                Console.WriteLine("")

                Dim iNumberOfEndpoint As Integer = -1
                If Integer.TryParse(NumberOfEndpoint, iNumberOfEndpoint) AndAlso iNumberOfEndpoint > -1 AndAlso iNumberOfEndpoint < Endpoints.Count Then
                    'create a a SessionConfiguration with the selected endpoint and application name
                    Dim sessionConfiguration As SessionConfiguration = SessionConfiguration.Build(System.Reflection.Assembly.GetEntryAssembly().GetName().Name, Endpoints(iNumberOfEndpoint))

                    'output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath)

                    'Create a New opc client instance and pass your license information
                    Using client As New DataAccessClient(LicenseUserName, LicenseSerial, sessionConfiguration)
                        Console.WriteLine("Info: license state => " & client.GetLicenceMessage())
                        Console.WriteLine("")

                        'register events
                        AddHandler client.ServerConnectionLost, AddressOf Client_ServerConnectionLost
                        AddHandler client.ServerConnected, AddressOf Client_ServerConnected
                        AddHandler client.InternalSubscription_StateChanged, AddressOf InternalSubscription_StateChanged
                        AddHandler client.KeepAlive, AddressOf Client_KeepAlive

                        Dim browsePath As String = String.Empty
                        Dim mode As String = String.Empty
                        Do
                            Console.WriteLine("please enter 'r' for read or 'w' for write or return for exit")
                            mode = Console.ReadLine()
                            If String.IsNullOrEmpty(mode) Then
                                Exit Do
                            End If
                            Try
                                Select Case mode.ToLower()
                                    Case "r"
                                        Console.WriteLine("please enter browse path (e.g. 'Objects.Server.Data.Static.Scalar.Int64Value')")
                                        browsePath = Console.ReadLine()
                                        If Not String.IsNullOrEmpty(browsePath) Then
                                            Console.WriteLine(browsePath & " Value => " & client.ReadValue(browsePath).ToString())
                                        End If
                                        Exit Select
                                    Case "w"
                                        Console.WriteLine("please enter browse path (e.g. 'Objects.Server.Data.Static.Scalar.Int64Value') ")
                                        browsePath = Console.ReadLine()
                                        If Not String.IsNullOrEmpty(browsePath) Then
                                            Console.WriteLine("please input value for writing")
                                            Dim value As String = Console.ReadLine()
                                            Console.WriteLine(browsePath & " Result => " & client.Write(browsePath, value).ToString())
                                        End If
                                        Exit Select
                                    Case Else
                                        Console.WriteLine("unknown command " & mode)
                                        Exit Select

                                End Select
                                Console.WriteLine()
                            Catch ex As Exception
                                Console.WriteLine(ex.Message)
                            End Try
                        Loop While Not String.IsNullOrEmpty(mode)
                    End Using

                Else
                    Console.WriteLine("invalid number of Endpoint")
                    Console.WriteLine()
                    Console.WriteLine("press enter for exit")
                    Console.ReadLine()
                End If
            Else
                Console.WriteLine("no endpoints found")
                Console.WriteLine()
                Console.WriteLine("press enter for exit")
                Console.ReadLine()


            End If
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.WriteLine("press enter for exit")
            Console.ReadLine()
        End Try

    End Sub


    Private Sub InternalSubscription_StateChanged(subscription As Subscription, e As SubscriptionStateChangedEventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " State of InternalSubscription changed to => " & e.Status.ToString())
    End Sub

    Private Sub Client_ServerConnected(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connected")
    End Sub

    Private Sub Client_ServerConnectionLost(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connection lost")
    End Sub

    Private Sub Client_KeepAlive(session As Session, e As KeepAliveEventArgs)
        'catch the keepalive event
    End Sub

End Module
package tutorials.t02_data_access;

import java.net.URI;
import java.util.Arrays;
import plccom.opc.ua.sdk.client.application.ClientConfiguration;
import plccom.opc.ua.sdk.client.application.SortDirection;
import plccom.opc.ua.sdk.client.application.UaClient;
import plccom.opc.ua.sdk.client.application.listener.SessionConnectionStateChangeListener;
import plccom.opc.ua.sdk.client.application.listener.SessionKeepAliveListener;
import plccom.opc.ua.sdk.client.core.attributes.UaAttributes;
import org.opcfoundation.ua.builtintypes.LocalizedText;
import org.opcfoundation.ua.builtintypes.NodeId;
import org.opcfoundation.ua.builtintypes.StatusCode;
import org.opcfoundation.ua.core.EndpointDescription;
import org.opcfoundation.ua.core.Identifiers;
import org.opcfoundation.ua.core.ReadResponse;
import org.opcfoundation.ua.core.ServerState;
import org.opcfoundation.ua.core.ServerStatusDataType;

public class Tutorial21_read_write implements SessionKeepAliveListener, SessionConnectionStateChangeListener {

	// Developer's TODO
	// Submit your license information from your license e-mail
	private final String LicenseUserName = "<Enter your UserName here>";
	private final String LicenseSerial = "<Enter your Serial here>";

	public static void main(String[] args) {
		Tutorial21_read_write prog = new Tutorial21_read_write();
		prog.start();
	}

	private void start() {
		try {

			String hostname = "localhost";
			int port = 4840;

			// create a discovery uri
			URI discoveryUri = new URI(String.format("opc.tcp://%s:%s", hostname, port));

			System.out.println(String.format("reading Endports from discoveryUri %s", discoveryUri.toString()));

			// Get endpoints from ua Server with discovery url
			EndpointDescription[] endpoints = UaClient.discoverEndpoints(discoveryUri);

			// sort endpoint by message security mode
			endpoints = UaClient.sortBySecurityLevel(endpoints, SortDirection.Asc);

			if (endpoints.length > 0) {

				// create Sessionconfiguration
				ClientConfiguration clientConfiguration = new ClientConfiguration(
						new LocalizedText(this.getClass().getSimpleName(), "en"), endpoints[0]);

				// Create new OPCUAClient
				UaClient myClient = new UaClient(LicenseUserName, LicenseSerial, clientConfiguration);
				try {
					// print license informations
					System.out.println(myClient.getLicenceMessage());

					myClient.addSessionKeepAliveListener(this);
					myClient.addSessionConnectionStateChangeListener(this);
					myClient.connect();

					///////////////////// read Values ////////////////////////

					// Read namespace Array
					ReadResponse res = myClient.read(Identifiers.Server_NamespaceArray, UaAttributes.Value);
					String[] namespaceArray = (String[]) res.getResults()[0].getValue().getValue();
					System.out.println(Arrays.toString(namespaceArray));

					// Read a variable by NodeId
					res = myClient.read(new NodeId(2, 10219), UaAttributes.Value);
					System.out.println(String.format("Result: %s Statuscode: %s",
							res.getResults()[0].getValue().toString(), res.getResults()[0].getStatusCode().toString()));

					// Read a variable by browse path
					res = myClient.read(myClient.getNodeIdByPath("Objects.Server.Data.Static.Scalar.Int16Value"),
							UaAttributes.Value);
					System.out.println(String.format("Result: %s Statuscode: %s",
							res.getResults()[0].getValue().toString(), res.getResults()[0].getStatusCode().toString()));

					///////////////////// read Attributes
					///////////////////// ////////////////////////

					res = myClient.read(myClient.getNodeIdByPath("Objects.Server.Data.Static.Scalar.Int16Value"),
							UaAttributes.DataType);
					System.out.println(String.format("Result: %s Statuscode: %s",
							res.getResults()[0].getValue().toString(), res.getResults()[0].getStatusCode().toString()));

					res = myClient.read((NodeId) (res.getResults()[0].getValue().getValue()), UaAttributes.BrowseName);
					System.out.println(String.format("Result: %s Statuscode: %s",
							res.getResults()[0].getValue().toString(), res.getResults()[0].getStatusCode().toString()));

					///////////////////// write values //////////////////////

					// write value of a variable to 1111 by NodeId
					StatusCode rsc = myClient.write(new NodeId(2, 10219), (short) 1111, UaAttributes.Value);
					System.out.println(String.format("Statuscode for write operation: %s", rsc.toString()));

					// write value of a variable to 11 by browse path
					rsc = myClient.write(myClient.getNodeIdByPath("Objects.Server.Data.Static.Scalar.Int16Value"),
							(short) 11, UaAttributes.Value);
					System.out.println(String.format("Statuscode for write operation: %s", rsc.toString()));

				} finally {
					// shutdown client
					myClient.close();
				}
			} else {
				System.out.println("no endpoints found");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void onSessionKeepAlive(ServerStatusDataType serverStatusDataType, ServerState serverState) {

		System.out.println("incoming Keepalive => Serverstate: " + serverState.toString());
	}

	@Override
	public void onSessionConnectionStateChanged(boolean isConnected) {
		System.out.println("incoming SessionConnectionState => Session Connected = " + isConnected);
	}

}

Example: Read or write values

Monitoring items

Das Überwachen von Items kann entweder über die NodeId oder direkt über den kompletten Namen/Pfad des Knotens erfolgen:

Beispiel:
...
//create and register monitoring item
client.StartMonitoringItem("Objects.Server.Data.Dynamic.Scalar.Int64Value", Client_MonitorNotification);
...

//catch the monitoring event
private void Client_MonitorNotification(string Identifier, MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
{
MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification;
Console.WriteLine(Identifier + " " + monitoredItem.StartNodeId + " Value: " + notification.Value + " Status: " + notification.Value.StatusCode.ToString());
}
 
Nachfolgend ein komplettes ausführbares Beispiel:
  • C#
  • Visual Basic
  • Java
using System;
using PLCcom.Opc.Ua;
using PLCcom.Opc.Ua.Client;
using PLCcom.Opc.Ua.Toolkit;

class Program
{
    static void Main(string[] args)
    {
        Program program = new Program();
        program.Start();
    }
    void Start()
    {
        try
        {
            //TODO
            //Submit your license information from your license e-mail
            //Note: with invalid license information the client will be disconnected after 15 minutes
            string LicenseUserName = "<Enter your UserName here>";
            string LicenseSerial = "<Enter your Serial here>";

            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')");
            string Hostname = Console.ReadLine();
            if (string.IsNullOrEmpty(Hostname))
            {
                Hostname = "localhost";
                Console.WriteLine("localhost");
            }
            Console.WriteLine("please enter the port number (nothing when discover discovery server)");
            string Port = Console.ReadLine();
            Console.WriteLine("");
            int iPort = 4840;

            EndpointDescriptionCollection Endpoints = null;
            if (int.TryParse(Port, out iPort) && iPort > 0)
            {
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname, iPort);
            }
            else
            {
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname);
            }


            if (Endpoints.Count > 0)
            {
                Console.WriteLine("endpoints found:");
                int counter = 0;
                foreach (EndpointDescription Endpoint in Endpoints)
                {
                    Console.WriteLine(counter++.ToString() + " => " + Endpoint);
                }

                Console.WriteLine("please enter index of desired endpoint");
                string NumberOfEndpoint = Console.ReadLine();
                Console.WriteLine("");

                int iNumberOfEndpoint = -1;
                if (int.TryParse(NumberOfEndpoint, out iNumberOfEndpoint) && iNumberOfEndpoint > -1 && iNumberOfEndpoint < Endpoints.Count)
                {
                    //create a a SessionConfiguration with the selected endpoint and application name
                    SessionConfiguration sessionConfiguration = SessionConfiguration.Build(System.Reflection.Assembly.GetEntryAssembly().GetName().Name,
                                                                                         Endpoints[iNumberOfEndpoint]);

                    //output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath);

                    //Create a new opc client instance and pass your license information
                    using (DataAccessClient client = new DataAccessClient(LicenseUserName, LicenseSerial, sessionConfiguration))
                    {
                        Console.WriteLine("Info: license state => " + client.GetLicenceMessage());
                        Console.WriteLine("");

                        //register events
                        client.ServerConnectionLost += Client_ServerConnectionLost;
                        client.ServerConnected += Client_ServerConnected;
                        client.InternalSubscription_StateChanged += InternalSubscription_StateChanged;
                        client.KeepAlive += Client_KeepAlive;
                        client.ConnectSession();

                        string browsePath = string.Empty;

                        Console.WriteLine("please enter browse path (e.g. 'Objects.Topics.S7_1500.DataBlocks.Datenbaustein_3.dword12_bitleiste') or return for exit");
                        browsePath = Console.ReadLine();
                        if (!string.IsNullOrEmpty(browsePath))
                        {
                            try
                            {
                                client.StartMonitoringItem(browsePath, Client_MonitorNotification);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }

                        Console.WriteLine();
                        Console.WriteLine("press enter for exit");
                        Console.ReadLine();
                    }
                }
                else
                {
                    Console.WriteLine("invalid number of Endpoint");

                }
            }
            else
            {
                Console.WriteLine("no endpoints found");
            }

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine("press enter for exit");
            Console.ReadLine();
        }
    }

    private void Client_MonitorNotification(string Identifier,
                                            MonitoredItem monitoredItem,
                                            MonitoredItemNotificationEventArgs e)
    {
        MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification;
        Console.WriteLine(Identifier + " " + monitoredItem.StartNodeId + " Value: " + notification.Value + " Status: " + notification.Value.StatusCode.ToString());
    }

    private void InternalSubscription_StateChanged(Subscription subscription, SubscriptionStateChangedEventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " State of InternalSubscription changed to => " + e.Status.ToString());
    }

    private void Client_ServerConnected(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connected");
    }

    private void Client_ServerConnectionLost(object sender, EventArgs e)
    {
        Console.WriteLine(DateTime.Now.ToLocalTime() + " Session connection lost");
    }

    void Client_KeepAlive(Session session, KeepAliveEventArgs e)
    {
        //catch the keepalive event
    }

}
Imports PLCcom.Opc.Ua
Imports PLCcom.Opc.Ua.Client
Imports PLCcom.Opc.Ua.Toolkit

Module Program

#Region "private member"
    Private client As DataAccessClient = Nothing
#End Region

    Sub Main()
        Try

            'TODO
            'Submit your license information from your license e-mail
            'Note: with invalid license information the client will be disconnected after 15 minutes
            Dim LicenseUserName As String = "<Enter your UserName here>"
            Dim LicenseSerial As String = "<Enter your Serial here>"

            Console.WriteLine("please enter the IP address or hostname (nothing for 'localhost')")
            Dim Hostname As String = Console.ReadLine()
            If String.IsNullOrEmpty(Hostname) Then
                Hostname = "localhost"
                Console.WriteLine("localhost")
            End If
            Console.WriteLine("please enter the port number (nothing when discover discovery server)")
            Dim Port As String = Console.ReadLine()
            Console.WriteLine("")
            Dim iPort As Integer = 4840

            Dim Endpoints As EndpointDescriptionCollection = Nothing
            If Integer.TryParse(Port, iPort) AndAlso iPort > 0 Then
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname, iPort)
            Else
                Endpoints = OpcUaClient.GetAllEndpoints(Hostname)
            End If

            If Endpoints.Count > 0 Then
                Console.WriteLine("endpoints found:")
                Dim counter As Integer = 0
                For Each Endpoint As EndpointDescription In Endpoints
                    Console.WriteLine(counter.ToString() & " => " & Endpoint.ToString)
                    counter += 1
                Next

                Console.WriteLine("please enter index of desired endpoint")
                Dim NumberOfEndpoint As String = Console.ReadLine()
                Console.WriteLine("")

                Dim iNumberOfEndpoint As Integer = -1
                If Integer.TryParse(NumberOfEndpoint, iNumberOfEndpoint) AndAlso iNumberOfEndpoint > -1 AndAlso iNumberOfEndpoint < Endpoints.Count Then
                    'create a a SessionConfiguration with the selected endpoint and application name
                    Dim sessionConfiguration As SessionConfiguration = SessionConfiguration.Build(System.Reflection.Assembly.GetEntryAssembly().GetName().Name, Endpoints(iNumberOfEndpoint))

                    'output certificate store path
                    Console.WriteLine("Info: Sessionconfiguration created, certificate store path => " + sessionConfiguration.CertificateStorePath)

                    'Create a New opc client instance and pass your license information
                    Using client As New DataAccessClient(LicenseUserName, LicenseSerial, sessionConfiguration)

                        Console.WriteLine("Info: license state => " & client.GetLicenceMessage())
                        Console.WriteLine("")

                        'register events
                        AddHandler client.ServerConnectionLost, AddressOf Client_ServerConnectionLost
                        AddHandler client.ServerConnected, AddressOf Client_ServerConnected
                        AddHandler client.InternalSubscription_StateChanged, AddressOf InternalSubscription_StateChanged
                        AddHandler client.KeepAlive, AddressOf Client_KeepAlive

                        Dim browsePath As String = String.Empty

                        Console.WriteLine("please enter browse path (e.g. 'Objects.Server.Data.Dynamic.Scalar.Int64Value') or return for exit")
                        browsePath = Console.ReadLine()
                        If Not String.IsNullOrEmpty(browsePath) Then
                            Try
                                client.StartMonitoringItem(browsePath, AddressOf Client_MonitorNotification)
                            Catch ex As Exception
                                Console.WriteLine(ex.Message)
                            End Try
                        End If

                        Console.WriteLine()
                        Console.WriteLine("press enter for exit")
                        Console.ReadLine()
                    End Using
                Else

                    Console.WriteLine("invalid number of Endpoint")
                End If
            Else
                Console.WriteLine("no endpoints found")
            End If

        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.WriteLine("press enter for exit")
            Console.ReadLine()
        Finally
            If Not IsNothing(client) AndAlso client.GetSessionState().Equals(SessionState.Connected) Then
                client.DisconnectSession()
            End If
        End Try

    End Sub

    Private Sub Client_MonitorNotification(Identifier As String, monitoredItem As MonitoredItem, e As MonitoredItemNotificationEventArgs)
        Dim notification As MonitoredItemNotification = TryCast(e.NotificationValue, MonitoredItemNotification)
        Console.WriteLine((Identifier & " " & Convert.ToString(monitoredItem.StartNodeId).ToString() & " Value: ") + notification.Value.ToString() & " Status: " & notification.Value.StatusCode.ToString())
    End Sub

    Private Sub InternalSubscription_StateChanged(subscription As Subscription, e As SubscriptionStateChangedEventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " State of InternalSubscription changed to => " & e.Status.ToString())
    End Sub

    Private Sub Client_ServerConnected(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connected")
    End Sub

    Private Sub Client_ServerConnectionLost(sender As Object, e As EventArgs)
        Console.WriteLine(DateTime.Now.ToLocalTime() & " Session connection lost")
    End Sub

    Private Sub Client_KeepAlive(session As Session, e As KeepAliveEventArgs)
        'catch the keepalive event
    End Sub

End Module
package tutorials.t02_data_access;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import plccom.opc.ua.sdk.client.application.ClientConfiguration;
import plccom.opc.ua.sdk.client.application.MonitoredItem;
import plccom.opc.ua.sdk.client.application.SortDirection;
import plccom.opc.ua.sdk.client.application.UaClient;
import plccom.opc.ua.sdk.client.application.UaSubscription;
import plccom.opc.ua.sdk.client.application.listener.MonitoredItemNotificationListener;
import plccom.opc.ua.sdk.client.application.listener.SessionConnectionStateChangeListener;
import plccom.opc.ua.sdk.client.application.listener.SessionKeepAliveListener;
import plccom.opc.ua.sdk.client.application.listener.SubscriptionListener;
import plccom.opc.ua.sdk.client.core.attributes.UaAttributes;
import org.opcfoundation.ua.builtintypes.DataValue;
import org.opcfoundation.ua.builtintypes.DateTime;
import org.opcfoundation.ua.builtintypes.LocalizedText;
import org.opcfoundation.ua.builtintypes.NodeId;
import org.opcfoundation.ua.builtintypes.StatusCode;
import org.opcfoundation.ua.common.ServiceResultException;
import org.opcfoundation.ua.core.EndpointDescription;
import org.opcfoundation.ua.core.EventFieldList;
import org.opcfoundation.ua.core.Identifiers;
import org.opcfoundation.ua.core.MonitoredItemCreateRequest;
import org.opcfoundation.ua.core.MonitoringMode;
import org.opcfoundation.ua.core.MonitoringParameters;
import org.opcfoundation.ua.core.ReadValueId;
import org.opcfoundation.ua.core.ServerState;
import org.opcfoundation.ua.core.ServerStatusDataType;

public class Tutorial23_monitoring_nodes implements SessionKeepAliveListener, SessionConnectionStateChangeListener,
		MonitoredItemNotificationListener, SubscriptionListener {

	// Developer's TODO
	// Submit your license information from your license e-mail
	private final String LicenseUserName = "<Enter your UserName here>";
	private final String LicenseSerial = "<Enter your Serial here>";

	public static void main(String[] args) {
		Tutorial23_monitoring_nodes prog = new Tutorial23_monitoring_nodes();
		prog.start();
	}

	private void start() {
		try {

			String hostname = "localhost";
			int port = 4840;

			// create a discovery uri
			URI discoveryUri = new URI(String.format("opc.tcp://%s:%s", hostname, port));

			System.out.println(String.format("reading Endports from discoveryUri %s", discoveryUri.toString()));

			// Get endpoints from ua Server with discovery url
			EndpointDescription[] endpoints = UaClient.discoverEndpoints(discoveryUri);

			// sort endpoint by message security mode
			endpoints = UaClient.sortBySecurityLevel(endpoints, SortDirection.Asc);

			if (endpoints.length > 0) {

				// create Sessionconfiguration and set the default publishing
				// interval
				ClientConfiguration clientConfiguration = new ClientConfiguration(
						new LocalizedText("ExampleApplication", "en"), endpoints[0]);

				// set default publishing interval to 1000 milliseconds
				clientConfiguration.setDefaultPublishingInterval(1000.0);

				// enable auto connect functionality
				// set automatic reconnect after 1000 milliseconds in case of losing connection
				clientConfiguration.setAutoConnectEnabled(true, 1000);

				// Create new OPCUAClient
				try (UaClient myClient = new UaClient(LicenseUserName, LicenseSerial, clientConfiguration)) {
					// print license informations
					System.out.println(myClient.getLicenceMessage());

					myClient.addSessionKeepAliveListener(this);
					myClient.addSessionConnectionStateChangeListener(this);

					myClient.getSubscriptionManager().addSubscriptionListener(this);

					// Setting up monitoring parameters
					MonitoringParameters parameters = new MonitoringParameters();
					parameters.setSamplingInterval(1000.0);

					// Create the request list
					List<MonitoredItemCreateRequest> requests = new ArrayList<MonitoredItemCreateRequest>();

					// create and add a create request for a monitoring item
					// identificated by browse path
					try {

						ReadValueId readValueId = new ReadValueId(
								myClient.getNodeIdByPath("Objects.Server.Data.Dynamic.Scalar.Int32Value"),
								UaAttributes.Value.getValue(), null, null);

						requests.add(new MonitoredItemCreateRequest(readValueId, MonitoringMode.Reporting, parameters));
					} catch (ServiceResultException e) {
						e.printStackTrace();
						System.out.println(e.getMessage());
					}

					// create and add a create request for a monitoring item
					// identificated by node
					{
						ReadValueId readValueId = new ReadValueId(Identifiers.Server_ServerStatus_CurrentTime,
								UaAttributes.Value.getValue(), null, null);

						requests.add(new MonitoredItemCreateRequest(readValueId, MonitoringMode.Reporting, parameters));
					}
					// create and add a create request for a monitoring item
					// identificated by NodeId
					try {
						ReadValueId readValueId = new ReadValueId(new NodeId(2, 10847), UaAttributes.Value.getValue(),
								null, null);

						requests.add(new MonitoredItemCreateRequest(readValueId, MonitoringMode.Reporting, parameters));
					} catch (Exception e) {
						System.out.println(e.getMessage());
					}

					// create and add a subscription
					UaSubscription subscription = myClient.getSubscriptionManager().createSubscription();

					// Create, monitoring items and add monitoring item event
					// listener
					List<MonitoredItem> monitoredItems = subscription.createMonitoredItems(requests, new MonitoredItemNotificationListener() {
						
						@Override
						public void onValueNotification(MonitoredItem monitoredItem, DataValue value) {
							// TODO Automatisch generierter Methodenstub
							
						}
						
						@Override
						public void onEventNotification(MonitoredItem monitoredItem, EventFieldList eventFieldList) {
							// TODO Automatisch generierter Methodenstub
							
						}
					});

					// Logging output
					for (MonitoredItem monitoredItem : monitoredItems)
						if (monitoredItem.getStatusCode().isGood())
							System.out.println(String.format("monitoredItem successfully %s created",
									monitoredItem.getDisplayName()));
						else
							System.out.println(String.format("cannot create monitoredItem %s, Statuscode: %s",
									monitoredItem.getDisplayName(), monitoredItem.getStatusCode()));

					System.in.read();

					// cleaning up
					myClient.getSubscriptionManager().closeAndClearAllSubscriptions();

				}

			} else {
				System.out.println("no endpoints found");
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

	@Override
	public void onValueNotification(MonitoredItem monitoredItem, DataValue value) {
		System.out.println(String.format("Value notification for NodeId %s arrived with Value: %s StatusCode: %s",
				monitoredItem.getReadValueId().getNodeId().toString(), value.getValue().toString(),
				value.getStatusCode().toString()));
	}

	@Override
	public void onEventNotification(MonitoredItem monitoredItem, EventFieldList eventFieldList) {
		System.out.println(String.format("Event notification for NodeId %s arrived", monitoredItem.getDisplayName()));
	}

	@Override
	public void onStatusChangeNotification(UaSubscription subscription, StatusCode statusCode) {
		System.out.println(String.format("StatusChangeNotification with statusCode %s on subscription %s", statusCode,
				subscription));

	}

	@Override
	public void onPublishFailure(ServiceResultException error) {
		System.out.println(String.format("onPublishFailure %s ", error.getMessage()));

	}

	@Override
	public void onNotificationDataLost(UaSubscription subscription) {
		System.out.println(String.format("onNotificationDataLost on subscription %s", subscription));

	}

	@Override
	public void onSubscriptionKeepAlive(UaSubscription subscription, DateTime publishTime) {
		System.out.println(String.format("onSubscriptionKeepAlive with subscription %s", subscription));

	}

	@Override
	public void onSessionKeepAlive(ServerStatusDataType serverStatusDataType, ServerState serverState) {
		System.out.println("incoming Keepalive => Serverstate: " + serverState.toString());
	}

	@Override
	public void onSessionConnectionStateChanged(boolean isConnected) {
		System.out.println("incoming SessionConnectionState => Session Connected = " + isConnected);
	}

}

Example: Monitoring items