Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

How to get a list of Digital only measures?

More
17 Oct 2013 13:42 #1491 by support
This is expected behavior. Passing in VarType.Empty means that no filtering on data types will be done.

www.quickopc.com/files/onlinedocs/QuickOpc/5.22/Reference/Qu...fe1-35f5-4eeb-72e30474db39.htm

Please Log in or Create an account to join the conversation.

More
17 Oct 2013 10:06 #1490 by byteslash
Hi, thanks for the response.
I tried your solution, but there is one thing not working:

Here is my version:
public List<OpcMeasure> ReadMeasures(MeasureType mType, string rootTag="")
        {
            var res = new List<OpcMeasure>();
            try
            {
                VarType[] dataTypes = null;
                switch (mType)
                {
                    case MeasureType.Analogic:
                        dataTypes = OpcDataTypesGenerator.AnalogDataTypes();
                    break;
                    case MeasureType.Digital:
                        dataTypes = OpcDataTypesGenerator.DigitalDataTypes();
                    break;
                }
                foreach (var dataType in dataTypes) {
 
                    var nodeFilter = new DANodeFilter(DABrowseFilter.Leaves, "", "", dataType);
                    var nodeElements = _client.BrowseNodes(Host, ServerName, rootTag, nodeFilter);
 
                    // Store the leaf information into the dictionary, and
                    // associate the current data type with it.
                    res.AddRange(nodeElements.Select(nodeElement => new OpcMeasure {ItemId = nodeElement.ItemId, MeasureType = mType}));
                }
            }
            catch (NullReferenceException)
            {
                res = null;
            }
            catch (OpcException)
            {
                res = null;
            }
            return res;
        }


Here is the class OpcDataTypesGenerator

public static class OpcDataTypesGenerator {
        public static VarType[] AnalogDataTypes() {
 
            return new VarType[] {
                VarType.Empty,
                VarType.BStr,
                VarType.R4,
                VarType.R8
            };
        }
 
        public static VarType[] DigitalDataTypes() {
 
            return new VarType[] {
                VarType.Empty,
                VarType.Array,
                VarType.Bool,
                VarType.Date,
                VarType.Decimal,
                VarType.Int,
                VarType.UI1,
                VarType.UI2,
                VarType.UI4,
                VarType.UI8,
                VarType.UInt
            };
        }
    }

Testing this with
var obj = server.ReadMeasures(MeasureType.Digital, "Greenhouse");
Gives all 4 items with the datatype VarType.Empty.

I habe Matrikon tools also installed and i can see that none of the Greenhouses tags/items have null as datatypes. I tried this before this refactoring (the code as you gave it) and the results are the same.

The line (in either version)
var nodeElements = _client.BrowseNodes(Host, ServerName, rootTag, nodeFilter);

is the culprit as i think the filter is not being properly applied

Please Log in or Create an account to join the conversation.

More
17 Oct 2013 07:33 #1488 by support
Hello, assuming that you are using a method like EasyDAClient.BrowseLeaves, you can use EasyDAClient.BrowseNodes instead, and use one of the overloads that takes a DANodeFilter argument.

You may then be able to distinguish the OPC items by their data type (such as that the digitals will probably have VarType.Bool, the analogs can have VarType.R4 or VarType.R8, etc.).

There is a related example (also in the solution with the examples, under the Console/DocExamples project): www.quickopc.com/files/onlinedocs/QuickOpc/5.22/Reference/Qu...f1e-e7d5-0da4-10834397135e.htm .
// 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.
 
using System;
using System.Collections.Generic;
using OpcLabs.EasyOpc;
using OpcLabs.EasyOpc.DataAccess;
 
namespace DocExamples
{
    namespace _EasyDAClient
    {
        /*partial*/ class BrowseNodes
        {
            public static void DataTypes()
            {
                var easyDAClient = 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 VarType.Empty as the first data type. 
                // The leaves of "unlisted" data types will have VarType.Empty 
                // associated with them.
                var dataTypes = new VarType[] { VarType.Empty, VarType.I2, VarType.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 nodeFilter = new DANodeFilter(DABrowseFilter.Leaves, "", "", dataType);
                    DANodeElementCollection nodeElements =
                        easyDAClient.BrowseNodes("", "OPCLabs.KitServer.2", "Greenhouse", nodeFilter);
 
                    // 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);
                }
            }
        }
    }
}

I hope this helps

Please Log in or Create an account to join the conversation.

More
16 Oct 2013 09:44 #1483 by byteslash
Hi, i would like to know how to i tell if a item is digital, analog or alarm?
i can connect to a server and get all items/tags on it, but i want only one set at a time. can i do this?

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.063 seconds