Attribute 'TcContextId'

Via the pragma, you can define which task should update an allocated variable.

Syntax: {attribute 'TcContextId' := '<TaskId>'}

The placeholder <TaskId> in inverted commas must be replaced by the task ID. The task IDs can be read in the Result table. The table is shown in the Context tab, which can be opened by double-clicking on the PLC process image (<Project name> instance).

Insertion location:

Sample 1:

Assumption: The task PlcTaskA has the ID 0, the task PlcTaskB has the ID 1.

The pragma is inserted in the line above the respective variable declaration. It therefore only affects the following declaration line.
The variable bVar1 is updated by the task PlcTaskA, the variable bVar2 is update by the task PlcTaskB.

VAR_GLOBAL
    {attribute 'TcContextId':='0'}
    bVar1  AT%Q* : BOOL;
    {attribute 'TcContextId':='1'}
    bVar2  AT%Q* : BOOL;
END_VAR

Sample 2:

Assumption: The task PlcTaskA has the ID 0, the task PlcTaskB has the ID 1.

The pragma is inserted in the GVL in the line above VAR_GLOBAL and in the line above a variable declaration.
Because the attribute is applied above its declaration line, the variable bVar3 is updated by the task PlcTaskB. Due to use above the first VAR_GLOBAL, all other variables (all up to bVar3) are updated by the task PlcTaskA.

{attribute 'TcContextId':='0'}
VAR_GLOBAL
    bVar1  AT%Q* : BOOL;     // => PlcTaskA
    bVar2  AT%Q* : BOOL;     // => PlcTaskA
 
    {attribute 'TcContextId':='1'}
    bVar3   AT%Q* : BOOL;    // => PlcTaskB
 
    bVar4  AT%Q* : BOOL;     // => PlcTaskA
END_VAR

Sample 3:

Assumption: The task PlcTaskA has the ID 0, the task PlcTaskB has the ID 1.

The pragma is inserted in the GVL in the line above the first VAR_GLOBAL as well as in the line above the second VAR_GLOBAL.
Please note that the purpose of this usage is not to have the variables bVar4-bVar6 updated by the task PlcTaskB.

Background: The insertion of the pragma above VAR_GLOBAL is only productive above the first VAR_GLOBAL in a GVL.

The sample illustrated leads to the following assignment: The pragma above the second VAR_GLOBAL is interpreted by the variable bVar4 as a pragma above the declaration line, therefore the variable bVar4 is updated by the task PlcTaskB. Due to use above the first VAR_GLOBAL, all other variables (all up to bVar4) are updated by the task PlcTaskA.

In order to apply the attribute to a whole group of variables (e.g. bVar4-bVar6), it is recommended to use a dedicated GVL for each group of variables.

{attribute 'TcContextId':='0'}
VAR_GLOBAL
bVar1 AT%Q* : BOOL; // => PlcTaskA
bVar2 AT%Q* : BOOL; // => PlcTaskA
bVar3 AT%Q* : BOOL; // => PlcTaskA
END_VAR
{attribute 'TcContextId':='1'}
VAR_GLOBAL
bVar4 AT%Q* : BOOL; // => PlcTaskB
bVar5 AT%Q* : BOOL; // => PlcTaskA
bVar6 AT%Q* : BOOL; // => PlcTaskA
END_VAR