Home Downloads Buy Now !

 OPCEnum

 

This sample uses OPCEnum either locally or via DCOM to get a list of OPC servers as IOServers.

 

using System;

using System.Collections;

using IDN.IO;

namespace OPCENUM_Example

{

    class Class1

    {

        [STAThread]

        static void Main(string[] args)

        {

            IONode node = new IONode();

  

            // The local machine is already the default NodeName

            // when the node is constructed.

            // However, any node's machine name can be used, i. e. ...

            // node.NodeName = "Brutus";

            node.NodeName = Environment.MachineName;

  

            // Try to get any Data Access 2.0 servers.

            SortedList servers = node.GetKnownServers();

            Console.WriteLine("OPC DA 2.0 Servers...");

            for (int i = 0; i < servers.Count; i++)

            {

                Console.WriteLine(((IOServer) servers.GetByIndex(i)).Name);

                Console.WriteLine(((IOServer) servers.GetByIndex(i)).Guid.ToString());

                Console.WriteLine(((IOServer) servers.GetByIndex(i)).ProgID);

                Console.WriteLine("");

            }

  

            // Try to get any Alarms and Events servers.

            Guid AECatagoryGuid = new Guid("58E13251-AC87-11d1-84D5-00608CB8A7E9");

            servers = node.GetKnownServers(AECatagoryGuid);

            Console.WriteLine("OPC AE Servers...");

            for (int i = 0; i < servers.Count; i++)

            {

                Console.WriteLine(((IOServer) servers.GetByIndex(i)).Name);

                Console.WriteLine(((IOServer) servers.GetByIndex(i)).Guid.ToString());

                Console.WriteLine(((IOServer) servers.GetByIndex(i)).ProgID);

                Console.WriteLine("");

            }

            Console.WriteLine("Done... [Enter] to exit.");

            node.Release();

            Console.ReadLine();

        }

    }

}

 



Copyright © 2004-2017 Industrial DOT NET, Inc.