Reputation: 2132
I have a function block A
that has one variable output
(defined in the FUNCTION_BLOCK A
method) and this FB_init
method:
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
END_VAR
VAR_OUTPUT
output : REAL := 0;
END_VAR
THIS^.output := output;
When I call this constructor as follows:
a : A(output => outputLocal);
Identifier 'output' not defined
. But I did defined
this parameter in the constructor method.No matching FB_init method found for instantiation of A
localoutput
to the variable output
(of the FB A
) in the FB constructor.Upvotes: 0
Views: 1464
Reputation: 26
By declaring output in the VAR_OUTPUT
section of the method, you are making it a local output variable to the method, not an input variable.
You need to declare a VAR_OUTPUT
in the FunctionBlock
and a VAR_INPUT
in the constructor and assign the input variable from the constructor to the output variable of the FunctionBlock
—probably by REF=
, or you'll just get the value.
Upvotes: 1
Reputation: 1540
Even though you technically can have output parameters in the FB_Init
-method, you can't get them out from the call of FB_Init. My guess is that it has to do with how the object is being constructed in time, and therefore it makes no sense.
The more important questions is: What are you trying to achieve? In the above example it seems you are trying to access the parameter output, which I assume is an output of the entire function block, from the FB_Init-call? You seem to be writing to an output of the function block, from an output of an method call, which doesn't make any sense.
If you only want to pass a parameter as an output from a function block, why not provide it as an input-parameter in that case? (either by copy or by reference)?
Upvotes: 0