OPC Studio User's Guide and Reference
WriteMultipleItemValues Method (_EasyDAClient)
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.DataAccess.ComTypes Namespace > _EasyDAClient Interface : WriteMultipleItemValues Method
Array of argument objects for the operation.

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

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Writes values into named items in an OPC server or OPC servers. Only the item values are written (qualities and timestamp are not written).
Syntax
'Declaration
 
<NotNullAttribute()>
Function WriteMultipleItemValues( _
   ByVal argumentsArray As Object _
) As Object()
'Usage
 
Dim instance As _EasyDAClient
Dim argumentsArray As Object
Dim value() As Object
 
value = instance.WriteMultipleItemValues(argumentsArray)
[NotNull()]
object[] WriteMultipleItemValues( 
   object argumentsArray
)
[NotNull()]
array<Object^>^ WriteMultipleItemValues( 
   Object^ argumentsArray
) 

Parameters

argumentsArray
Array of argument objects for the operation.

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

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Return Value

The function returns an array of OpcLabs.BaseLib.OperationModel.OperationResult objects. The indices of elements in the output array are the same as those in the input arrays.

This method never returns null (Nothing in Visual Basic).

The individual elements of the returned value are never null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

The size of the input array will become the size of the output array. The element positions (indices) in the output array are the same as in the input array.

This method does not throw an exception in case of OPC operation failures. Instead, the eventual exception related to each item is returned in Exception property of each returned OpcLabs.BaseLib.OperationModel.OperationResult element.

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.

The server(s) can be local or can be remotely accessed via DCOM.

Optionally, a specific data type can be requested, or an access path can be specified (OPC DA 1.0 only).

Example

COM

COM

COM

// This example shows how to write a value into a single OPC XML-DA item.
//
// 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 WriteItemValue.MainXml;
var
  Arguments: OleVariant;
  Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
  ItemValueArguments1: _DAItemValueArguments;
  Results: OleVariant;
  OperationResult: _OperationResult;
begin
  ItemValueArguments1 := CoDAItemValueArguments.Create;
  ItemValueArguments1.ServerDescriptor.UrlString := 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx';
  ItemValueArguments1.ItemDescriptor.ItemID := 'Static/Analog Types/Int';
  ItemValueArguments1.Value := 12345;

  Arguments := VarArrayCreate([0, 0], varVariant);
  Arguments[0] := ItemValueArguments1;

  // Instantiate the client object
  Client := CoEasyDAClient.Create;

  TVarData(Results).VType := varArray or varVariant;
  TVarData(Results).VArray := PVarArray(
    Client.WriteMultipleItemValues(Arguments));

  OperationResult := IInterface(Results[0]) as _OperationResult;
  if Not OperationResult.Succeeded then
      WriteLn(' *** Failure: ', OperationResult.Exception.GetBaseException.Message);
  
  VarClear(Results);
  VarClear(Arguments);

end;
// This example shows how to write a value into a single OPC XML-DA item.
//
// 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.

$ItemValueArguments1 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
$ItemValueArguments1->ServerDescriptor->UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
$ItemValueArguments1->ItemDescriptor->ItemID = "Static/Analog Types/Int";
$ItemValueArguments1->Value = 12345;

$arguments[0] = $ItemValueArguments1;

// Instantiate the client object.
$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");

$results = $Client->WriteMultipleItemValues($arguments);

$OperationResult = $results[0];
if ($OperationResult->Succeeded)
    printf("Result: success\n");
else
    printf("Result: %s\n", $OperationResult->ErrorMessageBrief);
Rem This example shows how to write a value into a single OPC XML-DA item.
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 WriteItemValue_MainXml_Command_Click()
    OutputText = ""
    
    Dim itemValueArguments1 As New DAItemValueArguments
    itemValueArguments1.serverDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
    itemValueArguments1.ItemDescriptor.ItemId = "Static/Analog Types/Int"
    itemValueArguments1.SetValue 12345
    
    Dim arguments(0) As Variant
    Set arguments(0) = itemValueArguments1

    ' Instantiate the client object
    Dim client As New EasyDAClient

    ' Modify values of nodes
    Dim results() As Variant
    results = client.WriteMultipleItemValues(arguments)

    Dim operationResult As operationResult: Set operationResult = results(0)
    If Not operationResult.Succeeded Then
        OutputText = OutputText & "*** Failure: " & operationResult.ErrorMessageBrief & vbCrLf
    End If
