I have a FB with 2 REFERENCE TO FB as input parameters.
In the FB, i want to work with either the first or the second Reference depending on a variable (NumSupport)
But when I try to affect the RefSupport:=RefSupport1, I get an exception.
Does anyone know how to deal with this problem ? What is correct way to work ?
Thank you
FUNCTION_BLOCK FB_Manip
VAR_INPUT
RefSupport1 : REFERENCE TO FB_Support;
RefSupport2 : REFERENCE TO FB_Support;
END_VAR
VAR
RefSupport : REFERENCE TO FB_Support;
NumSupport: INT:=1;
END_VAR
IF NumSupport=1 THEN
RefSupport:=RefSupport1;
ELSE
RefSupport:=RefSupport2;
END_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have a FB with 2 REFERENCE TO FB as input parameters.
In the FB, i want to work with either the first or the second Reference depending on a variable (NumSupport)
But when I try to affect the RefSupport:=RefSupport1, I get an exception.
Does anyone know how to deal with this problem ? What is correct way to work ?
Thank you
FUNCTION_BLOCK FB_Manip
VAR_INPUT
RefSupport1 : REFERENCE TO FB_Support;
RefSupport2 : REFERENCE TO FB_Support;
END_VAR
VAR
RefSupport : REFERENCE TO FB_Support;
NumSupport: INT:=1;
END_VAR
IF NumSupport=1 THEN
RefSupport:=RefSupport1;
ELSE
RefSupport:=RefSupport2;
END_IF
The operator generates a reference (pointer) to a value;
RefSupport REF= RefSupport1;
see https://help.codesys.com/webapp/_cds_ref_assignment;product=codesys;version=3.5.17.0
TIP: use a CASE statement for NumSupport instead of a IF THEN, that way you can easily extend your code in the future i.e;
Last edit: hermsen 2021-10-31
so easy ;)
Thank You !!!!
You could also use VAR_IN_OUT and not do VAR_INPUT and then declare a reference
https://help.codesys.com/webapp/_cds_vartypes_var_in_out;product=codesys;version=3.5.17.0
Best regards,
Marcel
Last edit: m.prestel 2021-11-02