Register    Login
 
Professional OPC Development Tools
And Services
 
 
SupportOnline Forums
 
Links: Related Pages
 
Links: Related Services
 
Links: Related Support
 
Links: Related Resources
 
Online Forums

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

OPC Labs team is actively monitoring the forums, and provides answers as soon as possible. For your convenience, we have also assembled a Frequently Asked Questions page.

Please do not use the Contact page for technical support.

HINT: You may use the Search feature (magnifier icon below) in the forums to locate the information you need. You can also search our entire Web site (the search box in the upper right corner of every page).

 
 
SupportSupportKnowledge Base ...Knowledge Base ...QuickOPC-ClassicQuickOPC-ClassicQuickOPC.NETQuickOPC.NETQON-KB-4. How to browse OPC address space in C#, and read the items foundQON-KB-4. How to browse OPC address space in C#, and read the items found
Previous Previous
 
Next Next
New Post
 3/3/2011 7:27 AM
 
 Modified By OPC Labs Technical Support  on 3/3/2011 5:28:33 PM

A new example illustrating how to browse and read is available in QuickOPC-NET Bonus Pack 5.04.104.1; the source looks like this:

// BrowseAndReadValues: Console application that recursively browses and displays the nodes in the OPC address space, and 

// attempts to read and display values of all OPC items it finds.

using OpcLabs.EasyOpc;

using OpcLabs.EasyOpc.DataAccess;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace BrowseAndReadValues

{

    class Program

    {

        const string serverClass = "OPCLabs.KitServer.2";

        static EasyDAClient client = new EasyDAClient();

        static void BrowseAndReadFromNode(string parentItemId)

        {

            // Obtain all node elements under parentItemId

            var nodeFilter = new DANodeFilter();    // no filtering whatsoever

            Dictionary<stringDANodeElement> nodeDictionary = client.BrowseNodes("", serverClass, parentItemId, nodeFilter);

            // Note that BrowseNodes(...) may also throw OpcException; a production code should contain handling for it, here 

            // omitted for brevity.

            foreach (DANodeElement nodeElement in nodeDictionary.Values)

            {

                // If the node is a leaf, it might be possible to read from it

                if (nodeElement.IsLeaf)

                {

                    // Determine what the display - either the value read, or exception message in case of failure.

                    string display;

                    try

                    {

                        object value = client.ReadItemValue("", serverClass, nodeElement.ItemId);

                        display = String.Format("{0}", value);

                    }

                    catch (OpcException exception)

                    {

                        display = String.Format("** {0} **", exception.GetBaseException().Message);

                    }

                    Console.WriteLine("{0} -> {1}", nodeElement.ItemId, display);

                }

                // If the node is not a leaf, just display its itemId

                else

                    Console.WriteLine("{0}", nodeElement.ItemId);

                // If the node is a branch, browse recursively into it.

                if (nodeElement.IsBranch)

                    BrowseAndReadFromNode(nodeElement.ItemId);

            }

        }

        static void Main(string[] args)

        {

            Console.WriteLine("Browsing and reading values...");

            // Set timeout to only wait 1 second - default would be 1 minute to wait for good quality that may never come.

            client.Timeouts.ReadItem = 1000;

            // Do the actual browsing and reading, starting from root of OPC address space (denoted by empty string for itemId)

            BrowseAndReadFromNode("");

            Console.WriteLine("Press Enter to continue...");

            Console.ReadLine();

        }

    }

}

New Post
 3/3/2011 7:33 AM
 

Here is the example output:

