The check detects function block instances which are declared as temporary variables. This affects instances which are declared in a method or function or as VAR_TEMP
, and therefore are reinitialized in each processing cycle or for each POU call.
Justification: Function blocks have a state that is usually maintained over multiple PLC cycles. An instance on the stack exists only for the duration of the function call. Therefore, it rarely makes sense to create an instance as a temporary variable. Secondly, function block instances are often large and need a lot of space on the stack (which is usually restricted to controllers). Thirdly, the initialization and often also the scheduling of a function block can take a long time.
Importance: Medium
Examples
PROGRAM PLC_PRG
VAR
END_VAR
VAR_TEMP
yafb: AFB;
END_VAR
FUNCTION Fun : INT
VAR_INPUT
END_VAR
VAR
funafb: AFB;
END_VAR
METHOD METH : INT
VAR_INPUT
END_VAR
VAR
methafb: AFB; // SA0167
END_VAR
--> SA0167: Temporäre Funktionsbausteininstanz: 'methafb'