Using the 'no_init' attribute will fix the compile error; however, (IMHO) this may not be the best solution. First, because you'll probably want to initialize the values and secondly because calling FB_Init explicitly, is strongly discouraged. Therefore I would like to explain why the error message occurs as well as giving some insight in how to solve the error.
The error is (AFAIK) due to either one of the two reason listed below.
- When you declare and initialize a
POU
(e.g. an FB
between the VAR
and END_VAR
keywords) and you directly initialize a value to one of it's inputs while this input is not included as VAR_INPUT
of the FB_Init
of the POU
.
I'll clarify this with some code:
VAR
myFunctionBlock: FB_FunctionBlock(myInput:= 1);
END_VAR
.. Above we're initializing input "myInput" of object/instance "myFunctionBlock" with the value 1 and this requires that "myInput" is included in the FB_Init of POU "FB_FunctionBlock":
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL;
bInCopyCode : BOOL;
myInput : INT; // Include the input or else you'll get the error
END_VAR
- In the
VAR_INPUT
-block of an FB_Init
you can include inputs of the POU
to which the FB_Init
belongs. When you do this your are required to initialize these inputs when you declare and initialize the POU
. (this is probably the case in your example)
Again I'll clarify this with some code:
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL;
bInCopyCode : BOOL;
myInput : INT;
END_VAR
.. Above input "myInput" is included in the FB_Init of POU "FB_FunctionBlock" and therefore when we create an object/instance of POU "FB_FunctionBlock" then we're required to initialize the input "myInput".
VAR
myFunctionBlock: FB_FunctionBlock(myInput:= 1);
// Include "myInput:= 1" or else you'll get the error
END_VAR