QuickOPC User's Guide and Reference
ReadItem(IEasyDAClient,String,String,String,VarType) Method
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.DataAccess Namespace > IEasyDAClientExtension Class > ReadItem Method : ReadItem(IEasyDAClient,String,String,String,VarType) Method
The client object that will perform the operation.
Name of the machine. Determines the computer on which the OPC server is located. May be an empty string, in which case the OPC server is assumed to exist on the local computer or at the computer specified for it by DCOM configuration.
Contains ProgID of the OPC server to read from.
Contains OPC item identifier.
Specifies the data type requested. Passing OpcLabs.BaseLib.ComInterop.VarTypes.Empty will cause the value be returned in server's canonical data type.
Reads a named item from an OPC server. Value, quality and timestamp are returned. Reads a named item using individual parameters specifying its location, and a specific data type.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Overloads Shared Function ReadItem( _
   ByVal client As IEasyDAClient, _
   ByVal machineName As String, _
   ByVal serverClass As String, _
   ByVal itemId As String, _
   ByVal dataType As VarType _
) As DAVtq
'Usage
 
Dim client As IEasyDAClient
Dim machineName As String
Dim serverClass As String
Dim itemId As String
Dim dataType As VarType
Dim value As DAVtq
 
value = IEasyDAClientExtension.ReadItem(client, machineName, serverClass, itemId, dataType)

Parameters

client
The client object that will perform the operation.
machineName
Name of the machine. Determines the computer on which the OPC server is located. May be an empty string, in which case the OPC server is assumed to exist on the local computer or at the computer specified for it by DCOM configuration.
serverClass
Contains ProgID of the OPC server to read from.
itemId
Contains OPC item identifier.
dataType
Specifies the data type requested. Passing OpcLabs.BaseLib.ComInterop.VarTypes.Empty will cause the value be returned in server's canonical data type.

Return Value

If successful, the function returns a DAVtq object. The object contains the value, timestamp and quality of the OPC item requested.
Exceptions
ExceptionDescription
Thrown when the OPC operation fails.
One of the arguments provided to a method is not valid.
A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.
Remarks

The server can be local or can be remotely accessed via DCOM. Optionally, an access path can be specified or a specific data type can be requested.

The ReadItem method only waits for the first update from the server (or until the timeout elapses); it does not wait until the quality becomes "uncertain" or "good".

Example
// This example shows how to read a single item, and display its value, timestamp and quality.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

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

            DAVtq vtq;
            try
            {
                vtq = client.ReadItem("", "OPCLabs.KitServer.2", "Simulation.Random");
            }
            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, and display its value, timestamp and quality.

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

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Assemblies/net47/OpcLabs.EasyOpcClassic.dll"

# Instantiate the client object.
$client = New-Object EasyDAClient

