OPC Studio 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. It 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.

The value represents a UNC or DNS computer name. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. IPv6 addresses are normally enclosed between '[' and ']'.

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

Contains ProgID of the OPC server to read from.

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

The Item ID of the OPC item involved in the operation.

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

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. It 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.

The value represents a UNC or DNS computer name. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. IPv6 addresses are normally enclosed between '[' and ']'.

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

serverClass
Contains ProgID of the OPC server to read from.

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

itemId
The Item ID of the OPC item involved in the operation.

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

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.

This method can return null (Nothing in Visual Basic).

Exceptions
ExceptionDescription
An error has occurred during application execution.
Remarks

This member or type is for use from COM. It is not meant to be used from .NET or Python. Refer to the corresponding .NET member or type instead, if you are developing in .NET or Python.

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.
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.

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.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in PHP on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PHP .
// 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.

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!
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
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".
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.

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