QuickOPC User's Guide and Reference
ReadValue(IEasyUAClient,UAEndpointDescriptor,UANodeDescriptor,UAAttributeId) Method
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA Namespace > IEasyUAClientExtension Class > ReadValue Method : ReadValue(IEasyUAClient,UAEndpointDescriptor,UANodeDescriptor,UAAttributeId) Method
The client object that will perform the operation.
Endpoint descriptor. Identifies the OPC-UA server.
Node descriptor. Identifies the node in OPC server's address space.
Attribute Id. Identifies an attribute of a node.
Reads an attribute from an OPC server. Only the attribute's value is returned (status code and timestamps are not returned). Reads an attribute's value using an endpoint descriptor, node Id and attribute Id.
Syntax
'Declaration
 
<ExtensionAttribute()>
<CanBeNullAttribute()>
Public Overloads Shared Function ReadValue( _
   ByVal client As IEasyUAClient, _
   ByVal endpointDescriptor As UAEndpointDescriptor, _
   ByVal nodeDescriptor As UANodeDescriptor, _
   ByVal attributeId As UAAttributeId _
) As Object
'Usage
 
Dim client As IEasyUAClient
Dim endpointDescriptor As UAEndpointDescriptor
Dim nodeDescriptor As UANodeDescriptor
Dim attributeId As UAAttributeId
Dim value As Object
 
value = IEasyUAClientExtension.ReadValue(client, endpointDescriptor, nodeDescriptor, attributeId)

Parameters

client
The client object that will perform the operation.
endpointDescriptor
Endpoint descriptor. Identifies the OPC-UA server.
nodeDescriptor
Node descriptor. Identifies the node in OPC server's address space.
attributeId
Attribute Id. Identifies an attribute of a node.

Return Value

If successful, the method returns the actual value of OPC attribute requested.
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.

An invalid enumeration value was used.

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.

The OPC UA operation has failed. This operation exception in uniformly used to allow common handling of various kinds of errors. The System.Exception.InnerException always contains information about the actual error cause.

This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately.

Remarks
The status code must be 'good' for this method to succeed; otherwise, a OpcLabs.EasyOpc.UA.OperationModel.UAException is thrown.

You can obtain nodeDescriptor e.g. by calling one of the browsing methods on EasyUAClientCore object.

Only the attribute's value is returned (status code and timestamps are not returned). The status code must be 'good' for this method to succeed; otherwise, a OpcLabs.EasyOpc.UA.OperationModel.UAException is thrown.

Example

.NET

// This example shows how to read a value of a specific attribute of a single node, and display it.

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}");
        }
    }
}
# This example shows how to read a value of a specific attribute of a single node, and display it.

#requires -Version 5.1
using namespace OpcLabs.EasyOpc.UA
using namespace OpcLabs.EasyOpc.UA.OperationModel

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll"

[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.
$client = New-Object EasyUAClient

# Obtain value of a DataType attribute
try {
    $value = [OpcLabs.EasyOpc.UA.IEasyUAClientExtension]::ReadValue($client,
        $endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853",
        [OpcLabs.EasyOpc.UA.UAAttributeId]::DataType)
}
catch [UAException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

# Display results
Write-Host "value type: $($value.GetType())"
Write-Host "value: $($value)"
# This example shows how to read a value of a specific attribute of a single node, and display it.

# 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.')
' This example shows how to read a value of a specific attribute of a single node, and display it.

Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel

Namespace _EasyUAClient
    Partial Friend Class ReadValue
        Public Shared Sub Overload2()

            ' Define which server we will work with.
            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/"

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

            ' Instantiate the client object.
            Dim client = New EasyUAClient()

            ' Obtain value of a DataType attribute.
            Dim value As Object
            Try
                value = client.ReadValue(endpointDescriptor, nodeDescriptor, UAAttributeId.DataType)
            Catch uaException As UAException
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
                Exit Sub
            End Try

            ' Display results
            Console.WriteLine("value type: {0}", value.GetType())
            Console.WriteLine("value: {0}", value)
        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