End Sub
Rem This example shows how to write a value into a single OPC XML-DA item.
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 ItemValueArguments1: Set ItemValueArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments")
ItemValueArguments1.ServerDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ItemValueArguments1.ItemDescriptor.ItemID = "Static/Analog Types/Int"
ItemValueArguments1.Value = 12345

Dim arguments(0)
Set arguments(0) = ItemValueArguments1

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim results: results = Client.WriteMultipleItemValues(arguments)

Dim OperationResult: Set OperationResult = results(0)
If OperationResult.Succeeded Then
    WScript.Echo "Result: success"
Else
    WScript.Echo "Result: " & OperationResult.Exception.GetBaseException.Message
End If
// This example shows how to write values 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 WriteMultipleItemValues.Main;
var
  Arguments: OleVariant;
  Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
  I: Cardinal;
  ItemValueArguments1: _DAItemValueArguments;
  ItemValueArguments2: _DAItemValueArguments;
  ItemValueArguments3: _DAItemValueArguments;
  Results: OleVariant;
  OperationResult: _OperationResult;

begin
  ItemValueArguments1 := CoDAItemValueArguments.Create;
  ItemValueArguments1.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  ItemValueArguments1.ItemDescriptor.ItemID := 'Simulation.Register_I4';
  ItemValueArguments1.Value := 23456;

  ItemValueArguments2 := CoDAItemValueArguments.Create;
  ItemValueArguments2.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  ItemValueArguments2.ItemDescriptor.ItemID := 'Simulation.Register_R8';
  ItemValueArguments2.Value := 2.34567890;

  ItemValueArguments3 := CoDAItemValueArguments.Create;
  ItemValueArguments3.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  ItemValueArguments3.ItemDescriptor.ItemID := 'Simulation.Register_BSTR';
  ItemValueArguments3.Value := 'ABC';

  Arguments := VarArrayCreate([0, 2], varVariant);
  Arguments[0] := ItemValueArguments1;
  Arguments[1] := ItemValueArguments2;
  Arguments[2] := ItemValueArguments3;

  // Instantiate the client object
  Client := CoEasyDAClient.Create;

  // Modify values of nodes
  TVarData(Results).VType := varArray or varVariant;
  TVarData(Results).VArray := PVarArray(
    Client.WriteMultipleItemValues(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;
// This example shows how to write values 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 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.

$ItemValueArguments1 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
$ItemValueArguments1->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ItemValueArguments1->ItemDescriptor->ItemID = "Simulation.Register_I4";
$ItemValueArguments1->Value = 23456;

$ItemValueArguments2 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
$ItemValueArguments2->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ItemValueArguments2->ItemDescriptor->ItemID = "Simulation.Register_R8";
$ItemValueArguments2->Value = 2.34567890;

$ItemValueArguments3 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
$ItemValueArguments3->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ItemValueArguments3->ItemDescriptor->ItemID = "Simulation.Register_BSTR";
$ItemValueArguments3->Value = "ABC";

$arguments[0] = $ItemValueArguments1;
$arguments[1] = $ItemValueArguments2;
$arguments[2] = $ItemValueArguments3;

$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
$results = $Client->WriteMultipleItemValues($arguments);

for ($i = 0; $i < count($results); $i++)
{
    $OperationResult = $results[$i];
    if ($OperationResult->Succeeded)
        printf("Result %d: success\n", $i);
    else
        printf("Result  s\n", $i, $OperationResult->ErrorMessageBrief);
}
REM This example shows how to write values 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 WriteMultipleItemValues_Main_Command_Click()
    OutputText = ""
    
    Dim itemValueArguments1 As New DAItemValueArguments
    itemValueArguments1.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
    itemValueArguments1.ItemDescriptor.itemId = "Simulation.Register_I4"
    itemValueArguments1.SetValue 23456
    
    Dim itemValueArguments2 As New DAItemValueArguments
    itemValueArguments2.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
    itemValueArguments2.ItemDescriptor.itemId = "Simulation.Register_R8"
    itemValueArguments2.SetValue 2.3456789
    
    Dim itemValueArguments3 As New DAItemValueArguments
    itemValueArguments3.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
    itemValueArguments3.ItemDescriptor.itemId = "Simulation.Register_BSTR"
    itemValueArguments3.SetValue "ABC"
    
    Dim arguments(2) As Variant
    Set arguments(0) = itemValueArguments1
    Set arguments(1) = itemValueArguments2
    Set arguments(2) = itemValueArguments3

    ' Instantiate the client object
    Dim client As New EasyDAClient

    ' Modify values of nodes
    Dim results() As Variant
    results = client.WriteMultipleItemValues(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 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 ItemValueArguments1: Set ItemValueArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments")
ItemValueArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemValueArguments1.ItemDescriptor.ItemID = "Simulation.Register_I4"
ItemValueArguments1.Value = 23456

Dim ItemValueArguments2: Set ItemValueArguments2 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments")
ItemValueArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemValueArguments2.ItemDescriptor.ItemID = "Simulation.Register_R8"
ItemValueArguments2.Value = 2.34567890

Dim ItemValueArguments3: Set ItemValueArguments3 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments")
ItemValueArguments3.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemValueArguments3.ItemDescriptor.ItemID = "Simulation.Register_BSTR"
ItemValueArguments3.Value = "ABC"

Dim arguments(2)
Set arguments(0) = ItemValueArguments1
Set arguments(1) = ItemValueArguments2
Set arguments(2) = ItemValueArguments3

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim results: results = Client.WriteMultipleItemValues(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
// This example shows how to write values into 3 items at once, test for success of each write and display the exception 
// message in case of failure.
//
// 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.

$ItemValueArguments1 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
$ItemValueArguments1->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ItemValueArguments1->ItemDescriptor->ItemID = "Simulation.Register_I4";
$ItemValueArguments1->Value = 23456;

$ItemValueArguments2 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
$ItemValueArguments2->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ItemValueArguments2->ItemDescriptor->ItemID = "Simulation.Register_R8";
$ItemValueArguments2->Value = "This string cannot be converted to VT_R8";

$ItemValueArguments3 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
$ItemValueArguments3->ServerDescriptor->ServerClass = "OPCLabs.KitServer.2";
$ItemValueArguments3->ItemDescriptor->ItemID = "UnknownItem";
$ItemValueArguments3->Value = "ABC";

$arguments[0] = $ItemValueArguments1;
$arguments[1] = $ItemValueArguments2;
$arguments[2] = $ItemValueArguments3;

$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
$results = $Client->WriteMultipleItemValues($arguments);

for ($i = 0; $i < count($results); $i++)
{
    $OperationResult = $results[$i];
    if ($OperationResult->Succeeded)
        printf("Result %d: success\n", $i);
    else
        printf("Result  s\n", $i, $OperationResult->ErrorMessageBrief);
}
Rem This example shows how to write values into 3 items at once, test for success of each write and display the exception 
Rem message in case of failure.
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 ItemValueArguments1: Set ItemValueArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments")
ItemValueArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemValueArguments1.ItemDescriptor.ItemID = "Simulation.Register_I4"
ItemValueArguments1.Value = 23456

Dim ItemValueArguments2: Set ItemValueArguments2 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments")
ItemValueArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemValueArguments2.ItemDescriptor.ItemID = "Simulation.Register_R8"
ItemValueArguments2.Value = "This string cannot be converted to VT_R8"

Dim ItemValueArguments3: Set ItemValueArguments3 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments")
ItemValueArguments3.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ItemValueArguments3.ItemDescriptor.ItemID = "UnknownItem"
ItemValueArguments3.Value = "ABC"

Dim arguments(2)
Set arguments(0) = ItemValueArguments1
Set arguments(1) = ItemValueArguments2
Set arguments(2) = ItemValueArguments3

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim results: results = Client.WriteMultipleItemValues(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
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