OPC Studio User's Guide and Reference
RegisterMultipleNodes Method (IEasyUAClientNodeRegistrationExtension)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.Services.Extensions Namespace > IEasyUAClientNodeRegistrationExtension Class : RegisterMultipleNodes Method
The client node registration object that will perform the operation.

This is typically obtained by calling System.IServiceProvider.GetService(System.Type) on the OpcLabs.EasyOpc.UA.IEasyUAClient (EasyUAClient object) with the type of OpcLabs.EasyOpc.UA.Services.IEasyUAClientNodeRegistration as an argument.

The value of this parameter cannot be null (Nothing in Visual Basic).

The endpoint descriptor of the server on which the nodes reside.

Because the OpcLabs.EasyOpc.UA.UAEndpointDescriptor has implicit conversions from System.String and System.Uri, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the endpoint URL, or a so-called OPC UA endpoint descriptor string), or a System.Uri object, in place of this parameter, and the corresponding endpoint descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.UA.UAEndpointDescriptor.FromString or OpcLabs.EasyOpc.UA.UAEndpointDescriptor.FromUri static method instead.

Also, because the OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement and OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement have an implicit conversion to OpcLabs.EasyOpc.UA.UAEndpointDescriptor, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement (results from OPC UA discovery) in place of this parameter, and the corresponding endpoint descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can convert a (non-null) OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement to OpcLabs.EasyOpc.UA.UAEndpointDescriptor using the OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement.ToUAEndpointDescriptor or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement.ToUAEndpointDescriptor method instead.

If you are using OPC Wizard (for server development), an implicit conversion from OpcLabs.EasyOpc.UA.EasyUAServerCore can be used in the same way to simply pass the server object in place of this parameter, which will use its OpcLabs.EasyOpc.UA.EasyUAServerCore.EffectiveServerDescriptor property for the connection.

The value of this parameter cannot be null (Nothing in Visual Basic).

An array of node descriptors for nodes that should be registered.

Because the OpcLabs.EasyOpc.UA.UANodeDescriptor has implicit conversions from OpcLabs.EasyOpc.UA.AddressSpace.UANodeId, OpcLabs.EasyOpc.UA.AddressSpace.UANodeElement, OpcLabs.EasyOpc.UA.Navigation.UABrowsePath and System.String, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.AddressSpace.UANodeId object (representing the Id of the OPC UA node), a node element object (from OPC UA browsing), OpcLabs.EasyOpc.UA.Navigation.UABrowsePath object (representing OPC UA absolute browse path), or a string (with expanded node Id text) in place of this parameter, and the corresponding node descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.UA.UANodeDescriptor.FromString, OpcLabs.EasyOpc.UA.UANodeDescriptor.FromUABrowsePath, OpcLabs.EasyOpc.UA.UANodeDescriptor.FromUANodeElement or OpcLabs.EasyOpc.UA.UANodeDescriptor.FromUANodeId static method instead.

If you are using OPC Wizard (for server development), an implicit conversion from OpcLabs.EasyOpc.UA.NodeSpace.UAServerNode can be used in the same way to simply pass the server node in place of this parameter, which will use its OpcLabs.EasyOpc.UA.NodeSpace.UAServerNode.EffectiveNodeDescriptor property for the operation.

The value of this parameter cannot be null (Nothing in Visual Basic).

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Registers the nodes specified by a single endpoint descriptor, and an array of node descriptors.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Shared Function RegisterMultipleNodes( _
   ByVal clientNodeRegistration As IEasyUAClientNodeRegistration, _
   ByVal endpointDescriptor As UAEndpointDescriptor, _
   ByVal nodeDescriptorArray() As UANodeDescriptor _
) As Integer()
'Usage
 
Dim clientNodeRegistration As IEasyUAClientNodeRegistration
Dim endpointDescriptor As UAEndpointDescriptor
Dim nodeDescriptorArray() As UANodeDescriptor
Dim value() As Integer
 
value = IEasyUAClientNodeRegistrationExtension.RegisterMultipleNodes(clientNodeRegistration, endpointDescriptor, nodeDescriptorArray)

Parameters

clientNodeRegistration
The client node registration object that will perform the operation.

This is typically obtained by calling System.IServiceProvider.GetService(System.Type) on the OpcLabs.EasyOpc.UA.IEasyUAClient (EasyUAClient object) with the type of OpcLabs.EasyOpc.UA.Services.IEasyUAClientNodeRegistration as an argument.

