Configure an OPC .NET Client connection to an OPC .NET server

The OPC .NET Client task/worksheet is to communicate with any system that implements the OPC .NET Server protocol.

About OPC .NET

The OPC .NET Client task/worksheet uses the new OPC .NET communication protocol introduced by the OPC Foundation. According to the foundation:

OPC .NET 3.0 (WCF) (formerly known as OPC Express Interface (Xi)) is the continued evolution of OPC Foundation native support for Microsoft platforms that previously included: the OPC Foundation Automation Wrapper for Visual Basic 6 and the OPC .NET 2.0 API for VB.NET and C#. It bridges the gap between Microsoft.NET and the world of OPC Classic.

In other words, OPC .NET is intended to be a new version of OPC that leverages Microsoft’s latest technologies. For more information, go to the OPC Foundation website.

Configuring a new OPC .NET server connection

To configure a new connection to an OPC .NET server:
  1. Do one of the following:
    • On the Insert tab of the ribbon, in the Communication group, click OPC Client and then select OPC .NET Connection from the drop-down list; or
    • In the Comm tab of the Project Explorer, right-click OPC .NET Connections and then click Insert on the shortcut menu.
    The OPC Server Connection dialog is displayed:
    Figure 1. OPC Server Connection dialog
    Web Studio Help dialog opcxi serverconnection OPC .NET Client

  2. In the Connection Name box, type a name for the connection.

    This name will be displayed in the OPC .NET Connections folder in the Project Explorer, and it is the name you will look for when you configure the OPC .NET Client worksheet.

  3. In the Discovery Server list, type or select the URL of the discovery server that publishes a list of OPC .NET servers on the network. If no discovery server appears to be available, click Refresh to scan the network again.
    Note: This feature requires that the Peer Name Resolution Protocol service be running on both the client station and and the discovery server. PNRP has been built into Microsoft Windows since Windows XP Service Pack 2, so this shouldn’t be a problem in most situations.
  4. In the Server list, type or select the URL of the OPC .NET server to which you want to connect. If the server you want doesn’t appear to be available, click Refresh the update the list from the discovery server.
  5. In the Protocol list, select the network protocol to be used to connect to the server. (For more information about the available protocols, please refer to Microsoft’s documentation for Windows Communication Foundation.)
    Note: If your OPC .NET configuration has different servers/endpoints for each operation, then do the following:
    1. In the Protocol list, select custom. The Custom button becomes enabled.
    2. Click the Custom button. The Endpoints dialog is displayed.
      Web Studio Help dialog opcxi serverconnection endpoints OPC .NET Client

    3. Use the dialog to specify the server/endpoint for each operation.
  6. In the User Name and Password boxes, type your login credentials for the OPC .NET server.
    Note: If the OPC .NET server is using Microsoft Active Directory, then User Name must be in the domainusername format.
  7. Select Callback to have the server send values to the client only when the values change, or select Polling to have the client periodically request values from the server.

    In most cases, you should select Polling to keep the connection active.

  8. Click OK. The connection is saved in the OPC .NET Connections folder in the Project Explorer.

Configuring a new OPC .NET Client worksheet

