// This example shows how to read values of 4 items at once, and display them.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// 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.
class procedure ReadMultipleItemValues.Main;
var
Arguments: OleVariant;
Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
I: Cardinal;
ReadItemArguments1: _DAReadItemArguments;
ReadItemArguments2: _DAReadItemArguments;
ReadItemArguments3: _DAReadItemArguments;
ReadItemArguments4: _DAReadItemArguments;
ValueResult: _ValueResult;
Results: OleVariant;
begin
ReadItemArguments1 := CoDAReadItemArguments.Create;
ReadItemArguments1.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
ReadItemArguments1.ItemDescriptor.ItemID := 'Simulation.Random';
ReadItemArguments2 := CoDAReadItemArguments.Create;
ReadItemArguments2.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
ReadItemArguments2.ItemDescriptor.ItemID := 'Trends.Ramp (1 min)';
ReadItemArguments3 := CoDAReadItemArguments.Create;
ReadItemArguments3.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
ReadItemArguments3.ItemDescriptor.ItemID := 'Trends.Sine (1 min)';
ReadItemArguments4 := CoDAReadItemArguments.Create;
ReadItemArguments4.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
ReadItemArguments4.ItemDescriptor.ItemID := 'Simulation.Register_I4';
Arguments := VarArrayCreate([0, 3], varVariant);
Arguments[0] := ReadItemArguments1;
Arguments[1] := ReadItemArguments2;
Arguments[2] := ReadItemArguments3;
Arguments[3] := ReadItemArguments4;
// Instantiate the client object
Client := CoEasyDAClient.Create;
TVarData(Results).VType := varArray or varVariant;
TVarData(Results).VArray := PVarArray(
Client.ReadMultipleItemValues(Arguments));
// Display results
for I := VarArrayLowBound(Results, 1) to VarArrayHighBound(Results, 1) do
begin
ValueResult := IInterface(Results[I]) as _ValueResult;
if ValueResult.Succeeded then
WriteLn('results(', i, ').Value: ', ValueResult.Value)
else
WriteLn('results(', i, ') *** Failure: ', ValueResult.ErrorMessageBrief);
end;
VarClear(Results);
VarClear(Arguments);
end;
REM This example shows how to read values of 4 items at once, and display them.
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 Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
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.
Private Sub ReadMultipleItemValues_Main_Command_Click()
OutputText = ""
Dim readArguments1 As New DAReadItemArguments
readArguments1.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
readArguments1.ItemDescriptor.itemId = "Simulation.Random"
Dim readArguments2 As New DAReadItemArguments
readArguments2.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
readArguments2.ItemDescriptor.itemId = "Trends.Ramp (1 min)"
Dim readArguments3 As New DAReadItemArguments
readArguments3.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
readArguments3.ItemDescriptor.itemId = "Trends.Sine (1 min)"
Dim readArguments4 As New DAReadItemArguments
readArguments4.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
readArguments4.ItemDescriptor.itemId = "Simulation.Register_I4"
Dim arguments(3) As Variant
Set arguments(0) = readArguments1
Set arguments(1) = readArguments2
Set arguments(2) = readArguments3
Set arguments(3) = readArguments4
' Instantiate the client object
Dim client As New EasyDAClient
Dim results() As Variant
results = client.ReadMultipleItemValues(arguments)
' Display results
Dim i: For i = LBound(results) To UBound(results)
Dim valueResult As valueResult: Set valueResult = results(i)
If valueResult.Succeeded Then
OutputText = OutputText & "results(" & i & ").Value: " & valueResult.value & vbCrLf
Else
OutputText = OutputText & "results(" & i & ") *** Failure: " & valueResult.ErrorMessageBrief & vbCrLf
End If
Next
End Sub
Rem This example shows how to read values of 4 items at once, and display them.
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 ReadItemArguments1: Set ReadItemArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments1.ItemDescriptor.ItemID = "Simulation.Random"
Dim ReadItemArguments2: Set ReadItemArguments2 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments2.ItemDescriptor.ItemID = "Trends.Ramp (1 min)"
Dim ReadItemArguments3: Set ReadItemArguments3 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments3.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments3.ItemDescriptor.ItemID = "Trends.Sine (1 min)"
Dim ReadItemArguments4: Set ReadItemArguments4 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments4.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments4.ItemDescriptor.ItemID = "Simulation.Register_I4"
Dim arguments(3)
Set arguments(0) = ReadItemArguments1
Set arguments(1) = ReadItemArguments2
Set arguments(2) = ReadItemArguments3
Set arguments(3) = ReadItemArguments4
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim results: results = Client.ReadMultipleItemValues(arguments)
Dim i: For i = LBound(results) To UBound(results)
Dim ValueResult: Set ValueResult = results(i)
If ValueResult.Succeeded Then
WScript.Echo "results(" & i & ").Value: " & ValueResult.Value
Else
WScript.Echo "results(" & i & ") *** Failure: " & ValueResult.ErrorMessageBrief
End If
Next