OPC Studio User's Guide and Reference
Implicit Type Conversion Operator (UAServerNode)
Example 



OpcLabs.ServerOpcUA Assembly > OpcLabs.EasyOpc.UA.NodeSpace Namespace > UAServerNode Class : Implicit Type Conversion Operator
The server node to be converted.

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

Converts the specified server node to an OPC UA node descriptor for client usage.
Syntax
'Declaration
 
<NotNullAttribute()>
Public Operator Widening CType( _
   ByVal serverNode As UAServerNode _
) As UANodeDescriptor
'Usage
 
[NotNull()]
public UANodeDescriptor operator implicit( 
   UAServerNode serverNode
)
[NotNull()]
public:
operator UANodeDescriptor^ ( 
   UAServerNode^ serverNode
)

Parameters

serverNode
The server node to be converted.

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

Return Value

Returns an OPC UA node descriptor that can be used by client objects (such as OpcLabs.EasyOpc.UA.EasyUAClient) to operate on this node.

Because there are implicit conversions to OpcLabs.EasyOpc.UA.Navigation.UANamedNodeDescriptor and OpcLabs.EasyOpc.UA.Navigation.UANamedNodePath from OpcLabs.EasyOpc.UA.UANodeDescriptor, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use the returned OpcLabs.EasyOpc.UA.UANodeDescriptor in any place where OpcLabs.EasyOpc.UA.Navigation.UANamedNodeDescriptor is expected (in this case the OpcLabs.EasyOpc.UA.UANodeDescriptor contains the final node descriptor) or where OpcLabs.EasyOpc.UA.Navigation.UANamedNodePath is expected (in this case the OpcLabs.EasyOpc.UA.UANodeDescriptor contains the base and only node in the named node path), and the corresponding OPC UA named node descriptor or named node path will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.UA.Navigation.UANamedNodeDescriptor.FromUANodeDescriptor or OpcLabs.EasyOpc.UA.Navigation.UANamedNodePath.FromUANodeDescriptor static method instead.

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

Remarks

The effective node descriptor is available when the node is rooted in the server. Otherwise, the effective node descriptor is OpcLabs.EasyOpc.UA.UANodeDescriptor.Null.

This method or property does not throw any exceptions, aside from execution exceptions such as System.Threading.ThreadAbortException or System.OutOfMemoryException.

Example
// This example shows how to obtain the effective endpoint descriptor of the server, and use it together with effective node
// descriptor of data variable to operate on the server using an OPC UA client object.
// You can use any OPC UA client, including our Connectivity Explorer and OpcCmd utility, to connect to the server. 
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client, server and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-OPCStudio-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 System.Threading;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.NodeSpace;

namespace UAServerDocExamples._EasyUAServer
{
    class EffectiveEndpointDescriptor
    {
        public static void Main1()
        {
            // Instantiate the server object.
            // By default, the server will run on endpoint URL "opc.tcp://localhost:48040/".
            var server = new EasyUAServer();

            // Define data variables providing random integers.
            var random = new Random();
            UADataVariable myDataVariable1 = UADataVariable.CreateIn(server.Objects, "MyDataVariable1")
                .ReadValueFunction(() => random.Next(0, 100));
            UADataVariable myDataVariable2 = UADataVariable.CreateIn(server.Objects, "MyDataVariable2")
                .ReadValueFunction(() => random.Next(100, 200));

            // Start the server.
            Console.WriteLine("The server is starting...");
            server.Start();

            // Give the server some time to make its endpoints ready to accept client connections. For precise determination,
            // you can use IEasyUAServerEndpointMonitoring.EndpointStateChanged event on the server object.
            Thread.Sleep(1000);
            
            // Instantiate the client object.
            var client = new EasyUAClient();

            Console.WriteLine("Subscribing to data changes...");

            // Subscribe to data changes of our first data variable. Display the data changes on the console.
            client.SubscribeDataChange(server.EffectiveEndpointDescriptor, myDataVariable1.EffectiveNodeDescriptor, 1000,
                (sender, args) => Console.WriteLine(args), state: 1);

            // Subscribe to data changes of our second data variable. Display the data changes on the console.
            // Passing the server object as the first argument makes an implicit conversion to the endpoint descriptor.
            // Passing the data variable object as the second argument makes an implicit conversion to the node descriptor.
            // We are doing an equivalent of the previous call, but in a more compact way.
            client.SubscribeDataChange(server, myDataVariable2, 1000, 
                (sender, args) => Console.WriteLine(args), state: 2);

            // Let the user decide when to stop.
            Console.WriteLine("Press Enter to stop the server...");
            Console.ReadLine();

            // Stop the server.
            Console.WriteLine("The server is stopping...");
            server.Stop();
        }
    }
}
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