The value of this parameter cannot be null (Nothing in Visual Basic).

endpointDescriptor
The endpoint descriptor of the server on which the nodes reside.

Because the OpcLabs.EasyOpc.UA.UAEndpointDescriptor has implicit conversions from System.String and System.Uri, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the endpoint URL, or a so-called OPC UA endpoint descriptor string), or a System.Uri object, in place of this parameter, and the corresponding endpoint descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.UA.UAEndpointDescriptor.FromString or OpcLabs.EasyOpc.UA.UAEndpointDescriptor.FromUri static method instead.

Also, because the OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement and OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement have an implicit conversion to OpcLabs.EasyOpc.UA.UAEndpointDescriptor, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement (results from OPC UA discovery) in place of this parameter, and the corresponding endpoint descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can convert a (non-null) OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement to OpcLabs.EasyOpc.UA.UAEndpointDescriptor using the OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement.ToUAEndpointDescriptor or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement.ToUAEndpointDescriptor method instead.

If you are using OPC Wizard (for server development), an implicit conversion from OpcLabs.EasyOpc.UA.EasyUAServerCore can be used in the same way to simply pass the server object in place of this parameter, which will use its OpcLabs.EasyOpc.UA.EasyUAServerCore.EffectiveServerDescriptor property for the connection.

The value of this parameter cannot be null (Nothing in Visual Basic).

nodeDescriptorArray
An array of node descriptors for nodes that should be registered.

Because the OpcLabs.EasyOpc.UA.UANodeDescriptor has implicit conversions from OpcLabs.EasyOpc.UA.AddressSpace.UANodeId, OpcLabs.EasyOpc.UA.AddressSpace.UANodeElement, OpcLabs.EasyOpc.UA.Navigation.UABrowsePath and System.String, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.AddressSpace.UANodeId object (representing the Id of the OPC UA node), a node element object (from OPC UA browsing), OpcLabs.EasyOpc.UA.Navigation.UABrowsePath object (representing OPC UA absolute browse path), or a string (with expanded node Id text) in place of this parameter, and the corresponding node descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.UA.UANodeDescriptor.FromString, OpcLabs.EasyOpc.UA.UANodeDescriptor.FromUABrowsePath, OpcLabs.EasyOpc.UA.UANodeDescriptor.FromUANodeElement or OpcLabs.EasyOpc.UA.UANodeDescriptor.FromUANodeId static method instead.

If you are using OPC Wizard (for server development), an implicit conversion from OpcLabs.EasyOpc.UA.NodeSpace.UAServerNode can be used in the same way to simply pass the server node in place of this parameter, which will use its OpcLabs.EasyOpc.UA.NodeSpace.UAServerNode.EffectiveNodeDescriptor property for the operation.

The value of this parameter cannot be null (Nothing in Visual Basic).

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Return Value

Returns an array of integer handles that can be used for unregistering the nodes. Indexes in the returned array correspond with indexes in the nodeDescriptorArray.

This method never returns null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

The method may perform the registration asynchronously.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

Example
// This example shows how to register and unregister multiple nodes in an OPC UA server, and use this approach together with
// connection locking.
//
// Node registration (with OPC UA servers that support it) can improve performance with repeatedly accessed nodes.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using Microsoft.Extensions.DependencyInjection;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;
using OpcLabs.EasyOpc.UA.Services;
using OpcLabs.EasyOpc.UA.Services.Extensions;