Browsing and reading values...
Trends
Trends.Ramp (10 s) -> 0.601315975189209
Trends.Ramp (10 min) -> 0.960227020084858
Trends.Ramp (1 s) -> 0.238754272460938
Trends.Sine (10 s) -> -0.752575871764547
Trends.Sine (1 min) -> -0.626574002237867
Trends.Sine (1 s) -> -0.41361193740018
Trends.Sine (10 min) -> -0.241893787514361
Trends.Ramp (1 min) -> 0.613468527793884
$ServerControl
$ServerControl.$Mode -> 0
$ServerControl.Command -> ** Topic not updated with quality that is not bad (timeout). **
Demo
Demo.Single -> 6.092882
Demo.Ramp -> 6.2960147857666
Greenhouse
Greenhouse.Sprinklers -> 0
Greenhouse.Humidity -> 47
Greenhouse.Temperature -> 22.82095
Greenhouse.RoofOpen -> 25
Simulation
Simulation.Register_R4 -> 0
Simulation.Register_I4 -> 0
Simulation.Register_ArrayOfI2 -> ** Type mismatch. **
Simulation.Register -> 0
Simulation.ReadValue_UI2 -> 9
Simulation.ReadValue_ArrayOfR4 -> System.Single[]
Simulation.ReadValue_ArrayOfI4 -> System.Int32[]
Simulation.ReadValue_ArrayOfBSTR -> System.String[]
Simulation.Ramp 0-100 (10 s) -> 95.7677364349365
Simulation.Ramp (10 s) -> 0.967833995819092
Simulation.Incrementing (1 min) -> 0
Simulation.ReadValue_INT -> 10
Simulation.ReadValue_ArrayOfDATE -> System.DateTime[]
Simulation.ReadValue_ArrayOfCY -> System.Decimal[]
Simulation.Random (10 min) -> 0.56358531449324
Simulation.Register_BOOL -> False
Simulation.ReadValue_ArrayOfI2 -> System.Int16[]
Simulation.Incrementing (1 s) -> 4
Simulation.ReadWriteCount -> 2
Simulation.ReadValue_UI1 -> 1
Simulation.ReadValue_BOOL -> True
Simulation.ReadValue_ArrayOfI1 -> System.Int16[]
Simulation.RegisterSet_3
Simulation.RegisterSet_3.I4 -> 0
Simulation.RegisterSet_3.ArrayOfUI2 -> ** Type mismatch. **
Simulation.Register_R8 -> 0
Simulation.Register_NULL ->
Simulation.ReadValue_UINT -> 2
Simulation.Incrementing (10 min) -> 0
Simulation.RegisterSet_2
Simulation.RegisterSet_2.I4 -> 0
Simulation.RegisterSet_2.ArrayOfUI2 -> ** Type mismatch. **
Simulation.RegisterSet_10
Simulation.RegisterSet_10.I4 -> 0
Simulation.RegisterSet_10.ArrayOfUI2 -> ** Type mismatch. **
Simulation.RegisterSet_1
Simulation.RegisterSet_1.I4 -> 0
Simulation.RegisterSet_1.ArrayOfUI2 -> ** Type mismatch. **
Simulation.Register_RECORD -> ** Type mismatch. **
Simulation.ReadValue_DECIMAL -> 2.59446620941162
Simulation.ReadValue_DATE -> 1/1/1900 4:42:17 PM
Simulation.Register_UINT -> 0
Simulation.ReadValue_I4 -> 3
Simulation.ReadValue_I2 -> 3
Simulation.ReadValue_I1 -> 3
Simulation.Random (1 s) -> 0.193304239020966
Simulation.Ramp (1 s) -> 0.397232055664063
Simulation.RegisterSet_7
Simulation.RegisterSet_7.I4 -> 0
Simulation.RegisterSet_7.ArrayOfUI2 -> ** Type mismatch. **
Simulation.Register_UI4 -> 0
Simulation.Register_UI2 -> 0
Simulation.Register_UI1 -> 0
Simulation.Incrementing (10 s) -> 0
Simulation.RegisterSet_6
Simulation.RegisterSet_6.I4 -> 0
Simulation.RegisterSet_6.ArrayOfUI2 -> ** Type mismatch. **
Simulation.Register_ERROR -> ** Type mismatch. **
Simulation.Register_CY -> 0.0000
Simulation.RegisterSet_5
Simulation.RegisterSet_5.I4 -> 0
Simulation.RegisterSet_5.ArrayOfUI2 -> ** Type mismatch. **
Simulation.Register_VARIANT -> ** Type mismatch. **
Simulation.Register_DECIMAL -> 0
Simulation.ReadValue_ArrayOfUINT -> System.Int64[]
Simulation.ReadValue_ArrayOfUI4 -> System.Int64[]
Simulation.ReadValue_ArrayOfUI2 -> System.Int32[]
Simulation.ReadValue_ArrayOfUI1 -> System.Byte[]
Simulation.RegisterSet_4
Simulation.RegisterSet_4.I4 -> 0
Simulation.RegisterSet_4.ArrayOfUI2 -> ** Type mismatch. **
Simulation.Register_EMPTY ->
Simulation.Register_I1 -> 0
Simulation.ReadValue_ArrayOfBOOL -> System.Boolean[]
Simulation.Register_BSTR ->
Simulation.ReadValue_R8 -> 6.16589069366455
Simulation.ReadValue_R4 -> 6.267459
Simulation.ReadValue_CY -> 6.4149
Simulation.ReadValue_ArrayOfR8 -> System.Double[]
Simulation.ReadValue_ArrayOfINT -> System.Int32[]
Simulation.Random (1 min) -> 0.895962401196326
Simulation.Random -> 0.00125125888851588
Simulation.Incrementing -> -1
Simulation.RegisterSet_9
Simulation.RegisterSet_9.I4 -> 0
Simulation.RegisterSet_9.ArrayOfUI2 -> ** Type mismatch. **
Simulation.Register_DISPATCH ->
Simulation.RegisterSet_8
Simulation.RegisterSet_8.I4 -> 0
Simulation.RegisterSet_8.ArrayOfUI2 -> ** Type mismatch. **
Simulation.Register_INT -> 0
Simulation.Register_I2 -> 0
Simulation.ReadValue_UI4 -> 8
Simulation.Register_UNKNOWN -> ** Type mismatch. **
Simulation.Register_DATE -> 12/30/1899 12:00:00 AM
Simulation.ReadValue_BSTR -> 8.17768812179565
Simulation.Random (10 s) -> 0.47987304300058
Press Enter to continue...

and the zipped project (for Visual Studio 2010):

BrowseAndReadValues.zip (4.27 KB)

New Post
 11/29/2011 3:34 AM
 

Starting with Version 5.12, the example presented here needs to be modified slightly: the BrowseNodes methods now returns DANodeElementCollection (derived from KeyedCollection<>).

The updated example is included with the product.

Previous Previous
 
Next Next
SupportSupportKnowledge Base ...Knowledge Base ...QuickOPC-ClassicQuickOPC-ClassicQuickOPC.NETQuickOPC.NETQON-KB-4. How to browse OPC address space in C#, and read the items foundQON-KB-4. How to browse OPC address space in C#, and read the items found

 
 
 
 
 

 
 
 
 
Home|Services|Products|Purchase|Downloads|Support|Resources|Company|Contact
Copyright 2007-2012 by OPC Labs Terms Of Use Privacy Statement May 18, 2012