To configure a new OPC .NET Client worksheet:
  1. Do one of the following:
    • On the Insert tab of the ribbon, in the Communication group, click OPC Client and then select OPC .NET Client from the drop-down list; or
    • In the Comm tab of the Project Explorer, right-click OPC .NET and then click Insert on the shortcut menu.
    A new OPC .NET Client worksheet is displayed:
    Figure 2. OPC .NET Client worksheet
    Web Studio Help worksheet comm opcxi OPC .NET Client

  2. In the Description box, type a description of the worksheet. This is for documentation purposes only and does not affect the execution of the worksheet.
  3. In the Connection list, select the OPC Server connection that you configured earlier.
  4. For more connection options, click Advanced.
    The Advanced dialog is displayed:
    Web Studio Help dialog opcxi advanced OPC .NET Client

    Review the options and configure as needed:
    Area / Element Description
    Read actions Enable subscription When this value is TRUE (non-zero), the client will subscribe to the server nodes so that it can receive notifications when the node values change.
    Note: This is enabled by default. If it is disabled, then you must use a read trigger (see below).
    Maximum group size The maximum number of server nodes that may be read in a single read operation.

    For example, if you have 1000 items/rows configured in the worksheet and Maximum group size is set to 100, 10 read operations will be performed when a read is triggered.

    Synchronous read trigger When the value of this tag/expression changes, the client reads all of the node values from the server. The read is performed synchronously, which means all other client operations are blocked until the read is finished. When the read is finished, the client increments the tag configured in Read count.
    Asynchronous read trigger N/A for OPC .NET Client.
    Read count The name of a tag (Integer type) that will receive a count of the number of read operations performed since the project was run.
    Status The name of a tag (Integer type) that will receive a status code for the last read operation performed by a trigger.
    Status message The name of a tag (String type) that will receive the corresponding status message.
    Maximum aging N/A for OPC .NET Client.
    Sampling rate N/A for OPC .NET Client.
    Write actions Enable write on tag change When this value is TRUE (non-zero), a write operation will be performed automatically whenever the value of a project tag changes. All tag changes that occured since the last scan of the worksheet will be written in a single write operation, or in multiple write operations if the number of tag changes exceeds the maximum group size.
    Note: This is enabled by default. If it is disabled, you must use write triggers (see below).
    Maximum group size The maximum number of tag changes that may be written in a single write operation.

    For example, if you have 1000 items/rows configured in the worksheet and Maximum group size is set to 100, then 10 write operations will be performed during each scan of the worksheet.

    Synchronous write trigger When the value of this tag/expression changes, the client writes all of the tag values to the server. The write operation is performed synchronously, which means all other client operations are blocked until the write operation is finished. When the write operation is finished, the client increments the tag configured in Write count.
    Asynchronous write trigger N/A for OPC .NET Client.
    Write count The name of a tag (Integer type) that will receive a count of the number of write operations performed since the project was run.
    Status The name of a tag (Integer type) that will receive a status code for the last write operation performed by a trigger.
    Status message The name of a tag (String type) that will receive the corresponding status message.
    Reload trigger The name of a tag (Boolean, Integer, or Real type) that can be used as a trigger. When the value of this tag changes, the worksheet is reloaded. Tags in curly brackets (e.g., {tagname}) configured in the body of the worksheet are refreshed only when the worksheet is reloaded. After the worksheet is reloaded, the value of this tag will be reset to 0.
    Refresh IDs on startup N/A for OPC .NET Client.
    Ensure cache synchronization When this option is selected, the client will wait after each write operation for confirmation from the server that the node values actually changed. If the client does not receive confirmation, it will restore the previous tag values.
    Enable bit notation When this option is selected, bit notation is allowed in the Item column of the worksheet body.
  5. Click OK to close the Advanced dialog and return to the worksheet.
  6. In the Status box, type the name of a tag (Integer type) that will receive connection status codes during project runtime.
  7. In the Status Message box, type the name of a tag (String type) that will receive the corresponding status messages.
  8. In the Publish Rate box, type the frequency (in milliseconds) at which the client will request updates from the server.
  9. In the Disable box, type a tag/expression. When the value is TRUE (non-zero), the worksheet will not be executed.
  10. In the Root node or view box, specify the server node that will serve as the root for all items in the worksheet body. Specifying a root node makes it easier to find items and improves runtime performance.
  11. For each row of the worksheet body, specify the following:
    • Tag Name: The name of a project tag.

      You may use tags in curly brackets (e.g., {tagname}), but if you do, then be sure to configure the Reload trigger option above.

    • Item: The server item with which the project tag should be associated.

      To browse the server’s list of items, right-click in this field and then click Browse on the shortcut menu.

      Note: If Enable bit notation is selected in the advanced settings, you can select a specific bit of a server node value by appending the bit number to the item name (e.g., nodepath.bit). Please note that this is supported only for unsigned variables and 32-bit signed variables; if you try to do it with 16-bit or 8-bit signed variables, the most significant bit (MSB) will not work properly.
    • Scan: If Always, then the row is continuously scanned during runtime. If Screen, then the row is scanned only when a project screen that uses the specified tag is open.
    • Div: For scaling — the value is divided by this number when reading from the server, and it is multiplied by this number when writing to the server.
    • Add: For scaling — this number is added to the value when reading from the server, and it is subtracted from the value when writing to the server.
    • Instance ID: The instance ID is automatically generated from the full path of the server item.
  12. Save and close the worksheet.

Enabling the OPC .NET Client task

To enable the OPC .NET Client task for runtime:
  1. On the Home tab of the ribbon, in either the Local Management or Remote Management group (depending on where the project server will be), click Tasks.

    The Execution Tasks dialog is displayed.

  2. In the list of tasks, select OPC .NET Client.
  3. Click Startup.

    The Startup dialog is displayed.

  4. Select Automatic, and then click OK.
  5. Click OK again to close the Execution Tasks dialog.

OPC .NET Client