Configuring an OPC Client connection to an OPC Server

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

This task implements the OPC standard as described in the OLE for Process Control Data Access Standard Version 1.0A document, which is available at the OPC Foundation web site.

Note: Before using the OPC Client task/worksheet in your project, you must make sure the OPC server software is properly installed and configured on the system to which you want to connect.

To configure a new connection, insert a new OPC Client worksheet on the Comm tab of the Project Explorer.

Figure 1. Sample OPC Client worksheet
Web Studio Help worksheet comm opc OPC DA 2.05

Use the following parameters in the configuration table for OPC:
  • Description text box: Type a description of the OPC task for documentation purposes only. (The OPC Client task ignores this information.)
  • Server Identifier: Type the name of the server you want to connect. If the server is already installed on the computer, you can select the server name from the list.
  • Disable: Type a tag or a constant with a value other than 0, to disable communication with the OPC server. Specify 0, or leave the field blank to enable communication.
  • Read Update Rate: Specify how often the server should update this group (in milliseconds). Specify 0 to indicate the server should use the fastest practical rate.
  • Percent Deadband (valid for analog items only): Specify how much percent change in an item value should cause a notification by the server.
  • Status: Type the name of a tag to receive the status of the connection. Good status is 1.
  • Remote Server Name: Node name or IP address of server on node network.
  • Read before writing checkbox: Check this option to force your project to read the original values of items on the OPC server just before writing new values to the server. The project does this by first buffering the new values to be written and then reading the original values from the server. Only after the project is synchronized with the server are the new values written from the buffer to the server.
  • Read after writing checkbox: Check this option to force your project to read back the new values of items on the OPC server just after the project has written those values.
    CAUTION:
    The Read before writing and Read after writing options are offered because the OPC Client/Server specification says that the value of an item on the client — in this case, your project — should not change unless the server sends the change. That way, the client always stays in sync with the server.
    Your project, however, may be designed to change those values according to runtime processes or user input. Therefore, the best way to change the values while staying in sync with the server is to make it seem like the changes originate on the server. With both options enabled, the following sequence of events happens on every scan of the OPC worksheet:
    1. The new values on the client are buffered.
    2. The original values on the server are read to the client — that is, the client is synchronized with the server.
    3. The new values are written from the buffer to the server.
    4. The new values on the server are read to the client — that is, the client is again synchronized with the server.

    At the end of each scan, the values reflect what’s happening in your project even though, technically speaking, the project is merely staying in sync with the server.

    Both options should be enabled in most projects. In some projects, however, this may cause items to bounce between the original values and the new values. If this is a problem, try moving those items to another OPC worksheet where the Read before writing and Read after writing options are disabled.

  • Accept Tag Name in the Item column checkbox: When this option is checked, the text configured between curly brackets in the Item field is resolved as a Tag Name (string tag). In this case, the value of this tag is used as the name of the item from the OPC Server, allowing the user to point to different item names during runtime, by changing the value of the tag(s) configured in the OPC Client worksheet (Item column).

    When the Accept Tag Name in the Item column option is unchecked, all characters configured in the Item column are considered part of the Item name (including the curly brackets).

  • Tag Name: Type the names of tags linked to the server items.
  • Item: Enter the name of the server’s items. After selecting an OPC Server, you can select items from the Server using the OPC Browser. Right-click in the Item field and select the OPC Browser option.
    Tip: You can configure a tag name between curly brackets (e.g., {TagName} ) in this field, allowing the user to change the item names dynamically, during runtime.
  • Scan field: Specify the condition under which the tag value is read from the remote device or server and then updated in the project database, using one of the following options:
    • Always means the tag is read and updated during every scan of the communication worksheet, regardless of whether the tag is used in any other project screens, scripts, or worksheets.

      This option is recommended for tags that must be continuously monitored in the background, such as tags that trigger alarms, tags used in recipes, tags that are recorded in the historical database, and so on.

    • Screen means the tag is read and updated only if it is being used in at least one open project screen, either locally or on another client station.

      This option is recommended for tags that are used in screen objects, because the project may not need to update tags that are not being visualized anywhere. Selecting this option can improve project performance.

    • Auto means the project will automatically choose either Always or Screen, depending on where the tag is used in your project. If the tag is only used in a screen object on a project screen, then the scan will default to Screen. But if the tag is configured in any other interface (e.g., Script, Math, Alarm, Trend, Recipe, Report, Scheduler), then the scan will switch to Always and remain there until the project is stopped.

    If you are not sure of which option to select, select Always. This will guarantee the tag is read and updated.

  • Div field: Specify the division constant when scale adjustment is required. This value is a division factor in a read operation and a multiplication factor in a write operation.
  • Add field: Specify the addition constant when scale adjustment is required. This value is a addition factor in a read operation and a subtraction factor in a write operation.
Note: The OPC DA specification supports custom item qualities using the high byte of the two-byte quality field. However, such qualities are often vendor-specific or even hand-coded, so it is not possible for InduSoft Web Studio to interpret them. All item qualities other than GOOD (192) will be ignored.

To run the OPC Client runtime task, you can choose to run it automatically on start up, or run the task manually by clicking Tasks (either local or remote) on the Home tab of the ribbon. After running this program, a small icon displays in your system tray.

To close the OPC Client runtime task, right-click the icon in the system tray, and click Exit.

InduSoft Web Studio, EmbeddedView, and CEView also provide an OPC Server communication task named Studio.Scada.OPC. This task starts automatically when any OPC Client (local or remote) attempts to connect to the Studio.Scada.OPC server. An OPC Client can exchange data with the tags database (Project Tags, System Tags, and Shared tags) using the OPC interface.

