// Shows how to write into multiple OPC items using a single method call, and read multiple item values back.
//
// 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
{
partial class WriteMultipleItemValues
{
public static void Main1()
{
// Instantiate the client object.
var client = new EasyDAClient();
Console.WriteLine("Writing multiple item values...");
OperationResult[] resultArray = client.WriteMultipleItemValues(
new[] {
new DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 12345),
new DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_BOOL", true),
new DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_R4", 234.56)
});
for (int i = 0; i < resultArray.Length; i++)
{
Debug.Assert(resultArray[i] != null);
if (resultArray[i].Succeeded)
Console.WriteLine($"Results[{i}]: success");
else
{
Debug.Assert(!(resultArray[i].Exception is null));
Console.WriteLine($"Results[{i}] *** Failure: {resultArray[i].ErrorMessageBrief}");
}
}
Console.WriteLine();
Console.WriteLine("Reading multiple item values...");
ValueResult[] valueResultArray = client.ReadMultipleItemValues("OPCLabs.KitServer.2",
new DAItemDescriptor[] {
"Simulation.Register_I4",
"Simulation.Register_BOOL",
"Simulation.Register_R4" });
for (int i = 0; i < valueResultArray.Length; i++)
{
Debug.Assert(valueResultArray[i] != null);
Console.WriteLine($"valueResultArray[{i}]: {valueResultArray[i]}");
}
// Example output:
//
//Writing multiple item values...
//Results[0]: success
//Results[1]: success
//Results[2]: success
//
//Reading multiple item values...
//valueResultArray[0]: Success; 12345 {System.Int32}
//valueResultArray[1]: Success; True {System.Boolean}
//valueResultArray[2]: Success; 234.56 {System.Single}
}
}
}
# Shows how to write into multiple OPC items using a single method call, and read multiple item values back.
#
# 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 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 item values..."
$resultArray = $client.WriteMultipleItemValues(@(
(New-Object DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 12345)),
(New-Object DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_BOOL", $true)),
(New-Object DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_R4", 234.56))
))
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)"
}
}
Write-Host
Write-Host "Reading multiple item values..."
$valueResultArray = [IEasyDAClientExtension]::ReadMultipleItemValues($client,
"OPCLabs.KitServer.2", @(
(New-Object DAItemDescriptor("Simulation.Register_I4")),
(New-Object DAItemDescriptor("Simulation.Register_BOOL")),
(New-Object DAItemDescriptor("Simulation.Register_R4"))
))
for ($i = 0; $i -lt $valueResultArray.Length; $i++) {
$valueResult = $valueResultArray[$i]
Write-Host "valueResultArray[$($i)]: $($valueResult)"
}
# Example output:
#
#Writing multiple item values...
#Result 0: success
#Result 1: success
#Result 2: success
#
#Reading multiple item values...
#valueResultArray[0]: Success; 12345 {System.Int32}
#valueResultArray[1]: Success; True {System.Boolean}
#valueResultArray[2]: Success; 234.56 {System.Single}
' This example shows how to write values into multiple items.
'
' 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 WriteMultipleItemValues
Public Shared Sub Main1()
Dim client = New EasyDAClient()
Dim argumentsArray = New DAItemValueArguments() { _
New DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 12345), _
New DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_BOOL", True), _
New DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_R4", 234.56) _
}
Dim resultArray As OperationResult() = client.WriteMultipleItemValues(argumentsArray)
For i = 0 To resultArray.Length - 1
Debug.Assert(resultArray(i) IsNot Nothing)
If resultArray(i).Succeeded Then
Console.WriteLine("Results[{0}]: success", i)
Else
Console.WriteLine("Results[{0}] *** Failure: {1}", i, resultArray(i).ErrorMessageBrief)
End If
Next i
Console.WriteLine("Reading multiple item values...")
Dim valueResultArray() As ValueResult = client.ReadMultipleItemValues("OPCLabs.KitServer.2", _
New DAItemDescriptor() { _
"Simulation.Register_I4",
"Simulation.Register_BOOL",
"Simulation.Register_R4"})
For i = 0 To valueResultArray.Length - 1
Debug.Assert(valueResultArray(i) IsNot Nothing)
Console.WriteLine("valueResultArray[{0}]: {1}", i, valueResultArray(i))
Next i
End Sub
End Class
End Namespace
// 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);
}
# Shows how to write into multiple OPC items using a single method call, and read multiple item values back.
#
# 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 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 item values...')
operationResultArray = client.WriteMultipleItemValues([
DAItemValueArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_I4'),
12345),
DAItemValueArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_BOOL'),
True),
DAItemValueArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_R4'),
234.56),
])
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('Reading multiple item values...')
try:
valueResultArray = IEasyDAClientExtension.ReadMultipleItemValues(client, ServerDescriptor('OPCLabs.KitServer.2'), [
DAItemDescriptor('Simulation.Register_I4'),
DAItemDescriptor('Simulation.Register_BOOL'),
DAItemDescriptor('Simulation.Register_R4'),
])
except OpcException as opcException:
print('*** Failure: ' + opcException.GetBaseException().Message)
exit()
for i, valueResult in enumerate(valueResultArray):
assert valueResult is not None
if valueResult.Succeeded:
print('valueResultArray[', i, '].Value: ', valueResult.Value, sep='')
else:
assert valueResult.Exception is not None
print('valueResultArray[', i, '] *** Failure: ', valueResult.ErrorMessageBrief, sep='')