OPC Updater Client

This section explains how to implement a tag entry/exit protocol in OPC clients.

The following screenshot shows an OPC server tag value, containing two Ubisense tag IDs, which has been set automatically with the form used in the OPCExample client. Note that this server browser shows the tag values as decimal numbers rather than the hexadecimal formats that most Ubisense programs use.

OPC Server Interface Code

There are two clients:

  • A client for updating this tag value with entry/exit protocol information.
  • A client for reading the value back from the server.

The clients require an OPC server to connect to, with an appropriate OPC item for storing Ubisense tag IDs.

The following code example shows how to interface the entry/exit protocol with an OPC server, using the OPC Foundation’s Classic .NET API Redistributables. The clients use this code to connect to OPC server and provide read/write values.

OPC Example Client Code

The following screenshot shows the OPCExample client running. The client listens for entry/exit protocol connections and updates the value of the OPC server item with all Ubisense tag IDs currently matching a recipe.

The following code shows how to use the above OPC Server Interface Code to update an item, gracefully handling new sessions and broken connections from the reader. This code is used in conjunction with the entry/exit protocol, through the event handlers, in the main program.

In the main program, the above client code (Part 1) is used in conjunction with the entry/exit protocol, to:

  • Create a connection to an OPC server for a specific item using the client code (Part 1).
  • Create a protocol object and add event handlers which use this server connection.
  • Use the protocol object to create an entry/exit protocol server, and then run the server.

OPCReader Client Code

The OPCReader client subscribes to the OPC server tag and outputs its value to the console whenever it is updated. The following screenshot shows the output returned by the OPCReader Client.

The following example shows how this program uses the OPC Interface Server code to read an OPC item containing the tag IDs.