Maximizing OPC

Maximizing OPC

Introduction

    This article discusses how to best use the native OPC interfaces that the instrumentation controls provide.

    This document explains the tools available for not only using and interacting with an OPC Server, but putting them to best use and providing you with more control.

    If you are using the OPC Data Control ActiveX instead of the native OPC interfaces, then this article does not apply to you.

What this article will cover

    The following topics will be discussed:

    • Different ways of binding OPC Tags to Properties within an instrument and the resource-costs associated with each
    • The need for the consolidation of communications channels to an OPC Server
    • Manual control over the OPC tools provided
      • activating/deactivating individual tags/groups

What you can gain from this article

    You will gain a key understanding of the native OPC interfaces, which is important. You will also see and learn how to not only use the tools to a basic level, but how to utilize them within more advanced ways to give you total control over your application.

    This article is intended to turn you into an OPC expert for the tools provided with the instrumentation controls. This knowledge will empower you with the information and questions you need to know and ask in order to develop the best OPC-enabled HMI that fits your demands/needs.

Refresher: OPC Connectivity Re-visited

    As an OPC Client, your application is [somewhat] in charge and in control of the OPC Server with regards the way in which data is obtained from a PLC/Device.

    When an OPC Client connects to an OPC Server to subscribe to a Tag, the following happens:

    • The connection is made between the Client and Server
    • The Server allocates some memory space that is reserved for this client connection. This means that each OPC Client gets its own reserved memory address space within the OPC Server.
    • An "OPC Group" is added into the private address space for that OPC Client. The scan-rate of the Tags is defined within the Group.
    • A Tag is added into the OPC Group.
    • The group is made active and told to provide update notifications to the OPC Client when the Tag's values have changed.

    The description above is correct for adding a single Tag. Several Tags can exist within one Group. Several Groups can exist within the address-space reserved for the OPC Client within the OPC Server.

    So what does all this mean to you?

    Not all OPC Servers are created equally... some offer more features than others, some are simply limited compared to others. For this reason it is important to know if the OPC Server you are using has any limitations or limits with regards:

    1. How many simultanous OPC Client connections it can handle.
    2. How many Groups can be created within the OPC Clients address-space within the OPC Server.
    3. How many Tags can exist within a single OPC Group.
    4. Are there any performance trade-offs when using multiple OPC Client connections simultaneously.

How the Instruments connect to an OPC Server

    As you know, each Instrument control has its own "OPC" Tab within the control's property pages. When using these to bind a property of that control to a Tag within the OPC Server is essentially:

    • Creating a single connection to the OPC Server.
    • Creating a single Group within the memory address space reserved for that OPC Client connection within the OPC Server.
    • Adding a single Tag to that group.
    • Requesting update notifications for when the Tag's value changes.

    Assume you plan on creating an HMI screen with 10 controls, or 20 controls, or more... imagine each one doing the same as the above list.
    I think that could be expensive on resources and could be potentially taxing on an OPC Server...
    what do you think?

Consolidating multiple OPC connections through one physical connection

    The instrumentation controls contain a consolidation tool called "IOPCManager" which can establish a connection to an OPC Server, and then allow other instrumentation controls to read/write to OPC Tags through it.

    The way you use this tool is vey simple. Let's now take a look at how to use the IOPCManager component

    Step 1 - Referencing the OPC Manager Component

      VB6

      • Open the "Project" menu
      • Choose "Components" (or press CTRL+T)
      • The following screen will open:

      • Choose/highlight the option "IOComp OPC Common Library"
      • Click the OK button
      • The VB toolbar should now show the following icon:

      Visual Studio .NET

      • Right-click on the Visual Studio.NET toolbar
      • Choose "Add/Remove Items...".
      • Click on the Tab "COM Components"
      • It may take a few seconds before the screen changes.
      • Scroll-down the list and check the box for the "iOPCManage" component
      • click the OK button
      • The following icon will be added to the visual studio.net toolbar of controls:

    Step 2 - Adding an OPC Manager Component to your project

      Whether you are using VB6 or .NET (or any other development language) you simply need to place an instance of the "iOPCManagerX" component onto your form.

    Step 3 - Configuring an OPC connection

      Once you have an instance of the iOPCManagerX component on your form, you can simply open the property-pages for that control by right-clicking on it and choosing the option to open its properties. The following window will be displayed:

      We now need to specify a connection to an OPC Server, along with a suggested scan-rate for those Tags that will use this connection.

      Step 1 - click the "Add" button
      Step 2 - a new group is added
      Step 3 - give the group a name in the "Name" field
      Step 4 - specify the "computer" where the OPC Server resides.
      Step 5 - specify the "OPC Server" you wish to use
      Step 6 - specify the scan-rate applicable to this connection/group.

      Once done, click the OK button to save those changes.

      You have now setup a common connection to an OPC Server.

      If you have more OPC Servers, or wish to define other connections to the same OPC Server, then simply add more in this screen following the same instructions as above.

    Step 4 - Configuring an Instrument to use the consolidated connection

      Now that the common connection to an OPC Server is defined, it is time to tell the instrument controls to use a common connection.

      Open the properties of an instrument control:

      In this screen, you will need to click the "Add" button to select an Instrument property you wish to bind the Tag to. Typically this is the "position" or "value" property.

      Once you have specified the property, the next step is to specify the "Group" -- a.k.a. the COMMON connection to the OPC Server. When using this option, the remaining options for the computer/server are grayed-out, this is intentional as they are already specified in the iOPCManagerX component.

      Simply specify the "Item" (otherwise known as the OPC Tag) and then click the OK button to save and close the dialog.

      Repeat this step on other instruments to setup Tag relationships with the instruments which will all share the same OPC Connection.