In addition, you can start the OPC Server task automatically when you run the project. Select the OPC Server task in the Execution Tasks dialog (Tasks on the Home tab of the ribbon), click the Startup button, and specify Automatic.

Tip: You can also use the OPC interface to exchange data between remote stations running InduSoft Web Studio, EmbeddedView, or CEView. You must configure the OPC Client in one station and you must execute the OPC Server in the other station.

Reading Array Items on the Server

The OPC Client runtime task is capable of reading array items on the specified OPC server. However, it cannot read only certain elements of an array item; the entire item is read during every scan. Also, the way in which the values of the individual array elements are written to project tags in IWS depends on what tag you configure.

Scenario 1: The project tag is an array (i.e., the tag’s Array property is greater than 0)

In this scenario, each element of the array item on the server is written one-for-one to an element of the project tag. If you specify an array index (e.g., MyArrayTag[3]), then writing will begin with that element. If you do not specify an array index, then writing will begin with element 0 by default.

You must make the Array property of the project tag large enough to accomodate the elements of the array item on the server. If it is not large enough, then elements will be lost.

Scenario 2: The project tag is not an array, but the tag name ends with a number

In this scenario, you can specify the first of a series of sequentially numbered project tags, and the values of the array elements are written to those tags.

Table 1. Examples of sequentially numbered project tags
When Tag Name is configured as… …the values of the array element are written to the following tags:
MyTag1 MyTag1, MyTag2, MyTag3
MyTag3 MyTag3, MyTag4, MyTag5
MyTag001 MyTag001, MyTag002, MyTag003

You must actually create enough project tags to accomodate the elements of the array item on the server. If there are not enough tags, then elements will be lost. Project tags cannot be created during runtime.

Scenario 3: The project tag is a class, and the class member ends with a number

This scenario is similar to Scenario 2 above — you can specify the first of a series of sequentially numbered class members, and the values of the array elements are written to those members.

Table 2. Examples of sequentially numbered class members
When Tag Name is configured as… …the values of the array element are written to the following members:
MyClass.Member1 MyClass.Member1, MyClass.Member2, MyClass.Member3
MyClass.Member3 MyClass.Member3, MyClass.Member4, MyClass.Member5
MyClass.Member001 MyClass.Member001, MyClass.Member002, MyClass.Member003

You must actually create the class with enough members to accomodate the elements of the array item on the server. If there are not enough members, then elements will be lost. Class members cannot be created during runtime.

Scenario 4: The project tag is both a class and an array

If the class member ends with a number, then it is handled the same as in Scenario 3 above, regardless of the fact that the tag is also an array.

If the class member does not end with a number, then it is handled the same as in Scenario 1 above.

Table 3. Examples of tags that are both classes and arrays
When Tag Name is configured as… …the values of the array element are written to the following members:
MyArrayClass.Member MyArrayClass[0].Member, MyArrayClass[1].Member, MyArrayClass[2].Member
MyArrayClass[3].Member MyArrayClass[3].Member, MyArrayClass[4].Member, MyArrayClass[5].Member
MyArrayClass[3].Member1 MyArrayClass[3].Member1, MyArrayClass[3].Member2, MyArrayClass[3].Member3
MyArrayClass[3].Member3 MyArrayClass[3].Member3, MyArrayClass[3].Member4, MyArrayClass[3].Member5
MyArrayClass[3].Member001 MyArrayClass[3].Member001, MyArrayClass[3].Member002, MyArrayClass[3].Member003
Note: This functionality is not supported in projects running on Windows Mobile or Windows Embedded Compact.

OPC Troubleshooting

When you are using OPC and have problems establishing communication, you should first verify the messages in the LogWin.

If you are running the project on a Windows Embedded target system, there are two ways to check the log:
  1. Remote LogWin
  2. Local Log

For information about using these logs, please refer to Using the LogWin task.

If you find error messages in the log, look them up in this manual/help system, and follow the documented steps for solving the problems. (Use <CTRL> + F to find them in the manual; use the Index to find them in the context sensitive help system.)

If you feel that you need to contact your distributor for technical support, make sure that you provide them with the following information:
  1. Log file
  2. Software vendor and product name of the OPC Server/Client that you are using
  3. If possible, a copy or an evaluation version of the OPC Server for testing purposes
  4. The contact information for your OPC Server/Client technical support

Three possible errors and their resolutions are listed below…

Security

Error Code: 0×80070005 or -2147024891

Reason for error: When the OPC Client tries to connect to the OPC Server, the DCOM layer usually requires authentication. The computer that is running the OPC Server needs to recognize the user logged on to the OPC Client computer, and such a user needs to have privileges to access the OPC Server.

Solution: The first step is to create a single user on both computers that has Administrator privileges and the same password. Log on with this user to both ends, and then try to establish the connection.

Name Resolution

Error: Couldn’t create connection with advise sink, error: -2147022986 (0×80070776)

Reason for error: There is a problem resolving the computer name.

Solution: This problem can be solved by specifying the IP address of the server instead of specifying the computer name.

Proxy for Windows CE

Error: OPCServer: IIndCP::Advise – Could not query callback interface: 0×80040155

Reason for error: Your Windows Embedded device is missing the OPCCOMN_PS.dll.

Solution: You should download the .dll to the device and register it. The .dll should be available with your IWS distribution, most probably in […]InduSoft Web Studio v7.1RedistWince x.xprocessor

If you do not find the .dll in the folder for your processor, contact your IWS distributor.

OPC DA 2.05