// This example shows how to write values, timestamps and qualities into 3 items at once.
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.
#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.
# 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.')