// This example shows how to obtain data types of leaves in the OPC-DA address
// space by browsing and filtering, i.e. without the use of OPC properties.
// This technique allows determining the data types with servers that only
// support OPC-DA 1.0. It can also be more effective than the use of
// GetMultiplePropertyValues, if there is large number of leaves, and
// relatively small number of data types to be checked.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
using System;
using System.Collections.Generic;
using OpcLabs.BaseLib.ComInterop;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.AddressSpace;
using OpcLabs.EasyOpc.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class BrowseNodes
{
public static void DataTypes()
{
// Instantiate the client object.
var client = new EasyDAClient();
// Define the list of data types we will be checking for.
// Change as needed for your application.
// This technique is only usable if there is a known list of
// data types you are interested in. If you are interested in
// all leaves, even those that are of data types not explicitly
// listed, always include VarTypes.Empty as the first data type.
// The leaves of "unlisted" data types will have VarTypes.Empty
// associated with them.
var dataTypes = new VarType[] { VarTypes.Empty, VarTypes.I2, VarTypes.R4 };
// For each leaf found, this dictionary wil hold its associated data type.
var dataTypeDictionary = new Dictionary<DANodeElement, VarType>();
// For each data type, browse for leaves of this data type.
foreach (VarType dataType in dataTypes)
{
var browseParameters = new DABrowseParameters(DABrowseFilter.Leaves, "", "", dataType);
DANodeElementCollection nodeElements;
try
{
nodeElements = client.BrowseNodes("", "OPCLabs.KitServer.2", "Greenhouse", browseParameters);
}
catch (OpcException opcException)
{
Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
return;
}
// Store the leaf information into the dictionary, and
// associate the current data type with it.
foreach (var nodeElement in nodeElements)
dataTypeDictionary[nodeElement] = dataType;
}
// Display each leaf found, and its associated data type.
foreach (KeyValuePair<DANodeElement, VarType> pair in dataTypeDictionary)
{
DANodeElement nodeElement = pair.Key;
VarType dataType = pair.Value;
Console.WriteLine("{0}: {1}", nodeElement, dataType);
}
}
}
}
# This example shows how to obtain data types of leaves in the OPC-DA address
# space by browsing and filtering, i.e. without the use of OPC properties.
# This technique allows determining the data types with servers that only
# support OPC-DA 1.0. It can also be more effective than the use of
# GetMultiplePropertyValues, if there is large number of leaves, and
# relatively small number of data types to be checked.
#
# 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.BaseLib.ComInterop import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *
# Instantiate the client object.
client = EasyDAClient()
# Define the list of data types we will be checking for.
# Change as needed for your application.
# This technique is only usable if there is a known list of
# data types you are interested in. If you are interested in
# all leaves, even those that are of data types not explicitly
# listed, always include VarTypes.Empty as the first data type.
# The leaves of "unlisted" data types will have VarTypes.Empty
# associated with them.
dataTypes = [VarType(VarTypes.Empty), VarType(VarTypes.I2), VarType(VarTypes.R4)]
# For each leaf found, this dictionary wil hold its associated data type.
dataTypeDictionary = {}
# For each data type, browse for leaves of this data type.
for dataType in dataTypes:
browseParameters = DABrowseParameters(DABrowseFilter.Leaves, '', '', dataType)
try:
nodeElements = IEasyDAClientExtension.BrowseNodes(client,
'', 'OPCLabs.KitServer.2', 'Greenhouse', browseParameters)
except OpcException as opcException:
print('*** Failure: ' + opcException.GetBaseException().Message)
exit()
# Store the leaf information into the dictionary, and
# associate the current data type with it.
for nodeElement in nodeElements:
dataTypeDictionary[nodeElement] = dataType
# Display each leaf found, and its associated data type.
for nodeElement, dataType in dataTypeDictionary.items():
print(nodeElement, ': ', dataType, sep='')
' This example shows how to obtain data types of leaves in the OPC-DA address
' space by browsing and filtering, i.e. without the use of OPC properties.
' This technique allows determining the data types with servers that only
' support OPC-DA 1.0. It can also be more effective than the use of
' GetMultiplePropertyValues, if there is large number of leaves, and
' relatively small number of data types to be checked.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Imports OpcLabs.BaseLib.ComInterop
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.AddressSpace
Imports OpcLabs.EasyOpc.OperationModel
Namespace DataAccess._EasyDAClient
Partial Friend Class BrowseNodes
Shared Sub DataTypes()
Dim client = New EasyDAClient()
' Define the list of data types we will be checking for.
' Change as needed for your application.
' This technique is only usable if there is a known list of
' data types you are interested in. If you are interested in
' all leaves, even those that are of data types not explicitly
' listed, always include VarTypes.Empty as the first data type.
' The leaves of "unlisted" data types will have VarTypes.Empty
' associated with them.
Dim dataTypes() = New VarType() {VarTypes.Empty, VarTypes.I2, VarTypes.R4}
' For each leaf found, this dictionary wil hold its associated data type.
Dim dataTypeDictionary = New Dictionary(Of DANodeElement, VarType)()
' For each data type, browse for leaves of this data type.
For Each dataType As VarType In dataTypes
Dim browseParameters = New DABrowseParameters(DABrowseFilter.Leaves, "", "", dataType)
Dim nodeElements As DANodeElementCollection
Try
nodeElements = client.BrowseNodes("", "OPCLabs.KitServer.2", "Greenhouse", browseParameters)
Catch opcException As OpcException
Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
Exit Sub
End Try
' Store the leaf information into the dictionary, and
' associate the current data type with it.
For Each nodeElement In nodeElements
dataTypeDictionary(nodeElement) = dataType
Next nodeElement
Next dataType
For Each pair In dataTypeDictionary
Dim nodeElement As DANodeElement = pair.Key
Dim dataType As VarType = pair.Value
Console.WriteLine("{0}: {1}", nodeElement, dataType)
Next pair
End Sub
End Class
End Namespace