Home Features
& Benefits What Is OPC Free Demo Purchasing Sample Code 
 & Support

How the OPC Data Control uses OPCEnum.exe

Introduction

This document compliments our DCOM Configuration tutorial by providing additional detail about how the OPC ActiveX Data control browses for available OPC servers on local and remote computers.

Who should read this?

This document should be read by the following people:

  • Anybody developing with OPC Data Control ActiveX who wishes to have an in-depth understanding of how the OPC ActiveX Data control gets the list of available OPC servers on a computer, and
  • Especially people developing with the OPC ActiveX Data Control where the OPC Server is on a different computer from the one the OPC ActiveX Data control is running on.

Pre-requisites

The following assumptions been made:

About The Reader

  • Familiarity with the OPC ActiveX Data Control product, and how to use it.
  • Familiarity with basic OPC terminology (read What is OPC if not)
  • Familiarity with basic COM and DCOM concepts
  • Familiarity with Windows NT/2000 Registry concepts

About The Software

  • You have the OPC ActiveX Data Control installed and correctly working
  • You have an OPC Server installed locally, or remotely
  • You have administrative permissions on your Windows NT/2000 computer(s).

How OPC Works in conjunction with COM to identify unique OPC Servers

OPC Servers are COM components, more specifically they are COM servers. COM components each have their own unique identification in the form of a Globally Unique Identifier (GUID), an example of which is shown below:

{6E617103-FF2D-11D2-8087-00105AA8F840}

Every unique OPC server application has a GUID that is unique to that server.  A quick note on terminology.  You will also see the terms CLSID and AppID. These are merely "uses" of the GUID. A CLSID is a "Class ID" and is a GUID used to uniquely identify a component or class. An AppID is an "Application ID" and is a GUID used to uniquely identify a software application.  For the purposes of this discussion and in high level OPC server discussions, you can use the terms GUID, CLSID, and AppID interchangeably to refer to the unique identifying string like the one above for a particular OPC server.

Usually you can find out the GUID for a server from the OPC server vendor. With the OPC ActiveX Data Control's Browse Demo that is installed with the product, you can inspect any properly installed OPC server on your computer and obtain the GUID. 

The above GUID is for the Software Toolbox TOP server OPC server. Not too friendly looking is it? not to panic, because COM components can also have a "human-friendly" name too which is called the Program Identifier (ProgID). The ProgID that corresponds to the GUID above is:

SWToolbox.TOPServer

All COM components are registered in the Windows NT/2000 Registry in several places specified by Microsoft. All OPC Servers make a standard set of registry entries specified by the OPC Data Access Specification.  If an OPC Client wants to find OPC Servers, then a search through the Windows NT/2000 Registry must be made.

Let's see this in an example:

Situation: Browsing for a list of OPC Servers on the local computer (using OPC Data Access 1.0 method)

When browsing for a list of OPC Servers, the following would happen:

    Access the Windows NT/2000 Registry

    Search through the Windows NT/2000 Registry for all OPC Servers - in OPC DA 1.0 all OPC servers made an entry under their GUID

    List the OPC Servers in your application

As you could imagine, searching through the entire Windows NT/2000 Registry would not be a fast operation and could take several minutes to complete.  In the OPC Data Access 1.0 Specification, this is how the list of available OPC servers on a target machine was obtained. 

Starting with the OPC Data Access 2.0 specification, an improvement was made.  On Windows operating systems there is a tool called the Component Category Manager. This tool provides a way to organize COM objects in the registry by category to allow for quicker retrieval.  Each unique category name in the Component Category Manager has a unique GUID associated with it. Starting with the OPC Data Access 2.0 specification, GUIDs were assigned for 2 categories: OPC Data Access 1.0 Servers {63D5F430-CFE4-11d1-B2C8-0060083BA1FB} and OPC Data Access 2.0 servers {63D5F432-CFE4-11d1-B2C8-0060083BA1FB}.  All OPC servers are required to make registry entries that associate themselves with the appropriate Component Category GUIDs for the OPC Data Access specification(s) they support. 

An OPC client can query the Component Category Manager for all servers that it has associated with the OPC category GUIDs.  This lookup is much faster than a walk through the entire registry. The only problem with this approach is that the Component Category Manager is an In-Process DLL, which from a practical point of view means it can only be accessed by applications running on the LOCAL machine. 

The solution to this shortcoming in the Component Category Manager is where we introduce OPCENUM.EXE.

What is OPCENUM.EXE?

OPCENUM.EXE is an executable that is usually found on computers with OPC software; such as OPC Servers or OPC Clients. The purpose of OPCENUM.EXE is to provide an interface into the local machine's Component Category Manager that can be accessed by remote OPC clients over DCOM. OPCEnum.exe provides several useful methods

  • IOPCServerList::EnumClassesofCategory - gets available OPC servers for a specified category of OPC server
  • IOPCServerList::GetClassDetails - given a CLSID, returns the ProgID and friendly name
  • IOPCServerList::CLSIDFromProgID - given a ProgID, returns the CLSID

So, when looking for a list of OPC Servers on the local machine, the following would happen:

  • The OPC Client would make a call to OPCENUM.EXE, specifically the IOPCServerList::EnumClassesofCategory method
  • OPCENUM.EXE would query the Component Category Manager on the machine that OPCEnum.exe is running on for the list of available servers.
  • OPCENUM.EXE would return the contents of the search in a pre-formatted structure to the OPC client
  • The client would display the information to the user

