// Shows how to write into multiple OPC items using a single method call, specifying their requested data types.
using System;
using System.Diagnostics;
using OpcLabs.BaseLib.ComInterop;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class WriteMultipleItemValues
{
public static void RequestedDataType()
{
// 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_I2", 12345)
{ ItemDescriptor = { RequestedDataType = VarTypes.I2}}, // <-- the requested data type
new DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_R4", 234.56)
{ ItemDescriptor = { RequestedDataType = VarTypes.R4}} // <-- the requested data type
});
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);
}
}
Console.WriteLine("Reading multiple item values...");
ValueResult[] valueResultArray = client.ReadMultipleItemValues("OPCLabs.KitServer.2",
new DAItemDescriptor[] { "Simulation.Register_I2", "Simulation.Register_R4" });
for (int i = 0; i < valueResultArray.Length; i++)
{
Debug.Assert(valueResultArray[i] != null);
Console.WriteLine("valueResultArray[{0}]: {1}", i, valueResultArray[i]);
}
}
}
}
' Shows how to write into multiple OPC items using a single method call, specifying their requested data types.
Imports OpcLabs.BaseLib.ComInterop
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel
Namespace DocExamples.DataAccess._EasyDAClient
Partial Friend Class WriteMultipleItemValues
Public Shared Sub RequestedDataType()
Dim client = New EasyDAClient()
Console.WriteLine("Writing multiple item values...")
Dim resultArray = client.WriteMultipleItemValues(New DAItemValueArguments() { _
New DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I2", 12345) With _
{.ItemDescriptor = New DAItemDescriptor() With {.RequestedDataType = VarTypes.I2}}, _
New DAItemValueArguments("", "OPCLabs.KitServer.2", "Simulation.Register_R4", 234.56) With _
{.ItemDescriptor = New DAItemDescriptor() With {.RequestedDataType = VarTypes.R4}} _
})
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
Console.WriteLine("Reading multiple item values...")
Dim valueResultArray = client.ReadMultipleItemValues("OPCLabs.KitServer.2",
New DAItemDescriptor() {"Simulation.Register_I2", "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