OPC Studio User's Guide and Reference
ReadItem(IEasyDAClient,ServerDescriptor,DAItemDescriptor,DAReadParameters) Method
Example 



OpcLabs.EasyOpcClassicCore Assembly > OpcLabs.EasyOpc.DataAccess Namespace > IEasyDAClientExtension Class > ReadItem Method : ReadItem(IEasyDAClient,ServerDescriptor,DAItemDescriptor,DAReadParameters) Method
The client object that will perform the operation.

This is typically the EasyDAClient object.

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

The OPC server involved in the operation.

Because the OpcLabs.EasyOpc.ServerDescriptor has an implicit conversion from System.Guid, System.String and OpcLabs.EasyOpc.ServerElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a GUID (representing the CLSID of the server), a string (representing the so-called OPC server descriptor string, such as a ProgID or the URL of the server), or a OpcLabs.EasyOpc.ServerElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC server descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromGuid, FromString or FromServerElement static method instead.

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

The OPC item involved in the operation.

Because the DAItemDescriptor has an implicit conversion from System.String and OpcLabs.EasyOpc.DataAccess.AddressSpace.DANodeElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the qualified name of the node), or a OpcLabs.EasyOpc.DataAccess.AddressSpace.DANodeElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC DA item descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromString or FromDANodeElement static method instead.

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

Read parameters, such as the data source or value age.

Because the DAReadParameters has an implicit conversion from System.Int32 and DADataSource, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use an integer (representing the value age in milliseconds), or an element of the DADataSource enumeration in place of this parameter, and the corresponding OPC DA read parameters object will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the DAReadParameters Constructor(Int32) or DAReadParameters Constructor(DADataSource) constructor instead.

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

Reads a named item using descriptor objects for the OPC server and OPC-DA item, and specifying read parameters such as the data source or value age. Value, quality and timestamp are returned.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Overloads Shared Function ReadItem( _
   ByVal client As IEasyDAClient, _
   ByVal serverDescriptor As ServerDescriptor, _
   ByVal itemDescriptor As DAItemDescriptor, _
   ByVal readParameters As DAReadParameters _
) As DAVtq
'Usage
 
Dim client As IEasyDAClient
Dim serverDescriptor As ServerDescriptor
Dim itemDescriptor As DAItemDescriptor
Dim readParameters As DAReadParameters
Dim value As DAVtq
 
value = IEasyDAClientExtension.ReadItem(client, serverDescriptor, itemDescriptor, readParameters)

Parameters

client
The client object that will perform the operation.

This is typically the EasyDAClient object.

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

serverDescriptor
The OPC server involved in the operation.

Because the OpcLabs.EasyOpc.ServerDescriptor has an implicit conversion from System.Guid, System.String and OpcLabs.EasyOpc.ServerElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a GUID (representing the CLSID of the server), a string (representing the so-called OPC server descriptor string, such as a ProgID or the URL of the server), or a OpcLabs.EasyOpc.ServerElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC server descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromGuid, FromString or FromServerElement static method instead.

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

itemDescriptor
The OPC item involved in the operation.

Because the DAItemDescriptor has an implicit conversion from System.String and OpcLabs.EasyOpc.DataAccess.AddressSpace.DANodeElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the qualified name of the node), or a OpcLabs.EasyOpc.DataAccess.AddressSpace.DANodeElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC DA item descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the FromString or FromDANodeElement static method instead.

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

readParameters
Read parameters, such as the data source or value age.

Because the DAReadParameters has an implicit conversion from System.Int32 and DADataSource, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use an integer (representing the value age in milliseconds), or an element of the DADataSource enumeration in place of this parameter, and the corresponding OPC DA read parameters object will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the DAReadParameters Constructor(Int32) or DAReadParameters Constructor(DADataSource) constructor instead.

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

Return Value

If successful, the function returns a DAVtq object. The object contains the value, timestamp and quality of the OPC item requested.

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.

The OPC "Classic" (or OPC XML-DA) 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

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 read a single item from the device, and display its value, timestamp and quality.
//
// 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.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    partial class ReadItem
    {
        public static void DeviceSource()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            Console.WriteLine("Reading item...");
            DAVtq vtq;
            try
            {
                // DADataSource enumeration:
                // Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
                // The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
                // current status of data received from the server.

                vtq = client.ReadItem("OPCLabs.KitServer.2", "Simulation.Random", DADataSource.Device);
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            Console.WriteLine("Vtq: {0}", vtq);
        }
    }
}
' This example shows how to read a single item from the device, and display its value, timestamp and quality.
'
' 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 OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DataAccess._EasyDAClient
    Partial Friend Class ReadItem
        Public Shared Sub DeviceSource()
            ' Instantiate the client object.
            Dim client = New EasyDAClient()

            Console.WriteLine("Reading item...")
            Dim vtq As DAVtq
            Try
                ' DADataSource enumeration:
                ' Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
                ' The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
                ' current status of data received from the server.

                vtq = client.ReadItem("OPCLabs.KitServer.2", "Simulation.Random", DADataSource.Device)
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            Console.WriteLine("Vtq: {0}", vtq)
        End Sub
    End Class
End Namespace
# This example shows how to read a single item from the device, and display its value, timestamp and quality.
#
# 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 import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object.
client = EasyDAClient()

print('Reading item...')
try:
    # DADataSource enumeration:
    # Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
    # The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
    # current status of data received from the server.
    vtq = IEasyDAClientExtension.ReadItem(client,
                                          ServerDescriptor('OPCLabs.KitServer.2'),
                                          DAItemDescriptor('Simulation.Random'),
                                          DAReadParameters(DADataSource.Device))
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message, sep='')
    exit()

# Display results.
print('Vtq: ', vtq, sep='')
// This example shows how to read a value of a single item from the device and display its value.
//
// 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.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess.Xml
{
    partial class ReadItemValue
    {
        public static void DeviceSourceXml()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            Console.WriteLine("Reading item value...");
            object value;
            try
            {
                // DADataSource enumeration:
                // Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
                // The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
                // current status of data received from the server.

                value = client.ReadItemValue("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double", DADataSource.Device);
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            Console.WriteLine(value);
        }
    }
}
' This example shows how to read a value of a single item from the device and display its value.
'
' 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 OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DataAccess.Xml
    Partial Friend Class ReadItemValue
        Public Shared Sub DeviceSourceXml()
            ' Instantiate the client object.
            Dim client As New EasyDAClient()

            Console.WriteLine("Reading item value...")
            Dim value As Object
            Try
                ' DADataSource enumeration:
                ' Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
                ' The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
                ' current status of data received from the server.

                value = client.ReadItemValue("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double", DADataSource.Device)
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            Console.WriteLine(value)
        End Sub
    End Class
End Namespace
# This example shows how to read a value of a single item from the device and display its value.
#
# 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 import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *

# Instantiate the client object.
client = EasyDAClient()

print('Reading item value...')
try:
    # DADataSource enumeration:
    # Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
    # The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
    # current status of data received from the server.

    value = IEasyDAClientExtension.ReadItemValue(client, 
                                                 ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'), 
                                                 DAItemDescriptor('Dynamic/Analog Types/Double'), 
                                                 DAReadParameters(DADataSource.Device))
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message, sep='')
    exit()

# Display results
print('value: ', value, sep='')
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