// This example shows how to write values, timestamps and qualities into 3 items at once.
//
// 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 WriteMultipleItems.Main;
var
Arguments: OleVariant;
Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
I: Cardinal;
ItemVtqArguments1: _DAItemVtqArguments;
ItemVtqArguments2: _DAItemVtqArguments;
ItemVtqArguments3: _DAItemVtqArguments;
Results: OleVariant;
OperationResult: _OperationResult;
begin
ItemVtqArguments1 := CoDAItemVtqArguments.Create;
ItemVtqArguments1.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
ItemVtqArguments1.ItemDescriptor.ItemID := 'Simulation.Register_I4';
ItemVtqArguments1.Vtq.Value := 23456;
ItemVtqArguments1.Vtq.TimestampLocal := Now();
ItemVtqArguments1.Vtq.Quality.NumericalValue := DAQualities_GoodNonSpecific;
ItemVtqArguments2 := CoDAItemVtqArguments.Create;
ItemVtqArguments2.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
ItemVtqArguments2.ItemDescriptor.ItemID := 'Simulation.Register_R8';
ItemVtqArguments2.Vtq.Value := 2.34567890;
ItemVtqArguments2.Vtq.TimestampLocal := Now();
ItemVtqArguments2.Vtq.Quality.NumericalValue := DAQualities_GoodNonSpecific;
ItemVtqArguments3 := CoDAItemVtqArguments.Create;
ItemVtqArguments3.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
ItemVtqArguments3.ItemDescriptor.ItemID := 'Simulation.Register_BSTR';
ItemVtqArguments3.Vtq.Value := 'ABC';
ItemVtqArguments3.Vtq.TimestampLocal := Now();
ItemVtqArguments3.Vtq.Quality.NumericalValue := DAQualities_GoodNonSpecific;
Arguments := VarArrayCreate([0, 2], varVariant);
Arguments[0] := ItemVtqArguments1;
Arguments[1] := ItemVtqArguments2;
Arguments[2] := ItemVtqArguments3;
// Instantiate the client object
Client := CoEasyDAClient.Create;
// Modify values of nodes
TVarData(Results).VType := varArray or varVariant;
TVarData(Results).VArray := PVarArray(
Client.WriteMultipleItems(Arguments));
// Display results
for I := VarArrayLowBound(Results, 1) to VarArrayHighBound(Results, 1) do
begin
OperationResult := IInterface(Results[I]) as _OperationResult;
if OperationResult.Succeeded then
WriteLn('Result ', I, ' success')
else
WriteLn('Result ', I, ' *** Failure: ', OperationResult.Exception.GetBaseException.Message);
end;
VarClear(Results);
VarClear(Arguments);
end;
REM This example shows how to write values, timestamps and qualities into 3 items at once.
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 WriteMultipleItems_Main_Command_Click()
OutputText = ""
Dim itemVtqArguments1 As New DAItemVtqArguments
itemVtqArguments1.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
itemVtqArguments1.ItemDescriptor.itemId = "Simulation.Register_I4"
itemVtqArguments1.vtq.SetValue 23456
itemVtqArguments1.vtq.TimestampLocal = Now()
itemVtqArguments1.vtq.Quality.NumericalValue = DAQualities_GoodNonspecific
Dim itemVtqArguments2 As New DAItemVtqArguments
itemVtqArguments2.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
itemVtqArguments2.ItemDescriptor.itemId = "Simulation.Register_R8"
itemVtqArguments2.vtq.SetValue 2.3456789
itemVtqArguments2.vtq.TimestampLocal = Now()
itemVtqArguments2.vtq.Quality.NumericalValue = DAQualities_GoodNonspecific
Dim itemVtqArguments3 As New DAItemVtqArguments
itemVtqArguments3.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
itemVtqArguments3.ItemDescriptor.itemId = "Simulation.Register_BSTR"
itemVtqArguments3.vtq.SetValue "ABC"
itemVtqArguments3.vtq.TimestampLocal = Now()
itemVtqArguments3.vtq.Quality.NumericalValue = DAQualities_GoodNonspecific
Dim arguments(2) As Variant
Set arguments(0) = itemVtqArguments1
Set arguments(1) = itemVtqArguments2
Set arguments(2) = itemVtqArguments3
' Instantiate the client object
Dim client As New EasyDAClient
' Modify values of nodes
Dim results() As Variant
results = client.WriteMultipleItems(arguments)
' Display results
Dim i: For i = LBound(results) To UBound(results)
Dim operationResult As operationResult: Set operationResult = results(i)
If operationResult.Succeeded Then
OutputText = OutputText & "result " & i & " success" & vbCrLf
Else
OutputText = OutputText & "result " & i & " *** Failure: " & operationResult.ErrorMessageBrief & vbCrLf
End If
Next
End Sub
Rem This example shows how to write values, timestamps and qualities into 3 items at once.
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 ItemVtqArguments1: Set ItemVtqArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemVtqArguments")
ItemVtqArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemVtqArguments1.ItemDescriptor.ItemID = "Simulation.Register_I4"
ItemVtqArguments1.Vtq.Value = 23456
ItemVtqArguments1.Vtq.TimestampLocal = Now()
ItemVtqArguments1.Vtq.Quality.NumericalValue = 192
Dim ItemVtqArguments2: Set ItemVtqArguments2 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemVtqArguments")
ItemVtqArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemVtqArguments2.ItemDescriptor.ItemID = "Simulation.Register_R8"
ItemVtqArguments2.Vtq.Value = 2.34567890
ItemVtqArguments2.Vtq.TimestampLocal = Now()
ItemVtqArguments2.Vtq.Quality.NumericalValue = 192
Dim ItemVtqArguments3: Set ItemVtqArguments3 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemVtqArguments")
ItemVtqArguments3.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemVtqArguments3.ItemDescriptor.ItemID = "Simulation.Register_BSTR"
ItemVtqArguments3.Vtq.Value = "ABC"
ItemVtqArguments3.Vtq.TimestampLocal = Now()
ItemVtqArguments3.Vtq.Quality.NumericalValue = 192
Dim arguments(2)
Set arguments(0) = ItemVtqArguments1
Set arguments(1) = ItemVtqArguments2
Set arguments(2) = ItemVtqArguments3
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim results: results = Client.WriteMultipleItems(arguments)
Dim i: For i = LBound(results) To UBound(results)
Dim OperationResult: Set OperationResult = results(i)
If OperationResult.Succeeded Then
WScript.Echo "Result " & i & ": success"
Else
WScript.Echo "Result " & i & ": " & OperationResult.Exception.GetBaseException.Message
End If
Next