Connectivity Software User's Guide and Reference
Examples - OPC UA Specialized - Kepware KEPServerEX - Read

.NET

// This KEPServerEX/UA example shows how to read and display data of an attribute (value, timestamps, and status code).
//
// Find all latest examples here: https://www.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-ConnectivityStudio-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://forum.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 OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples.Specialized
{
    partial class Kepware_KEPServerEX_UA
    {
        public static void Read()
        {
            UAEndpointDescriptor endpointDescriptor = "opc.tcp://localhost:49320";  // default KEPServerEX/UA endpoint 

            // Instantiate the client object.
            var client = new EasyUAClient();

            // Obtain attribute data. By default, the Value attribute of a node will be read.
            UAAttributeData attributeData;
            try
            {
                attributeData = client.Read(endpointDescriptor,
                    // The UANodeId.KEPServerEX(...) helper method simplifies creation of node IDs for KEPServerEX/UA nodes.
                    UANodeId.KEPServerEX("Simulation Examples.Functions.Random1"));
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results
            Console.WriteLine($"Value: {attributeData.Value}");
            Console.WriteLine($"ServerTimestamp: {attributeData.ServerTimestamp}");
            Console.WriteLine($"SourceTimestamp: {attributeData.SourceTimestamp}");
            Console.WriteLine($"StatusCode: {attributeData.StatusCode}");
        }
    }
}