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