OPC Studio User's Guide and Reference
Examples - OPC Unified Architecture - Read value of specific attribute of a single node
View with Navigation Tools
// This example shows how to read a value of a specific attribute of a single node, and display it.
//
// 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 OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class ReadValue
    {
        public static void Overload2()
        {
            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/"

            UANodeDescriptor nodeDescriptor = "nsu=http://test.org/UA/Data/ ;i=10853";

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

            // Obtain value of a DataType attribute
            object value;
            try
            {
                value = client.ReadValue(endpointDescriptor, nodeDescriptor, UAAttributeId.DataType);
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results
            Console.WriteLine($"value type: {value?.GetType()}");
            Console.WriteLine($"value: {value}");
        }
    }
}

Python

# This example shows how to read a value of a specific attribute of a single node, and display it.
#
# 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 .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel 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/'

nodeDescriptor = UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853')

# Instantiate the client object.
client = EasyUAClient()

# Obtain value of a DataType attribute.
try:
    value = IEasyUAClientExtension.ReadValue(client, endpointDescriptor, nodeDescriptor, UAAttributeId.DataType)
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
print('value type: ', type(value), sep='')  # The output will differ from pure .NET languages such as C# or VB.NET.
print('value: ', value, sep='')

print()
print('Finished.')

 

See Also

Concepts