Data exchange via the PLC process image

Data is typically exchanged from the PLC process image with the IO process image. In the same way it is also possible to exchange data within a PLC between two task contexts.

A basic condition for the applicability of this method is that only one task should write to the same data. The data is then declared so that it is part of the output process image of this task.

Example

  • “DataA” is to be read from task context 1 and written from task context 2.
  • In addition, “DataB” is to be read and written from task context 2 and accessed from task context 1.
  • Implementation:
    • You define “DataA” for task context 1 in the output process image and also for task context 2 in the input process image there.
    • Accordingly, you define “DataB” for task context 2 in the output process image and also for task context 1 in the input process image there.
    • You can declare “DataA” and “DataB” directly where they are used, instead of declaring them globally.
    • In the process image display below the PLC instance in TwinCAT XAE, you link “DataA” with each other and “DataB” with each other.

 

Only the data that is required in the other task context may be added to the output process image, in order to avoid the process image becoming unnecessarily large. The asynchronous mapping performs copy actions in each cycle to exchange the data between the PLC process images and the additional temporary buffer. Because copying actions with large data blocks require a lot of computing time - as is also the case when calling a MEMCPY function - this usually limits the possible data volume to significantly less than 1 MB. The mapping is executed by the respective task itself, so that correspondingly complex mapping reduces the task runtime for the actual program processing.

A second condition for the applicability of this method is that the data must not be function block instances or pointers of any kind (POINTER TO, interface pointers/interface variables, references, ...). It is therefore not possible to call methods from one and the same function block instance from two different task contexts.

If necessary, the required data can be combined into a structure.

Sample program: Synchronization by exchanging data via the PLC process image

The example shows the data exchange between a slow task and a fast task within a PLC instance.

As an example for any data blocks (no function block instances or pointers), an integer variable is transferred to the other task. It also shows how you can trigger a function in the other task context using a Boolean variable.

Download:TC3_PlcSample_MultiTaskSync_PlcProcessImage.zip