// This example shows how to read 4 items from the device, and display their values, timestamps and qualities.
using System;
using System.Diagnostics;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class ReadMultipleItems
{
public static void DeviceSource()
{
// Instantiate the client object.
var client = new EasyDAClient();
// DADataSource enumeration:
// Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
// The data source (memory, OPC cache or OPC device) selection will be based on the desired value age and
// current status of data received from the server.
DAVtqResult[] vtqResults = client.ReadMultipleItems(
new []
{
new DAReadItemArguments("OPCLabs.KitServer.2", "Simulation.Random", DADataSource.Device),
new DAReadItemArguments("OPCLabs.KitServer.2", "Trends.Ramp (1 min)", DADataSource.Device),
new DAReadItemArguments("OPCLabs.KitServer.2", "Trends.Sine (1 min)", DADataSource.Device),
new DAReadItemArguments("OPCLabs.KitServer.2", "Simulation.Register_I4", DADataSource.Device)
});
for (int i = 0; i < vtqResults.Length; i++)
{
Debug.Assert(vtqResults[i] != null);
if (vtqResults[i].Succeeded)
Console.WriteLine("vtqResult[{0}].Vtq: {1}", i, vtqResults[i].Vtq);
else
Console.WriteLine("vtqResult[{0}] *** Failure: {1}", i, vtqResults[i].ErrorMessageBrief);
}
}
// Example output:
//
//vtqResult[0].Vtq: 0.00125125888851588 { System.Double} @2020-04-10T12:44:16.250; GoodNonspecific(192)
//vtqResult[1].Vtq: 0.270812898874283 {System.Double} @2020-04-10T12:44:16.248; GoodNonspecific(192)
//vtqResult[2].Vtq: 0.991434340167834 {System.Double} @2020-04-10T12:44:16.250; GoodNonspecific(192)
//vtqResult[3].Vtq: 0 {System.Int32} @1601-01-01T00:00:00.000; GoodNonspecific(192)
}
}
# This example shows how to read 4 items from the device, and display their values, timestamps and qualities.
# 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()
# DADataSource enumeration:
# Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
# The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
# current status of data received from the server.
#
vtqResultArray = client.ReadMultipleItems([
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Random'), DAReadParameters(DADataSource.Device)),
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Trends.Ramp (1 min)'), DAReadParameters(DADataSource.Device)),
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Trends.Sine (1 min)'), DAReadParameters(DADataSource.Device)),
DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_I4'), DAReadParameters(DADataSource.Device)),
])
for i, vtqResult in enumerate(vtqResultArray):
assert vtqResult is not None
if vtqResult.Succeeded:
print('vtqResultArray[', i, '].Vtq: ', vtqResult.Vtq, sep='')
else:
print('vtqResultArray[', i, '] *** Failure: ', vtqResult.ErrorMessageBrief, sep='')