Communication by OPC interface

Basic principles for the OPC communication:

The OPC (OLE for Process Control) is the standardized specification of the interface for applications that are addressed to controlling and monitoring fast processes. This specification is defined and updated by the unprofitable organization OPC Foundation (see: The specification has the client-server architecture. The specification is now focused to the following areas:

- data sharing (OPC DataAccess)
- alarms and events sharing (OPC Alarm and Event Handling)
- historic trends sharing (OPC Historical Data Access), etc.

There is implemented the part of data sharing from the client point of view in the PROMOTIC system in the meantime. The OPC specification, version 1 and 2 is supported (higher OPC version was not available at the time of writing this documentation).

The principle of the data transfer over the OPC:

The OPC server is required. You can get the OPC server from companies that produce the software. Such company is often the producer of the PLC device. The OPC server is the OS Windows application that runs either as a stand-alone program or it can be for example a Dll library. The OPC server can, for example, communicate with the PLC device over the serial link and at the same time it can offer data (that are get from the PLC device) over the OPC interface to other OS Windows applications. In this case the PROMOTIC application is the other application.

In the PROMOTIC application that wants to get (set) the data from the PLC, it is necessary to create the PmOpcClient object. In this object the OPC server is selected (if the OPC is correctly installed then it appears in the menu). It is necessary to insert required number of PmOpcClientData objects into the PmOpcClient object. These objects represent groups of the data that we want to transfer. They must be configured correspondingly. You can enter there if the data group has to be read or written automatically. If you don't want to read-write data automatically, it can be solved in the script by the PmOpcClientData.Read-PmOpcClientData.Write method.

Further it is necessary to define, which data are needed to be transfered. There are two ways of doing this:
1) Data extension: A very convinient way of defining the data we want to communicate with is to use Data extension It is defined in data item of the PmData object and for OPC the ExtOpcClient is used.
2) Data definition direct in PmOpcClientData object: In the Data page can be defined data items, which are configured similarly as for example for the PmData object. But for each item it is necessary to set moreover two fields required for the OPC communication. The fields are the ItemID and AccesPath items. These two fields represent the address of the item on the OPC server. If the OPC server supports the OPC version 2, then the buttons (with 3 dots) for the selection of the fields should be functional at the enter points directly from the OPC server. If it is not true, then it is necessary to enter the data manually.

The access to the data items in the PmOpcClientData object is the same as in the PmData object, which means for example over the PmOpcClientData.Item property. This property accesses one data item as the Var object from which the standard data (especially the value of the data item by the Value property) can be found but the Var object has two more properties specific only for the OPC in the PmOpcClientData object. It goes about the Var.Quality property, by means of which it is possible to find out the validity of the received value, and the ExtOpcClient.TimeStamp property, by means of which it is possible to find out the timestamp of the last value.

OPC Basic terms:
CACHE: the auxiliary memory of the OPC server where the server stores data on an ongoing basis that are get from other data sources (e.g. from the PLC device, DEVICE - see further). If the OPC client needs to get data, they needn't to be get slowly from the PLC device but it can read them quickly from this memory on the OPC server.
DEVICE: the source of the data, from which the OPC server gets data. An access to these data is usually slower by an exponent than from the CACHE.
Asynchronous transfer: The way of the data transfer between the client and the server. The client sends a request (writing, reading) to the OPC server and it DOESN'T WAIT for the end of processing the request. The request is processed by the OPC server during the certain time and the result is sent to the client. The client can perform other operations between sending the request and the result. This way of the data transfer is suitable for prolonged operations, for example writing or reading data from the DEVICE.
Synchronous transfer: The way of the data transfer between the client and the server. The client sends a request (writing, reading) to the OPC server and it WAITS for the end of processing the request. This way of the data transfer is suitable for very fast operations, for example writing or reading from the CACHE if the OPC server is on the same computer as the client.
Instruction for simple check of the OPC communication:
1. Create an empty project (or use an existing one) and create the PmOpcClient object in it. Enter the OPC server which you want to connect to in the OPC server - CLSID/ProgID configurator (the server can be selected by the button on the right). If the required server is not offered, it means that this server isn't correctly installed on Your computer.
2. Create new PmOpcClientData subobject in the PmOpcClient object.
3. Check in the PmOpcClientData object that the Active after start and Update from server at server change configurators are ticked.
4. Create one variable on the page PmOpcClientData > Data: press the "New" button. The window for configuration of new variable opens. Set the required data type.
5. Fill in the required OPC address of the variable in the ItemID configurator. This configurator can be filled in by the button on the right - then the OPC server is started and it'll offer variables that can be transferred, to you by itself (only the OPC server with the interface OPCv2.0 and newers allow it - older OPC servers don't allow it).
6. Some types of addressing require entering another ItemID configurator except the AccessPath configurator (the same method from the previous step is valid for entering). But for most OPC servers you can leave this configurator empty.
7. Leave entering the variable and start the application (runtime).
8. For testing you needn't create any panels, everything can be found out in the INFO system. Open the INFO system, switch to the "PmRoot" item and there switch into the PmOpcClientData object that you've created. You can see the current value and the status of variables on the Vars page. You can see the statistic of the OPC transfer of this object on the Object page.
9. If the data transfer doesn't work, look in the Errors item of the INFO system.
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice