Attribute 'TcContextName'
Via the pragma, you can define which task should update an allocated variable.
Syntax: {attribute 'TcContextName' := '<TaskName>'}
The placeholder <TaskId> in inverted commas must be replaced by the task name.
Insertion location:
- Line above the first VAR_GLOBAL in a GVL
- Line above the declaration of a POU
- Line above the declaration line of the allocated variables
Sample 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 'TcContextName':='PlcTaskA'}
bVar1 AT%Q* : BOOL;
{attribute 'TcContextName':='PlcTaskB'}
bVar2 AT%Q* : BOOL;
END_VAR
Sample 2:
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 'TcContextName':='PlcTaskA'}
VAR_GLOBAL
bVar1 AT%Q* : BOOL; // => PlcTaskA
bVar2 AT%Q* : BOOL; // => PlcTaskA
{attribute 'TcContextName':='PlcTaskB'}
bVar3 AT%Q* : BOOL; // => PlcTaskB
bVar4 AT%Q* : BOOL; // => PlcTaskA
END_VAR
Sample 3:
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 'TcContextName':= 'PlcTaskA'}
VAR_GLOBAL
bVar1 AT%Q* : BOOL; // => PlcTaskA
bVar2 AT%Q* : BOOL; // => PlcTaskA
bVar3 AT%Q* : BOOL; // => PlcTaskA
END_VAR
{attribute 'TcContextName':='PlcTaskB'}
VAR_GLOBAL
bVar4 AT%Q* : BOOL; // => PlcTaskB
bVar5 AT%Q* : BOOL; // => PlcTaskA
bVar6 AT%Q* : BOOL; // => PlcTaskA
END_VAR