Attribute ‘global_init_slot’ΒΆ

This pragma defines the initialization order of function blocks or global variable lists.

Variables in a list (GVL or POU) are initialized from top to bottom.

If there are several global variable lists, then the initialization order is not defined.

The initialization does not apply for the initialization of literal values, for example 1, 'hello', 3.6, or constants of base data types. However, you must define the initialization order yourself if there are dependencies between the lists. You can assign a defined initialization slot to a GVL or POU with the ‘global_init_slot’ attribute.

Syntax:

{attribute 'global_init_slot' := '<slot>'}

<slot>: Integer value that defines the position in the call order. The default value for a POU (program, function block) is 50000. The default value for a GVL is 49990. A lower value means an earlier initialization. Caution: If several blocks or GVLs receive the same value for the 'global_init_slot' attribute, then the initialization order remains undefined.

Insert location: The pragma always affects the entire GVL or POU and therefore it must be located above the VAR_GLOBAL or POU declaration.

Example

The program includes two global variable lists GVL_1 and GVL_2, as well as a PLC_PRG program that uses variables from both lists. GVL_1 uses the variable B for initializing a variable A, which is initialized in GVL_2 with a value of 1000.

GVL_1:

VAR_GLOBAL   //49990
 A : INT := GVL_2.B*100;
END_VAR

GVL_2:

VAR_GLOBAL   //49990
    B : INT := 1000;
 C : INT := 10;
END_VAR

PLC_PRG

PROGRAM PLC_PRG  //50000
VAR
    ivar: INT := GVL_1.A;
    ivar2: INT;
END_VAR

ivar:=ivar+1;
ivar2:=GVL_2.C;

In this case, the compiler prints an error because GVL_2.B is used for initializing GVL_1.A before GVL_2 has been initialized. You can prevent this by using the global_init_slot attribute to position GVL_2 before GVL_1 in the initialization sequence.

In this example, GVL_1 must have at least a slot value of 49989 in order to achieve the earliest initialization within the program. Every lower value has the same effect:

GVL_2

{attribute 'global_init_slot' := '100'}
VAR_GLOBAL
  B : INT := 1000;
END_VAR

Note: Using GVL_2.C in the implementation part of PLC_PRG is also not critical even without using a pragma because both GVLs are initialized before the program in either case.