// This example shows how to read 4 items from the device, and display their values, timestamps and qualities. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . using System; using System.Diagnostics; using OpcLabs.EasyOpc.DataAccess; using OpcLabs.EasyOpc.DataAccess.OperationModel; namespace DocExamples.DataAccess.Xml { partial class ReadMultipleItems { public static void DeviceSourceXml() { // 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("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double", DADataSource.Device), new DAReadItemArguments("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double[]", DADataSource.Device), new DAReadItemArguments("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Int", DADataSource.Device), new DAReadItemArguments("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Static/Analog Types/Int", DADataSource.Device) }); for (int i = 0; i < vtqResults.Length; i++) { Debug.Assert(vtqResults[i] != null); if (vtqResults[i].Succeeded) Console.WriteLine("vtqResults[{0}].Vtq: {1}", i, vtqResults[i].Vtq); else Console.WriteLine("vtqResults[{0}] *** Failure: {1}", i, vtqResults[i].ErrorMessageBrief); } } // Example output: // //vtqResults[0].Vtq: 100 {Double} @2024-01-01T14:31:03.232; GoodNonspecific (192) //vtqResults[1].Vtq: [3] {1000, 1000, 1000} {Double[]} @2024-01-01T14:31:03.232; GoodNonspecific (192) //vtqResults[2].Vtq: 700 {Int32} @2024-01-01T14:31:03.232; GoodNonspecific (192) //vtqResults[3].Vtq: 0 {Int32} @2024-01-01T14:31:03.232; GoodNonspecific (192) } }
# This example shows how to read 4 items from the device, and display their values, timestamps and qualities. # # 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 . # 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 * # 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 will be based on the desired value age and # current status of data received from the server. vtqResults = client.ReadMultipleItems( [ DAReadItemArguments(ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'), DAItemDescriptor('Dynamic/Analog Types/Double'), DAReadParameters(DADataSource.Device)), DAReadItemArguments(ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'), DAItemDescriptor('Dynamic/Analog Types/Double[]'), DAReadParameters(DADataSource.Device)), DAReadItemArguments(ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'), DAItemDescriptor('Dynamic/Analog Types/Int'), DAReadParameters(DADataSource.Device)), DAReadItemArguments(ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'), DAItemDescriptor('Static/Analog Types/Int'), DAReadParameters(DADataSource.Device)) ]) for i, vtqResult in enumerate(vtqResults): assert vtqResult is not None if vtqResult.Succeeded: print('vtqResults[', i, '].Vtq: ', vtqResult.Vtq, sep='') else: print('vtqResults[', i, '] *** Failure: ', vtqResult.ErrorMessageBrief, sep='') # Example output: # #vtqResults[0].Vtq: 100 {Double} @2024-01-01T14:31:03.232; GoodNonspecific (192) #vtqResults[1].Vtq: [3] {1000, 1000, 1000} {Double[]} @2024-01-01T14:31:03.232; GoodNonspecific (192) #vtqResults[2].Vtq: 700 {Int32} @2024-01-01T14:31:03.232; GoodNonspecific (192) #vtqResults[3].Vtq: 0 {Int32} @2024-01-01T14:31:03.232; GoodNonspecific (192)
' This example shows how to read 4 items from the device, and display their values, timestamps and qualities. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . Imports OpcLabs.EasyOpc.DataAccess Imports OpcLabs.EasyOpc.DataAccess.OperationModel Namespace DataAccess.Xml Partial Friend Class ReadMultipleItems Public Shared Sub DeviceSourceXml() ' Instantiate the client object. Dim 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. Dim vtqResults() As DAVtqResult = client.ReadMultipleItems(New DAReadItemArguments() { New DAReadItemArguments("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double", DADataSource.Device), New DAReadItemArguments("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Double[]", DADataSource.Device), New DAReadItemArguments("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Int", DADataSource.Device), New DAReadItemArguments("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Static/Analog Types/Int", DADataSource.Device) }) For i = 0 To vtqResults.Length - 1 Debug.Assert(vtqResults(i) IsNot Nothing) If vtqResults(i).Succeeded Then Console.WriteLine("vtqResults[{0}].Vtq: {1}", i, vtqResults(i).Vtq) Else Console.WriteLine("vtqResults[{0}] *** Failure: {1}", i, vtqResults(i).ErrorMessageBrief) End If Next i End Sub ' Example output ' 'vtqResults[0].Vtq: 100 {Double} @2024-01-01T14:31:03.232; GoodNonspecific (192) 'vtqResults[1].Vtq: [3] {1000, 1000, 1000} {Double[]} @2024-01-01T14:31:03.232; GoodNonspecific (192) 'vtqResults[2].Vtq: 700 {Int32} @2024-01-01T14:31:03.232; GoodNonspecific (192) 'vtqResults[3].Vtq: 0 {Int32} @2024-01-01T14:31:03.232; GoodNonspecific (192) End Class End Namespace
Copyright © 2004-2024 CODE Consulting and Development, s.r.o., Plzen. All rights reserved. Web page: www.opclabs.com
Send Documentation Feedback. Resources: Knowledge Base, Product Downloads. Technical support: Online Forums, FAQ.Missing some example? Ask us for it on our Online Forums! You do not have to own a commercial license in order to use Online Forums, and we reply to every post.