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
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
- 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
- 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.
- 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.
- 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.
- 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:
- In the Protocol list, select custom. The Custom button becomes enabled.
- Click the Custom button. The Endpoints dialog is displayed.
- Use the dialog to specify the server/endpoint for each operation.
- 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.
- 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.
- Click OK. The connection is saved in the OPC .NET Connections folder in the Project Explorer.
Configuring a new OPC .NET Client worksheet
- 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
- 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.
- In the Connection list, select the OPC Server connection that you configured earlier.
- For more connection options, click Advanced.
The Advanced dialog is displayed: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. - Click OK to close the Advanced dialog and return to the worksheet.
- In the Status box, type the name of a tag (Integer type) that will receive connection status codes during project runtime.
- In the Status Message box, type the name of a tag (String type) that will receive the corresponding status messages.
- In the Publish Rate box, type the frequency (in milliseconds) at which the client will request updates from the server.
- In the Disable box, type a tag/expression. When the value is TRUE (non-zero), the worksheet will not be executed.
- 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.
- 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.
- Tag Name: The name of a project tag.
- Save and close the worksheet.
Enabling the OPC .NET Client task
- 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.
- In the list of tasks, select OPC .NET Client.
- Click Startup.
The Startup dialog is displayed.
- Select Automatic, and then click OK.
- Click OK again to close the Execution Tasks dialog.