namespace UADocExamples._EasyUAClientNodeRegistration
{
    class RegisterAndUnregisterMultipleNodes
    {
        public static void Main1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object.
            using (var client = new EasyUAClient())
            {
                // Obtain the client node registration service.
                IEasyUAClientNodeRegistration clientNodeRegistration = client.GetRequiredService<IEasyUAClientNodeRegistration>();

                // Obtain the client connection control service.
                IEasyUAClientConnectionControl clientConnectionControl = client.GetRequiredService<IEasyUAClientConnectionControl>();

                var nodeDescriptorArray = new UANodeDescriptor[]
                {
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[0]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[4]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[8]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[12]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[16]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[20]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[24]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[28]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[32]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[36]"
                };

                Console.WriteLine("Registering nodes");
                int[] registrationHandleArray = clientNodeRegistration.RegisterMultipleNodes(endpointDescriptor, nodeDescriptorArray);

                Console.WriteLine("Locking the connection");
                // Locking the connection will attempt to open it, and when successful, the nodes will be registered with
                // the server at that time. The use of locking is not necessary, but it may bring benefits together with the
                // node registration. See the conceptual documentation for more information.
                int lockHandle = clientConnectionControl.LockConnection(endpointDescriptor);

                Console.WriteLine("Waiting for 10 seconds...");
                // The example uses this delay to demonstrate the fact that your code might have other tasks to do, before
                // it accesses the previously registered nodes.
                System.Threading.Thread.Sleep(10 * 1000);

                Console.WriteLine("Reading (1)");
                UAAttributeDataResult[] resultArray1 = client.ReadMultiple(endpointDescriptor, nodeDescriptorArray);
                foreach (UAAttributeDataResult result in resultArray1)
                    Console.WriteLine(result);

                Console.WriteLine("Reading (2)");
                UAAttributeDataResult[] resultArray2 = client.ReadMultiple(endpointDescriptor, nodeDescriptorArray);
                foreach (UAAttributeDataResult result in resultArray2)
                    Console.WriteLine(result);

                Console.WriteLine("Unlocking the connection");
                clientConnectionControl.UnlockConnection(lockHandle);

                Console.WriteLine("Unregistering nodes");
                clientNodeRegistration.UnregisterMultipleNodes(registrationHandleArray);

                Console.WriteLine("Finished.");
            }
        }
    }
}
' This example shows how to register and unregister multiple nodes in an OPC UA server, and use this approach together with
' connection locking.
'
' Node registration (with OPC UA servers that support it) can improve performance with repeatedly accessed nodes.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports Microsoft.Extensions.DependencyInjection
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel
Imports OpcLabs.EasyOpc.UA.Services
Imports OpcLabs.EasyOpc.UA.Services.Extensions

Namespace _EasyUAClientNodeRegistration
    Friend Class RegisterAndUnregisterMultipleNodes
        Public Shared Sub Main1()
            Dim endpointDescriptor As UAEndpointDescriptor =
                    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
            ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            ' or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            ' Instantiate the client.
            Using client = New EasyUAClient()
                ' Obtain the client node registration service.
                Dim clientNodeRegistration As IEasyUAClientNodeRegistration = client.GetRequiredService(Of IEasyUAClientNodeRegistration)

                ' Obtain the client connection control service.
                Dim clientConnectionControl As IEasyUAClientConnectionControl = client.GetRequiredService(Of IEasyUAClientConnectionControl)

                Dim nodeDescriptorArray = New UANodeDescriptor() {
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[0]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[4]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[8]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[12]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[16]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[20]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[24]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[28]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[32]",
                    "nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[36]"
                }

                Console.WriteLine("Registering nodes")
                Dim registrationHandleArray() As Integer = clientNodeRegistration.RegisterMultipleNodes(endpointDescriptor, nodeDescriptorArray)

                Console.WriteLine("Locking the connection")
                ' Locking the connection will attempt to open it, and when successful, the nodes will be registered with
                ' the server at that time. The use of locking is not necessary, but it may bring benefits together with the
                ' node registration. See the conceptual documentation for more information.
                Dim lockHandle As Integer = clientConnectionControl.LockConnection(endpointDescriptor)

                Console.WriteLine("Waiting for 10 seconds...")
                ' The example uses this delay to demonstrate the fact that your code might have other tasks to do, before
                ' it accesses the previously registered nodes.
                System.Threading.Thread.Sleep(10 * 1000)

                Console.WriteLine("Reading (1)")
                Dim resultArray1() As UAAttributeDataResult = client.ReadMultiple(endpointDescriptor, nodeDescriptorArray)
                For Each result As UAAttributeDataResult In resultArray1
                    Console.WriteLine(result)
                Next result

                Console.WriteLine("Reading (2)")
                Dim resultArray2() As UAAttributeDataResult = client.ReadMultiple(endpointDescriptor, nodeDescriptorArray)
                For Each result As UAAttributeDataResult In resultArray2
                    Console.WriteLine(result)
                Next result

                Console.WriteLine("Unlocking the connection")
                clientConnectionControl.UnlockConnection(lockHandle)

                Console.WriteLine("Unregistering nodes")
                clientNodeRegistration.UnregisterMultipleNodes(registrationHandleArray)

                Console.WriteLine("Finished.")
            End Using
        End Sub
    End Class