try {
    $vtq = [IEasyDAClientExtension]::ReadItem($client, "", "OPCLabs.KitServer.2", "Simulation.Random")
}
catch [OpcException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

Write-Host "Vtq: $($vtq)"
' This example shows how to read a single item, and display its value, timestamp and quality.

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DocExamples.DataAccess._EasyDAClient
    Partial Friend Class ReadItem
        Public Shared Sub Main1()
            Dim client = New EasyDAClient()

            Dim vtq As DAVtq
            Try
                vtq = client.ReadItem("", "OPCLabs.KitServer.2", "Simulation.Random")
            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
// Shows how different data types can be read, including rare types and arrays of values.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    partial class ReadItem
    {
        // Instantiate the client object.
        static readonly EasyDAClient Client = new EasyDAClient();

        static void ReadAndDisplay(string itemId)
        {
            Console.WriteLine();
            Console.WriteLine("Reading \"{0}\"...", itemId);

            DAVtq vtq;
            try
            {
                vtq = Client.ReadItem("OPCLabs.KitServer.2", itemId);
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }
            Console.WriteLine("Vtq: {0}", vtq);
        }

        public static void DataTypes()
        {
            ReadAndDisplay("Simulation.Register_EMPTY");
            ReadAndDisplay("Simulation.Register_NULL");
            ReadAndDisplay("Simulation.Register_DISPATCH");

            ReadAndDisplay("Simulation.ReadValue_I2");
            ReadAndDisplay("Simulation.ReadValue_I4");
            ReadAndDisplay("Simulation.ReadValue_R4");
            ReadAndDisplay("Simulation.ReadValue_R8");
            ReadAndDisplay("Simulation.ReadValue_CY");
            ReadAndDisplay("Simulation.ReadValue_DATE");
            ReadAndDisplay("Simulation.ReadValue_BSTR");
            ReadAndDisplay("Simulation.ReadValue_BOOL");
            ReadAndDisplay("Simulation.ReadValue_DECIMAL");
            ReadAndDisplay("Simulation.ReadValue_I1");
            ReadAndDisplay("Simulation.ReadValue_UI1");
            ReadAndDisplay("Simulation.ReadValue_UI2");
            ReadAndDisplay("Simulation.ReadValue_UI4");
            ReadAndDisplay("Simulation.ReadValue_INT");
            ReadAndDisplay("Simulation.ReadValue_UINT");

            ReadAndDisplay("Simulation.ReadValue_ArrayOfI2");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfI4");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfR4");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfR8");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfCY");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfDATE");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfBSTR");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfBOOL");
            //ReadAndDisplay("Simulation.ReadValue_ArrayOfDECIMAL");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfI1");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI1");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI2");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI4");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfINT");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUINT");
        }
    }
}
' Shows how different data types can be read, including rare types and arrays of values.

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DocExamples.DataAccess._EasyDAClient
    Partial Friend Class ReadItem
        Private Shared ReadOnly DAClient As New EasyDAClient()

        Private Shared Sub ReadAndDisplay(itemId As String)
            Console.WriteLine()
            Console.WriteLine("Reading ""{0}""...", itemId)

            Dim vtq As DAVtq
            Try
                vtq = DAClient.ReadItem("OPCLabs.KitServer.2", itemId)
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            Console.WriteLine("Vtq.ToString(): {0}", vtq.ToString())
        End Sub

        Shared Sub DataTypes()
            ReadAndDisplay("Simulation.Register_EMPTY")
            ReadAndDisplay("Simulation.Register_NULL")
            ReadAndDisplay("Simulation.Register_DISPATCH")

            ReadAndDisplay("Simulation.ReadValue_I2")
            ReadAndDisplay("Simulation.ReadValue_I4")
            ReadAndDisplay("Simulation.ReadValue_R4")
            ReadAndDisplay("Simulation.ReadValue_R8")
            ReadAndDisplay("Simulation.ReadValue_CY")
            ReadAndDisplay("Simulation.ReadValue_DATE")
            ReadAndDisplay("Simulation.ReadValue_BSTR")
            ReadAndDisplay("Simulation.ReadValue_BOOL")
            ReadAndDisplay("Simulation.ReadValue_DECIMAL")
            ReadAndDisplay("Simulation.ReadValue_I1")
            ReadAndDisplay("Simulation.ReadValue_UI1")
            ReadAndDisplay("Simulation.ReadValue_UI2")
            ReadAndDisplay("Simulation.ReadValue_UI4")
            ReadAndDisplay("Simulation.ReadValue_INT")
            ReadAndDisplay("Simulation.ReadValue_UINT")

            ReadAndDisplay("Simulation.ReadValue_ArrayOfI2")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfI4")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfR4")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfR8")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfCY")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfDATE")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfBSTR")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfBOOL")
            'ReadAndDisplay("Simulation.ReadValue_ArrayOfDECIMAL");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfI1")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI1")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI2")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI4")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfINT")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUINT")
        End Sub
    End Class
End Namespace
// This example shows how to read a single item, and display its value, timestamp and quality.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

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

            DAVtq vtq;
            try
            {
                vtq = client.ReadItem("", "OPCLabs.KitServer.2", "Simulation.Random");
            }
            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, and display its value, timestamp and quality.

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

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Assemblies/net47/OpcLabs.EasyOpcClassic.dll"

# Instantiate the client object.
$client = New-Object EasyDAClient

try {
    $vtq = [IEasyDAClientExtension]::ReadItem($client, "", "OPCLabs.KitServer.2", "Simulation.Random")
}
catch [OpcException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

Write-Host "Vtq: $($vtq)"
' This example shows how to read a single item, and display its value, timestamp and quality.

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DocExamples.DataAccess._EasyDAClient
    Partial Friend Class ReadItem
        Public Shared Sub Main1()
            Dim client = New EasyDAClient()

            Dim vtq As DAVtq
            Try
                vtq = client.ReadItem("", "OPCLabs.KitServer.2", "Simulation.Random")
            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 using a browse path, and display its value, timestamp and quality.

using System;
using OpcLabs.EasyOpc;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

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

            DAVtq vtq;
            try
            {
                vtq = client.ReadItem(
                    new ServerDescriptor("", "OPCLabs.KitServer.2"),
                    new DAItemDescriptor(null, "/Simulation/Random"));
            }
            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 using a browse path, and display its value, timestamp and quality.

Imports OpcLabs.EasyOpc
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DocExamples.DataAccess._EasyDAClient
    Partial Friend Class ReadItem
        Public Shared Sub BrowsePath()
            Dim client = New EasyDAClient()

            Dim vtq As DAVtq
            Try
                vtq = client.ReadItem(New ServerDescriptor("", "OPCLabs.KitServer.2"), New DAItemDescriptor(Nothing, "/Simulation/Random"))
            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
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2012, Windows Server 2016; .NET Core, .NET 5, .NET 6: Linux, macOS, Microsoft Windows

See Also

Reference

IEasyDAClientExtension Class
IEasyDAClientExtension Members
Overload List