OPC Studio User's Guide and Reference
WriteMultipleItems Method (EasyDAClientCore)
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.DataAccess Namespace > EasyDAClientCore Class : WriteMultipleItems 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 named items into an OPC server or OPC servers. Values, qualities and timestamps are written.
Syntax
'Declaration
 
Public Function WriteMultipleItems( _
   ByVal argumentsArray() As DAItemVtqArguments _
) As OperationResult()
'Usage
 
Dim instance As EasyDAClientCore
Dim argumentsArray() As DAItemVtqArguments
Dim value() As OperationResult
 
value = instance.WriteMultipleItems(argumentsArray)
public OperationResult[] WriteMultipleItems( 
   DAItemVtqArguments[] 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.

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
// 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 C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// 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.

using System;
using System.Diagnostics;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    class WriteMultipleItems
    {
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            Console.WriteLine("Writing multiple items...");
            OperationResult[] resultArray = client.WriteMultipleItems(
                new[] { 
                    new DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_I4", 
                        new DAVtq(23456, DateTime.UtcNow, DAQualities.GoodNonspecific)),
                    new DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_R8", 
                        new DAVtq(2.34567890, DateTime.UtcNow, DAQualities.GoodNonspecific)),
                    new DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_BSTR", 
                        new DAVtq("ABC", DateTime.UtcNow, DAQualities.GoodNonspecific))
                });
            
            for (int i = 0; i < resultArray.Length; i++)
            {
                Debug.Assert(resultArray[i] != null);
                if (resultArray[i].Succeeded)
                    Console.WriteLine("Result {0}: success", i);
                else
                {
                    Debug.Assert(!(resultArray[i].Exception is null));
                    Console.WriteLine("Result {0} *** Failure: {1}", i, resultArray[i].ErrorMessageBrief);
                }
            }
        }
    }
}
# 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 PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell .
# 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.

#requires -Version 5.1
using namespace System
using namespace OpcLabs.EasyOpc.DataAccess
using namespace OpcLabs.EasyOpc.DataAccess.OperationModel

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicCore.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassic.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicComponents.dll"

# Instantiate the client object.
$client = New-Object EasyDAClient

Write-Host "Writing multiple items..."
$resultArray = $client.WriteMultipleItems(@(
    (New-Object DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_I4", 
        (New-Object DAVtq(23456, [DateTime]::UtcNow, [DAQualities]::GoodNonspecific)))),
    (New-Object DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_R8", 
        (New-Object DAVtq(2.345667890, [DateTime]::UtcNow, [DAQualities]::GoodNonspecific)))),
    (New-Object DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_BSTR",
        (New-Object DAVtq("ABC", [DateTime]::UtcNow, [DAQualities]::GoodNonspecific))))
    ))

for ($i = 0; $i -lt $resultArray.Length; $i++) {
    $result = $resultArray[$i]
    if ($result.Succeeded) {
        Write-Host "Result $($i): success"
    }
    else {
        Write-Host "Result $($i) *** Failure: $($result.ErrorMessageBrief)"
    }
}
' 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 VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' 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.

Imports OpcLabs.BaseLib.OperationModel
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel

Namespace DataAccess._EasyDAClient
    Partial Friend Class WriteMultipleItems
        Public Shared Sub Main1()
            ' Instantiate the client object.
            Dim client = New EasyDAClient()

            Console.WriteLine("Writing multiple items...")
            Dim resultArray() As OperationResult = client.WriteMultipleItems(New DAItemVtqArguments() {
                New DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_I4",
                    New DAVtq(23456, DateTime.UtcNow, DAQualities.GoodNonspecific)),
                New DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_R8",
                    New DAVtq(2.3456789, DateTime.UtcNow, DAQualities.GoodNonspecific)),
                New DAItemVtqArguments("OPCLabs.KitServer.2", "Simulation.Register_BSTR",
                    New DAVtq("ABC", DateTime.UtcNow, DAQualities.GoodNonspecific))
            })

            For i = 0 To resultArray.Length - 1
                Debug.Assert(resultArray(i) IsNot Nothing)

                If resultArray(i).Succeeded Then
                    Console.WriteLine("Result {0}: success", i)
                Else
                    Debug.Assert(resultArray(i).Exception IsNot Nothing)
                    Console.WriteLine("Result {0} *** Failure: {1}", i, resultArray(i).ErrorMessageBrief)
                End If
            Next i
        End Sub
    End Class
End Namespace
# 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 Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# 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.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from System import *
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.DataAccess.OperationModel import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object.
client = EasyDAClient()

print('Writing multiple items...')
operationResultArray = client.WriteMultipleItems([
    DAItemVtqArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_I4'),
                       DAVtq(23456, DateTime.UtcNow, DAQuality(DAQualities.GoodNonspecific))),
    DAItemVtqArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_R8'),
                       DAVtq(2.34567890, DateTime.UtcNow, DAQuality(DAQualities.GoodNonspecific))),
    DAItemVtqArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_BSTR'),
                       DAVtq('ABC', DateTime.UtcNow, DAQuality(DAQualities.GoodNonspecific))),
    ])

for i, operationResult in enumerate(operationResultArray):
    assert operationResult is not None
    if operationResult.Succeeded:
        print('operationResultArray[', i, ']: success', sep='')
    else:
        assert operationResult.Exception is not None
        print('operationResultArray[', i, '] *** Failure: ', operationResult.ErrorMessageBrief, sep='')

print('Finished.')
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