End Namespace
# This example shows how to register and unregister multiple nodes in an OPC UA server, and use this approach together
# with connection locking.
#
# Node registration (with OPC UA servers that support it) can improve performance with repeatedly accessed nodes.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from Microsoft.Extensions.DependencyInjection import *
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *
from OpcLabs.EasyOpc.UA.Services import *
from OpcLabs.EasyOpc.UA.Services.Extensions import *


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

# Instantiate the client object.
client = None
try:
    client = EasyUAClient()

    # Obtain the client connection monitoring service.
    clientNodeRegistration = ServiceProviderServiceExtensions.GetRequiredService[IEasyUAClientNodeRegistration](client)
    if clientNodeRegistration is None:
        print('The client connection monitoring service is not available.')
        exit()

    # Obtain the client connection control service.
    clientConnectionControl = ServiceProviderServiceExtensions.GetRequiredService[IEasyUAClientConnectionControl](client)
    if clientConnectionControl is None:
        print('The client connection control service is not available.')
        exit()

    nodeDescriptorArray = [
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[0]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[4]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[8]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[12]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[16]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[20]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[24]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[28]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[32]'),
        UANodeDescriptor('nsu=http://samples.org/UA/memorybuffer/Instance ;ns=8;s=UInt32[36]'),
    ]

    print('Registering nodes')
    registrationHandleArray = IEasyUAClientNodeRegistrationExtension.RegisterMultipleNodes(clientNodeRegistration,
                                                                                           endpointDescriptor,
                                                                                           nodeDescriptorArray)

    print('Locking the connection')
    # Locking the connection will attempt to open it, and when successful, the nodes will be registered with
    # the server at that time. The use of locking is not necessary, but it may bring benefits together with the
    # node registration. See the conceptual documentation for more information.
    lockHandle = clientConnectionControl.LockConnection(endpointDescriptor)

    print('Waiting for 10 seconds...')
    # The example uses this delay to demonstrate the fact that your code might have other tasks to do, before
    # it accesses the previously registered nodes.
    time.sleep(10)

    print('Reading (1)')
    attributeDataResultArray1 = IEasyUAClientExtension.ReadMultiple(client, endpointDescriptor, nodeDescriptorArray)
    for attributeDataResult in attributeDataResultArray1:
        print(attributeDataResult)

    print('Reading (2)')
    attributeDataResultArray2 = IEasyUAClientExtension.ReadMultiple(client, endpointDescriptor, nodeDescriptorArray)
    for attributeDataResult in attributeDataResultArray2:
        print(attributeDataResult)

    print('Unlocking the connection')
    clientConnectionControl.UnlockConnection(lockHandle)

    print('Unregistering nodes')
    clientNodeRegistration.UnregisterMultipleNodes(registrationHandleArray)

    print('Finished.')

finally:
    client and client.Dispose()
// This example shows how to register and unregister multiple nodes with Unified Automation UA .NET SDK Bundle.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using Microsoft.Extensions.DependencyInjection;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;
using OpcLabs.EasyOpc.UA.Services;
using OpcLabs.EasyOpc.UA.Services.Extensions;

