QuickOPC User's Guide and Reference
GetPropertyValue Method (_EasyDAClient)
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.DataAccess.ComTypes Namespace > _EasyDAClient Interface : GetPropertyValue Method
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.
The Item ID of the OPC item involved in the operation.
The numerical value of the Property ID of the OPC property being obtained
Gets a value of OPC property, using individual parameters specifying the OPC server, and OPC Item ID.
Syntax
'Declaration
 
<CanBeNullAttribute()>
Function GetPropertyValue( _
   ByVal machineName As String, _
   ByVal serverClass As String, _
   ByVal itemId As String, _
   ByVal propertyId As Integer _
) As Object
'Usage
 
Dim instance As _EasyDAClient
Dim machineName As String
Dim serverClass As String
Dim itemId As String
Dim propertyId As Integer
Dim value As Object
 
value = instance.GetPropertyValue(machineName, serverClass, itemId, propertyId)
[CanBeNull()]
object GetPropertyValue( 
   string machineName,
   string serverClass,
   string itemId,
   int propertyId
)
[CanBeNull()]
Object^ GetPropertyValue( 
   String^ machineName,
   String^ serverClass,
   String^ itemId,
   int propertyId
) 

Parameters

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
The Item ID of the OPC item involved in the operation.
propertyId
The numerical value of the Property ID of the OPC property being obtained

Return Value

If successful, the function returns the actual value of the OPC property requested.
Exceptions
ExceptionDescription
An error has occurred during application execution.
Example

COM

Rem This example shows how to get a value of a single OPC property.
Rem
Rem Note that some properties may not have a useful value initially (e.g. until the item is activated in a group), which also the
Rem case with Timestamp property as implemented by the demo server. This behavior is server-dependent, and normal. You can run 
Rem IEasyDAClient.ReadItemValue.Main.vbs shortly before this example, in order to obtain better property values. Your code may 
Rem also subscribe to the item in order to assure that it remains active.

Option Explicit

Const Timestamp = 4

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")

On Error Resume Next
Dim value: value = Client.GetPropertyValue("", "OPCLabs.KitServer.2", "Simulation.Random", Timestamp)
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

WScript.Echo value
// This example shows how to get a value of a single OPC property.
//
// Note that some properties may not have a useful value initially (e.g. until the item is activated in a group), which also the
// case with Timestamp property as implemented by the demo server. This behavior is server-dependent, and normal. You can run 
// IEasyDAClient.ReadItemValue.Main.vbs shortly before this example, in order to obtain better property values. Your code may 
// also subscribe to the item in order to assure that it remains active.

const Timestamp = 4;

$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");

try
{
    $value = $Client->GetPropertyValue("", "OPCLabs.KitServer.2", "Simulation.Random", Timestamp);
}
catch (com_exception $e)
{
    printf("*** Failure: %s\n", $e->getMessage());
    Exit();
}

printf("%s\n", $value);
# This example shows how to get a value of a single OPC property.
#
# Note that some properties may not have a useful value initially (e.g. until the item is activated in a group), which also the
# case with Timestamp property as implemented by the demo server. This behavior is server-dependent, and normal. You can run 
# IEasyDAClient.ReadItemValue.Main.vbs shortly before this example, in order to obtain better property values. Your code may 
# also subscribe to the item in order to assure that it remains active.

# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
import win32com.client
from pywintypes import com_error

TIMESTAMP = 4

# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient') 

# Perform the operation
try:
    value = client.GetPropertyValue('', 'OPCLabs.KitServer.2', 'Simulation.Random', TIMESTAMP)
except com_error as e:
    print('*** Failure: ' + e.args[2][1] + ': ' + e.args[2][2])
    exit()

# Display results
print('value: ', value)
Rem This example measures the time needed to get values of all OPC properties of a single OPC item "one by one".

Option Explicit

Dim ServerDescriptor: Set ServerDescriptor = CreateObject("OpcLabs.EasyOpc.ServerDescriptor")
ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"

Dim NodeDescriptor: Set NodeDescriptor = CreateObject("OpcLabs.EasyOpc.DataAccess.DANodeDescriptor")
NodeDescriptor.ItemID = "Simulation.ReadValue_I4"

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")

Dim PropertyElementCollection
On Error Resume Next
Set PropertyElementCollection = Client.BrowseProperties(ServerDescriptor, NodeDescriptor)
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

'EasyDAClient.ReadItemValue "", "OPCLabs.KitServer.2", "Simulation.ReadValue_I4"
Dim startTime: startTime = Timer
Dim PropertyElement: For Each PropertyElement In PropertyElementCollection
    Dim propertyID: Set propertyID = PropertyElement.PropertyID
    On Error Resume Next
    Dim value: value = Client.GetPropertyValue("", "OPCLabs.KitServer.2", "Simulation.ReadValue_I4", propertyID.NumericalValue)
    If Err.Number <> 0 Then
        WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
        WScript.Quit
    End If
    On Error Goto 0
    'WScript.Echo value
Next
WScript.Echo "Time taken (milliseconds): " & (Timer - startTime)*1000
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