Skip to main content

Data consistency in combination with the CODESYS Communication Manager

Important

The information on this page applies exclusively to objects, data, and methods which have been published via the CODESYS Communication Manager editors (IEC symbol sets, OPC UA Information Models, and the symbol configuration), and not to the OPC UA Server in general.

The OPC UA Server is a service which runs in the background of the PLC. The tasks of the OPC UA Server have a lower priority than the tasks of the IEC applications. Due to multitasking and multicore systems, the tasks of the OPC UA Server may be interrupted by other tasks. It can also occur that IEC tasks run in parallel with the tasks of the OPC UA Server, which can lead to data inconsistencies when reading or editing data. This chapter is intended to provide an overview of where consistency can be guaranteed and where it cannot.

Data access (read, write, and sample)

Data which is guaranteed to be consistent

All scalar data types up to a size of 8 bytes are consistently read from and written from the IEC data.

Data which is not guaranteed to be consistent

Strings

Strings are read and written character by character. Therefore, the consistency of a read or written string cannot be guaranteed.

Arrays

Reading or writing arrays are handled element by element. The basic read or write logic of the base data type of the array is used. If the base element can be processed consistently, then all array elements will also be consistent. However, it cannot be guaranteed that already processed array elements have not changed during the processing of the complete array.

Structured Data Types (STRUCT and FB)

Reading or writing the members of a structure or of a functional block is done element by element. This uses the basic read and write logic of the base data type of the member. If the base element can be processed consistently, then the member will also be consistent. However, it cannot be guaranteed that already processed members have not changed while processing the complete structure of function block.

Combinations

If arrays and structures are combined, then the above rules apply to the struct member or array element. The read and write logic of the base data type of the array elements or struct members is used. This results in the following general behavior:

  1. Values of simple data types (except STRING) and WSTRING) will always be consistent, regardless of where they are placed.

  2. STRING and WSTRING are not guaranteed to be consistent.

  3. Structures and arrays are not guaranteed to be consistent. However, the single values inside are consistent if they are of a simple data type.

Method calls

Input and output parameters (regardless of data type, arrays, or structures) are consistently transferred from the OPC UA Server to the method call or from the outputs of the method call back to the OPC UA Server. This is guaranteed by using the stack memory of the thread which executes the method call. However, the data access from the methods code into the IEC application is not guaranteed to be consistent. Because these methods run concurrently to the IEC applications tasks, normal mechanisms to synchronize access to data can be used (e.g. mutex, semaphore, or double buffer).