The example below combines the ability to browse for items with getting the data type property for each of the items obtained, for OPC XML-DA Servers.
// This example shows how to obtain a data type of all OPC XML-DA items under a branch. using System; using System.Linq; using OpcLabs.BaseLib.ComInterop; using OpcLabs.BaseLib.OperationModel; using OpcLabs.EasyOpc; using OpcLabs.EasyOpc.DataAccess; using OpcLabs.EasyOpc.DataAccess.AddressSpace; namespace DocExamples.DataAccess.Xml { class GetMultiplePropertyValues { public static void DataTypeXml() { // Instantiate the client object. var client = new EasyDAClient(); ServerDescriptor serverDescriptor = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"; // Browse for all leaves under the "Static/Analog Types" branch DANodeElementCollection nodeElementCollection = client.BrowseLeaves(serverDescriptor, "Static/Analog Types"); // Create list of node descriptors, one for each leaf obtained DANodeDescriptor[] nodeDescriptorArray = nodeElementCollection .Where(element => !element.IsHint) // filter out hint leafs that do not represent real OPC items (rare) .Select(element => new DANodeDescriptor(element)) .ToArray(); // Get the value of DataType property; it is a 16-bit signed integer ValueResult[] valueResultArray = client.GetMultiplePropertyValues(serverDescriptor, nodeDescriptorArray, DAPropertyIds.DataType); for (int i = 0; i < valueResultArray.Length; i++) { DANodeDescriptor nodeDescriptor = nodeDescriptorArray[i]; // Check if there has been an error getting the property value ValueResult valueResult = valueResultArray[i]; if (!(valueResult.Exception is null)) { Console.WriteLine("{0} *** Failure: {1}", nodeDescriptor.NodeId, valueResult.Exception.Message); continue; } // Convert the data type to VarType var varType = (VarType)(short)valueResult.Value; // Display the obtained data type Console.WriteLine("{0}: {1}", nodeDescriptor.ItemId, varType); } } } }
# This example shows how to obtain a data type of all OPC XML-DA items under a branch. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc # Import .NET namespaces. from OpcLabs.BaseLib.ComInterop import * from OpcLabs.EasyOpc import * from OpcLabs.EasyOpc.DataAccess import * from OpcLabs.EasyOpc.DataAccess.OperationModel import * from OpcLabs.EasyOpc.OperationModel import * serverDescriptor = ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx') # Instantiate the client object. client = EasyDAClient() # Browse for all leaves under the "Static/Analog Types" branch try: nodeElementCollection = IEasyDAClientExtension.BrowseLeaves(client, serverDescriptor, DANodeDescriptor('Static/Analog Types')) except OpcException as opcException: print('*** Failure: ' + opcException.GetBaseException().Message) exit() # Create list of node descriptors, one for each leaf obtained. filteredNodeElements = filter(lambda element: not element.IsHint, nodeElementCollection) nodeDescriptorArray = list(map(lambda element: DANodeDescriptor(element), filteredNodeElements)) # Get the value of DataType property; it is a 16-bit signed integer. resultArray = IEasyDAClientExtension.GetMultiplePropertyValues(client, serverDescriptor, nodeDescriptorArray, DAPropertyDescriptor.FromInt64(DAPropertyIds.DataType)) # Display results for i, valueResult in enumerate(resultArray): nodeDescriptor = nodeDescriptorArray[i] # Check if there has been an error getting the property value. if valueResult.Exception is None: # Convert the data type to VarType. varType = VarType(valueResult.Value) # Display the obtained data type. print(nodeDescriptor.ItemId, ': ', varType, sep='') else: print(nodeDescriptor.ItemId, ' *** Failure: ', valueResult.Exception.Message) print() print('Finished')
' This example shows how to obtain a data type of all OPC XML-DA items under a branch. Imports OpcLabs.BaseLib.ComInterop Imports OpcLabs.BaseLib.OperationModel Imports OpcLabs.EasyOpc Imports OpcLabs.EasyOpc.DataAccess Namespace DataAccess.Xml Friend Class GetMultiplePropertyValues Public Shared Sub DataTypeXml() Dim client = New EasyDAClient() Dim serverDescriptor As ServerDescriptor = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx" ' Browse for all leaves under the "Simulation" branch Dim nodeElementCollection = client.BrowseLeaves(serverDescriptor, "Static/Analog Types") ' Create list of node descriptors, one for each leaf obtained ' filter out hint leafs that do not represent real OPC items (rare) Dim nodeDescriptorArray() As DANodeDescriptor = nodeElementCollection _ .Where(Function(element) Not element.IsHint) _ .Select(Function(element) New DANodeDescriptor(element)) _ .ToArray() ' Get the value of DataType property; it is a 16-bit signed integer Dim valueResultArray() As ValueResult = client.GetMultiplePropertyValues(serverDescriptor, nodeDescriptorArray, DAPropertyIds.DataType) For i = 0 To valueResultArray.Length - 1 Dim nodeDescriptor = nodeDescriptorArray(i) ' Check if there has been an error getting the property value Dim valueResult As ValueResult = valueResultArray(i) If valueResult.Exception IsNot Nothing Then Console.WriteLine("{0} *** Failure: {1}", nodeDescriptor.NodeId, valueResult.Exception.Message) Continue For End If ' Convert the data type to VarType Dim varType = CType(CShort(valueResult.Value), VarType) ' Display the obtained data type Console.WriteLine("{0}: {1}", nodeDescriptor.ItemId, varType) Next i End Sub End Class End Namespace
Copyright © 2004-2023 CODE Consulting and Development, s.r.o., Plzen. All rights reserved. Web page: www.opclabs.com
Send Documentation Feedback. Resources: Knowledge Base. Technical support: Online Forums, FAQ.