Controlling the OPC Connection

    Adding, Removing and Clearing connections

      You can programmatically add and remove OPC Connections from the iOPCManagerX component by using the ".Add" and ".Remove" buttons. You can also clear all the groups from the manager by calling the ".Clear" method.

      These abilities could be used to create applications that are able to configure themselves at runtime by loading their configuration from an external file for example.

    Enabling & Disabling data for a group

      There is a way in which you can activate and deactivate a group within the iOPCManagerX component.

      Activating a group allows that group to run within the OPC Servers' address-space, and also allows the instrument to receive update notifications as to when Tags within that group change value.

      Deactivating a group disables the group within the OPC Serves' address-space but does not delete it. This is a good way to "temporarily" suspend the use of those Tags within the Server without having to disconnect from those Tags altogether. While a Tag is disabled, simply changing its enabled-status will resume/pause the groups ability to send the instruments update notifications.

      Each Group object (within the iOPCManagerX component) has 2 methods:

      • Suspend
      • Resume

      These methods can be called at any time.

    Handling Group Events

      There are 2 events that a group will fire when new OPC Data is received from the OPC Server.

      • OnBeforeGroupUpdate
      • OnAfterGroupUpdate

      Both events pass a string argument containing the name of the group whose values have changed.

      These events can allow you to do some processing before the updated OPC values reach the instruments and/or after the updated OPC values have reached the instruments.

Controlling the OPC abilities of the Instruments themselves

    Whereas you have the ability to manually bind OPC Tags to properties of the Instrument components from within the controls Property Pages, these same actions can be made programmatically too!

    If you wish to create an application that configures itself at runtime via an external configuration file, or based on some end-user action, then the following methods may be of interest to you:

    Method

    Description

    SetOPCItemAutoConnect

    This Method allows you to specify if the Tag will automatically connect to the OPC Server at startup, subscribe to the Tag and start updating the control automatically when those values change.

    SetOPCItemComputerName

    This Method allows you to specify the computer where the OPC Server resides.

    Do not use this method if you are using the iOPCManagerX component to consolidate your OPC Server connection.

    SetOPCItemData

    This method allows you to write a value to the Tag in the OPC Server.

    SetOPCItemGroupName

    This method allows you to specify the name of a group that you have previously defined for connecting to an OPC Server.

    SetOPCItemItemName

    This method allows you to set or change the name of the Tag that is bound to a property for an instrument.

    SetOPCItemPropertyName

    This method allows you to specify a property within the Instrument which you can then use to bind a Tag to.

    SetOPCItemServerName

    This method allows you to change the name of the OPC Server to connect to.

    SetOPCItemUpdateRate

    This method allows you to change the update rate (or "scan-rate") of a Tag.

    The methods shown above have corresponding "Get" method names to, e.g. "SetOPCItemAutoConnect" also has the inverse "GetOPCItemAutoConnect" too. The "Get...." versions allow you to read the values of these properties instead of writing to them.

Summary

    In this document we have explained how the OPC Connectivity works between the instrumentation controls themselves and an OPC Server.

    We have also explained why you should consolidate your OPC Communications through the iOPCManagerX component.

    We have also explained some of the features available to the instrumentation components that can allow you to programmatically make/break OPC Connections, read/write tag data and respond to events.

Copyright Software Toolbox, Inc., 1996-2004, 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
Email:
tools@softwaretoolbox.com