// This example shows how to read 4 items from an OPC XML-DA server at once, and display their values, timestamps
// and qualities.
//
// 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 ReadMultipleItems.MainXml;
var
  Arguments: OleVariant;
  Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
  I: Cardinal;
  ReadItemArguments1: _DAReadItemArguments;
  ReadItemArguments2: _DAReadItemArguments;
  ReadItemArguments3: _DAReadItemArguments;
  ReadItemArguments4: _DAReadItemArguments;
  VtqResult: _DAVtqResult;
  Results: OleVariant;
begin
  ReadItemArguments1 := CoDAReadItemArguments.Create;
  ReadItemArguments1.ServerDescriptor.UrlString := 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx';
  ReadItemArguments1.ItemDescriptor.ItemID := 'Dynamic/Analog Types/Double';
  ReadItemArguments2 := CoDAReadItemArguments.Create;
  ReadItemArguments2.ServerDescriptor.UrlString := 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx';
  ReadItemArguments2.ItemDescriptor.ItemID := 'Dynamic/Analog Types/Double[]';
  ReadItemArguments3 := CoDAReadItemArguments.Create;
  ReadItemArguments3.ServerDescriptor.UrlString := 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx';
  ReadItemArguments3.ItemDescriptor.ItemID := 'Dynamic/Analog Types/Int';
  ReadItemArguments4 := CoDAReadItemArguments.Create;
  ReadItemArguments4.ServerDescriptor.UrlString := 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx';
  ReadItemArguments4.ItemDescriptor.ItemID := 'SomeUnknownItem';
  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.ReadMultipleItems(Arguments));
  // Display results
  for I := VarArrayLowBound(Results, 1) to VarArrayHighBound(Results, 1) do
  begin
      VtqResult := IInterface(Results[I]) as _DAVtqResult;
      if VtqResult.Exception <> nil then
      begin
        WriteLn('results[', i, '] *** Failure: ', VtqResult.ErrorMessageBrief);
        Continue;
      end;
      WriteLn('results[', i, '].Vtq.ToString(): ', VtqResult.Vtq.ToString);
  end;
  VarClear(Results);
  VarClear(Arguments);
end;
	 
	
		// This example shows how to read 4 items from an OPC XML-DA server at once, and display their values, timestamps 
// and qualities.
//
// 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.
$ReadItemArguments1 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments");
$ReadItemArguments1->ServerDescriptor->UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
$ReadItemArguments1->ItemDescriptor->ItemID = "Dynamic/Analog Types/Double";
$ReadItemArguments2 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments");
$ReadItemArguments2->ServerDescriptor->UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
$ReadItemArguments2->ItemDescriptor->ItemID = "Dynamic/Analog Types/Double[]";
$ReadItemArguments3 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments");
$ReadItemArguments3->ServerDescriptor->UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
$ReadItemArguments3->ItemDescriptor->ItemID = "Dynamic/Analog Types/Int";
$ReadItemArguments4 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments");
$ReadItemArguments4->ServerDescriptor->UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
$ReadItemArguments4->ItemDescriptor->ItemID = "SomeUnknownItem";
$arguments[0] = $ReadItemArguments1;
$arguments[1] = $ReadItemArguments2;
$arguments[2] = $ReadItemArguments3;
$arguments[3] = $ReadItemArguments4;
$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
$results = $Client->ReadMultipleItems($arguments);
for ($i = 0; $i < count($results); $i++)
{
    $VtqResult = $results[$i];
    if ($VtqResult->Succeeded)
        printf("results[d].Vtq.ToString()s\n", $i, $VtqResult->Vtq->ToString);
    else
        printf("results[d]: *** Failures\n", $i, $VtqResult->ErrorMessageBrief);
}
	 
	
		Rem This example shows how to read 4 items from an OPC XML-DA server at once, and display their values, timestamps
Rem and qualities.
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 ReadMultipleItems_MainXml_Command_Click()
    OutputText = ""
    
    Dim readArguments1 As New DAReadItemArguments
    readArguments1.serverDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
    readArguments1.ItemDescriptor.ItemId = "Dynamic/Analog Types/Double"
    
    Dim readArguments2 As New DAReadItemArguments
    readArguments2.serverDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
    readArguments2.ItemDescriptor.ItemId = "Dynamic/Analog Types/Double[]"
    
    Dim readArguments3 As New DAReadItemArguments
    readArguments3.serverDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
    readArguments3.ItemDescriptor.ItemId = "Dynamic/Analog Types/Int"
    
    Dim readArguments4 As New DAReadItemArguments
    readArguments4.serverDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
    readArguments4.ItemDescriptor.ItemId = "SomeUnknownItem"
    
    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 vtqResults() As Variant
    vtqResults = client.ReadMultipleItems(arguments)
    ' Display results
    Dim i: For i = LBound(vtqResults) To UBound(vtqResults)
        Dim vtqResult As DAVtqResult: Set vtqResult = vtqResults(i)
        If Not (vtqResult.Exception Is Nothing) Then
            OutputText = OutputText & "results(" & i & ") *** Failure: " & vtqResult.ErrorMessageBrief & vbCrLf
        Else
        OutputText = OutputText & "results(" & i & ").Vtq.ToString(): " & vtqResult.vtq & vbCrLf
        End If
    Next
End Sub
	 
	
		Rem This example shows how to read 4 items from an OPC XML-DA server at once, and display their values, timestamps
Rem and qualities.
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.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ReadItemArguments1.ItemDescriptor.ItemID = "Dynamic/Analog Types/Double"
Dim ReadItemArguments2: Set ReadItemArguments2 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments2.ServerDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ReadItemArguments2.ItemDescriptor.ItemID = "Dynamic/Analog Types/Double[]"
Dim ReadItemArguments3: Set ReadItemArguments3 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments3.ServerDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ReadItemArguments3.ItemDescriptor.ItemID = "Dynamic/Analog Types/Int"
Dim ReadItemArguments4: Set ReadItemArguments4 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments4.ServerDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ReadItemArguments4.ItemDescriptor.ItemID = "SomeUnknownItem"
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.ReadMultipleItems(arguments)
Dim i: For i = LBound(results) To UBound(results)
    Dim VtqResult: Set VtqResult = results(i)
    If Not (VtqResult.Exception Is Nothing) Then
        WScript.Echo "results(" & i & ") *** Failure: " & VtqResult.ErrorMessageBrief
    Else
        WScript.Echo "results(" & i & ").Vtq.ToString(): " & VtqResult.Vtq.ToString()
    End If
Next