Attention
These docs are a bit ambitious. The steps described are accurate but IronPLC cannot yet run programs.
P0021¶
- Code
P0021
- Message
Function block invocation is not a variable in scope
This error occurs when a function block invocation references a variable that is not a function block instance in scope.
Example¶
The following code will generate error P0021:
FUNCTION_BLOCK Callee
END_FUNCTION_BLOCK
FUNCTION_BLOCK Caller
VAR
MyVar : INT; (* This is not a function block instance *)
END_VAR
END_FUNCTION_BLOCK
PROGRAM main
VAR
CallerInstance : Caller;
END_VAR
CallerInstance(MyVar); (* Error: MyVar is not a function block instance *)
END_PROGRAM
The function block invocation CallerInstance(MyVar)
tries to call MyVar
as a function block, but MyVar
is declared as an INT
variable, not a function block instance.
To fix this error, ensure the variable being invoked is a function block instance:
FUNCTION_BLOCK Callee
END_FUNCTION_BLOCK
FUNCTION_BLOCK Caller
VAR
CalleeInstance : Callee; (* This is a function block instance *)
END_VAR
END_FUNCTION_BLOCK
PROGRAM main
VAR
CallerInstance : Caller;
END_VAR
CallerInstance(CalleeInstance); (* Correct: CalleeInstance is a function block *)
END_PROGRAM