In the CoDeSys help I found info about VAR_INPUT CONSTANT, but if I try this I get compile errors when calling the method with not all inputs filled in.
it is possible with a FB by using an initial value to the input variable definition like Input :Byte := 4;, But not possible with a FUN that I am aware of, CoDeSys will not compile if the input to a function is not connected to a variable. Why do you need to do this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The default argument causes default method operation. All method calls that require default operation then need to pass the default argument. A lot simpler and safer if you can omit it as in C++, no ? Thx !
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As it's possible in e.g. C++ to have default function arguments, I'm now wondering if this is also possible in CoDeSys ?
C++ example
Following function calls are both valid ...
In the CoDeSys help I found info about VAR_INPUT CONSTANT, but if I try this I get compile errors when calling the method with not all inputs filled in.
Does anyone have an idea if my idea is possible ?
it is possible with a FB by using an initial value to the input variable definition like Input :Byte := 4;, But not possible with a FUN that I am aware of, CoDeSys will not compile if the input to a function is not connected to a variable. Why do you need to do this?
The default argument causes default method operation. All method calls that require default operation then need to pass the default argument. A lot simpler and safer if you can omit it as in C++, no ? Thx !
I do not have the problem
Please add a Function_Block to your project
FUNCTION_BLOCK My_FB
VAR_INPUT
nValue : INT;
END_VAR
VAR_INPUT CONSTANT
nStep: INT := 1;
END_VAR
VAR
END_VAR
Code is only a ;
Declare a instance in the PLC_PRG
VAR
END_VAR
And use it with mfb();
Set a BP to mfb()
And step into with F8
There youβll see nStep is 1
I'm using CoDeSys v3.3
It indeed works for Function Blocks ... Thanks ! However, I need to explicitely pass the input name in the FB call ...```
mfb(nValue:=99);
```
Tried the same now with a method but then I get a compile error that tells me the method requires exactly 2 inputs
Any idea on that ?