Where is OPCEnum.exe on a computer?

OPCEnum.exe needs to be installed on each computer that has OPC servers that you wish to access remotely.  Most OPC servers install it in \Winnt\System32 and properly register it. The OPC ActiveX Data Control also installs a copy.

If you do not have a copy on your remote machine, you can copy one from your local machine and place it into the \Winnt\System32 directory. After you have done this, open up a dos window and type opcenum.exe /regserver and press enter.  There is no visual feedback of the success of this step, but it is important to do if you are manually installing OPCenum.exe on a machine.

How OPC ActiveX Data Control uses OPCENUM.EXE

The OPC Data Control ActiveX uses the OPCENUM.EXE program in a very specific manner. It is imperative for your own understanding that you carefully review this next section if you plan to use the OPC ActiveX Data Control to connect to a remote OPC server and you want to insure robust operation.

Hint: The following section outlines the reasons behind the answers to most of the technical enquiries we receive with regards to connecting the OPC Data Control ActiveX to remote OPC Servers.

Firstly, the difference between GUID and PROGID

Remember the difference between the GUID and PROGID?

PROG ID:

GUID:

SWToolbox.TOPServer

{6E617103-FF2D-11D2-8087-00105AA8F840}

Besides the obvious differences between the ProgID and GUID, there is another important non-obvious difference between the two. The GUID is the most "reliable" form of identification you should use. Why? because this is actual ID of the COM object - you can't have a COM object without a GUID that uniquely identifies it.  You can have a COM object without a ProgID or friendly name, though if an OPC server didn't have a ProgID, it would most likely not pass the OPC compliance test. Also, there is a performance difference:

  • If you use the GUID; the OPC client can specify the OPC Server by it's actual name (GUID) and avoid an extra set of registry lookups.
  • If you use the PROGID; the OPC client must "lookup" the PROGID to find the GUID which can take several registry calls.

"But wait, once i find the OPC server once, i'm done" - not true - many calls between OPC clients and servers include the GUID of the OPC server in the calls. You wouldn't want to have to do a ProgID to CLSID lookup every time you make a call would you if you were writing the guts of an OPC client.

Summary: For these reasons we advise and recommend that you use the GUID (aka CLSID/AppID) of your OPC server in your OPC client application code to refer to the OPC server, particularly if the OPC server is on a different computer from the OPC client application.

How OPC Data Control works with PROGID and GUID

All of this comes into play when you look at how the OPC Data Control ActiveX will work when accessing a local or remote OPC Server. The ability to connect to a remote OPC Server does depend on the security settings you have configured for DCOM (see Dcom Config Tutorial). Having the right GUID or ProgID will do you no good if you don't have your DCOM security settings right.

A comparison is shown in the table below when contacting an OPC Server (locally or remotely) and when using the PROGID or the GUID/CLSID.

Connecting to Local OPC Server via PROGID

Connecting to Local OPC Server via GUID/CLSID

The OPC ActiveX Data Control will use OPCENUM.EXE on the local machine to look in the local Windows NT/2000 Registry to find the GUID for the PROGID. Once found, the OPC ActiveX Data Control have the information it needs to make a call to the OPC server.

The OPC ActiveX Data Control will directly connect to the OPC server using it's GUID/CLSID.

Connecting to Remote OPC Server via PROGID

Connecting to Remote OPC Server via GUID/CLSID

Not recommended.

You will have a problem if you try to do this. The OPC ActiveX Data Control will look in the local Windows NT/2000 Registry for the PROGID to try and get the GUID!

Without the GUID the OPC Data Control does not know how to connect to the OPC serer.

Solutions:

1) Highly Recommended: use the GUID/CLSID of the OPC server in all remote connections - see to the right.

or
 

2) If you install a copy of the OPC Server that you are trying to connect to on the remote computer then the necessary Windows NT/2000 Registry settings will be available to provide the OPC Data Control the information it needs. Many OPC server vendors include a small file that contains the registry settings that you can alternatively install - for example, with our TOP Server, you can double click on the file OPC_Remote.reg that gets installed with our TOP Server OPC server to

The OPC ActiveX Data Control will directly connect to the OPC server using it's GUID/CLSID. Windows will automatically route this via DCOM to the correct computer that you specify in the .PCName property of the OPC ActiveX Data control.

Note - if you do not specify a computer name in the .PCName property of the OPC ActiveX Data control then the ActiveX will attempt to connect to the specified OPC server on the local computer.

Final Analysis

From this document, you should now understand:

  • the importance of OPCENUM.EXE
  • why the GUID is so important and why it should be used instead of the PROGID when writing client applications using the OPC ActiveX Data Control.

From here, you may wish to review our DCOM Configuration Tutorial which will take you step-by-step configuring the DCOM Settings for both the OPC Server and the OPC Client.  Having proper DCOM security settings is a key step towards successful OPC client to remote OPC server connections.

 

Copyright Software Toolbox, Inc., 1996-2002, All Rights Reserved Worldwide.
148A East Charles Street, Matthews, North Carolina, USA 28105
Phone: 704-849-2773 or 1-888-665-3678 (US), Fax: 704-849-6388
Business hours - Monday to Friday, 8 AM to 5 PM EST (GMT-5)