Attribute ‘call_after_init’

Hint

VAR_INPUT declarations in functions or methods that use the attribute lead to compile errors. Reason: Input variables are unknown in this case at the time of the call, which occurs implicitly during the online change.

The effect of this pragma is that a method is called implicitly after the initialization of a function block instance. For reasons of performance you must add the attribute both to the function block and to the method in its own first line above the declaration part.

Syntax:

{attribute 'call_after_init'}

Call: First line above the declaration part of the method and the function block.

CODESYS calls the method after the method FB_init and after the variable values of an initialization expression in the instance declaration have become valid.

This functionality is supported from compiler version 3.4.1.0.

Example

Definition:

{attribute 'call_after_init'}
FUNCTION_BLOCK FB
... <function block definition>

{attribute 'call_after_init'}
METHOD FB_AfterInit
... <method definition>

The definition implements, for example, the following declaration in the subsequent code processing:

inst : FB := (in1 := 99);

Code processing:

inst.FB_Init();
inst.in1 := 99;
inst.FB_AfterInit();

This allows a reaction to the user-defined initialization in FB_AfterInit.

See also