namespace UADocExamples.Specialized
{
    class UnifiedAutomation_UaSdkNetBundle
    {
        public static void RegisterAndUnregisterNodes()
        {
            UAEndpointDescriptor endpointDescriptor = "opc.tcp://localhost:48030/";

            // Instantiate the client object and hook events
            using (var client = new EasyUAClient())
            {
                // Obtain the client node registration service.
                IEasyUAClientNodeRegistration clientNodeRegistration =
                    client.GetRequiredService<IEasyUAClientNodeRegistration>();

                // Obtain the client connection control service.
                IEasyUAClientConnectionControl clientConnectionControl =
                    client.GetRequiredService<IEasyUAClientConnectionControl>();

                var nodeDescriptorArray = new UANodeDescriptor[]
                {
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable000",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable001",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable002",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable003",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable004",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable005",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable006",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable007",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable008",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable009"
                };

                Console.WriteLine("Registering nodes");
                int[] registrationHandleArray =
                    clientNodeRegistration.RegisterMultipleNodes(endpointDescriptor, nodeDescriptorArray);

                Console.WriteLine("Locking the connection");
                // Locking the connection will attempt to open it, and when successful, the nodes will be registered with
                // the server at that time. The use of locking is not necessary, but it may bring benefits together with the
                // node registration. See the conceptual documentation for more information.
                int lockHandle = clientConnectionControl.LockConnection(endpointDescriptor);

                Console.WriteLine("Waiting for 10 seconds...");
                // The example uses this delay to demonstrate the fact that your code might have other tasks to do, before
                // it accesses the previously registered nodes.
                System.Threading.Thread.Sleep(10 * 1000);

                Console.WriteLine("Reading (1)");
                UAAttributeDataResult[] resultArray1 = client.ReadMultiple(endpointDescriptor, nodeDescriptorArray);
                foreach (UAAttributeDataResult result in resultArray1)
                    Console.WriteLine(result);

                Console.WriteLine("Reading (2)");
                UAAttributeDataResult[] resultArray2 = client.ReadMultiple(endpointDescriptor, nodeDescriptorArray);
                foreach (UAAttributeDataResult result in resultArray2)
                    Console.WriteLine(result);

                Console.WriteLine("Unlocking the connection");
                clientConnectionControl.UnlockConnection(lockHandle);

                Console.WriteLine("Unregistering nodes");
                clientNodeRegistration.UnregisterMultipleNodes(registrationHandleArray);

                Console.WriteLine("Finished.");
            }
        }
    }
}
' This example shows how to register and unregister multiple nodes with Unified Automation UA .NET SDK Bundle.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports Microsoft.Extensions.DependencyInjection
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel
Imports OpcLabs.EasyOpc.UA.Services
Imports OpcLabs.EasyOpc.UA.Services.Extensions

Namespace Specialized
    Friend Class UnifiedAutomation_UaSdkNetBundle
        Public Shared Sub RegisterAndUnregisterNodes()
            Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://localhost:48030/"

            ' Instantiate the client object and hook events
            Using client = New EasyUAClient()
                ' Obtain the client node registration service.
                Dim clientNodeRegistration As IEasyUAClientNodeRegistration = client.GetRequiredService(Of IEasyUAClientNodeRegistration)

                ' Obtain the client connection control service.
                Dim clientConnectionControl As IEasyUAClientConnectionControl = client.GetRequiredService(Of IEasyUAClientConnectionControl)

                Dim nodeDescriptorArray = New UANodeDescriptor() {
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable000",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable001",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable002",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable003",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable004",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable005",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable006",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable007",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable008",
                    "nsu=http://www.unifiedautomation.com/DemoServer/ ;ns=2;s=Demo.Massfolder_Dynamic.Variable009"
                }

                Console.WriteLine("Registering nodes")
                Dim registrationHandleArray() As Integer = clientNodeRegistration.RegisterMultipleNodes(endpointDescriptor, nodeDescriptorArray)

                Console.WriteLine("Locking the connection")
                ' Locking the connection will attempt to open it, and when successful, the nodes will be registered with
                ' the server at that time. The use of locking is not necessary, but it may bring benefits together with the
                ' node registration. See the conceptual documentation for more information.
                Dim lockHandle As Integer = clientConnectionControl.LockConnection(endpointDescriptor)

                Console.WriteLine("Waiting for 10 seconds...")
                ' The example uses this delay to demonstrate the fact that your code might have other tasks to do, before
                ' it accesses the previously registered nodes.
                System.Threading.Thread.Sleep(10 * 1000)

                Console.WriteLine("Reading (1)")
                Dim resultArray1() As UAAttributeDataResult = client.ReadMultiple(endpointDescriptor, nodeDescriptorArray)
                For Each result As UAAttributeDataResult In resultArray1
                    Console.WriteLine(result)
                Next result

                Console.WriteLine("Reading (2)")
                Dim resultArray2() As UAAttributeDataResult = client.ReadMultiple(endpointDescriptor, nodeDescriptorArray)
                For Each result As UAAttributeDataResult In resultArray2
                    Console.WriteLine(result)
                Next result

                Console.WriteLine("Unlocking the connection")
                clientConnectionControl.UnlockConnection(lockHandle)

                Console.WriteLine("Unregistering nodes")
                clientNodeRegistration.UnregisterMultipleNodes(registrationHandleArray)

                Console.WriteLine("Finished.")
            End Using
        End Sub
    End Class
End Namespace
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also