Good morning to all,
I'm new and I'm starting to study the FBD language in codesys, I have a big doubt:
I understand that the RETURN command in FBD stops the execution of a POU.
If I create a POU-function that returns a value, such as a function that takes two INT inputs and returns their sum, how can I return a result?
For example In the example I attach, I would like to return the value of ret_sum.
I think that:
true --- RETURN
Is not correct.
Thanks to who will respond.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-08-04
Originally created by: scott_cunningham
RETURN is a keyword for exiting a POU early, not for returning values like you find in other languages. In your example, the lines of code in your POU will be executed, ret_sum will be filled and you can access this value in your other POU that called the FB instance. VAR_OUTPUTs automatically work - just put a value into the variable.
PLCopen Programming guidelines recommends to not use the RETURN command. You can read more about it in the guidelines.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
scott_cunningham hat geschrieben:
RETURN is a keyword for exiting a POU early, not for returning values like you find in other languages. In your example, the lines of code in your POU will be executed, ret_sum will be filled and you can access this value in your other POU that called the FB instance. VAR_OUTPUTs automatically work - just put a value into the variable.
PLCopen Programming guidelines recommends to not use the RETURN command. You can read more about it in the guidelines.
Thanks a lot for your answer scott_cunningham, I downloaded PLCopen Programming guidelines and I start to study.
I understand the use of return in a Program or in a Function Block, but it's still not clear for me how to return a value in a Function (that returns a value e.g. INT) in FBD language.
In my first example I did an error adding the Var_Output ret_sum, now my FBD box that represent my function have 2 output ,the returned value of the function itself and the output variable ret_sum.
What I try to do is a pure function that returns a INT value and I want, for example, call this function in a Program.
I attach the new example but something is surely wrong,in fact when I go in simulation mode my function return alway 0 (and not 3+2=5) when I call it from my Program PLC_Prg.
I'm almoust sure that this happens because I don't know how set the returned value in a Function in FBD language.
I try to find this information in Codesys help without success, sorry.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Good morning to all,
I'm new and I'm starting to study the FBD language in codesys, I have a big doubt:
I understand that the RETURN command in FBD stops the execution of a POU.
If I create a POU-function that returns a value, such as a function that takes two INT inputs and returns their sum, how can I return a result?
For example In the example I attach, I would like to return the value of ret_sum.
I think that:
true --- RETURN
Is not correct.
Thanks to who will respond.
Originally created by: scott_cunningham
RETURN is a keyword for exiting a POU early, not for returning values like you find in other languages. In your example, the lines of code in your POU will be executed, ret_sum will be filled and you can access this value in your other POU that called the FB instance. VAR_OUTPUTs automatically work - just put a value into the variable.
PLCopen Programming guidelines recommends to not use the RETURN command. You can read more about it in the guidelines.
Thanks a lot for your answer scott_cunningham, I downloaded PLCopen Programming guidelines and I start to study.
I understand the use of return in a Program or in a Function Block, but it's still not clear for me how to return a value in a Function (that returns a value e.g. INT) in FBD language.
In my first example I did an error adding the Var_Output ret_sum, now my FBD box that represent my function have 2 output ,the returned value of the function itself and the output variable ret_sum.
What I try to do is a pure function that returns a INT value and I want, for example, call this function in a Program.
I attach the new example but something is surely wrong,in fact when I go in simulation mode my function return alway 0 (and not 3+2=5) when I call it from my Program PLC_Prg.
I'm almoust sure that this happens because I don't know how set the returned value in a Function in FBD language.
I try to find this information in Codesys help without success, sorry.
Use
MyFunc:=ret_value
Originally created by: scott_cunningham
Thanks Josep - I forgot to mention using the function name for the return...
@cassiel Here is what your function should look like in FBD:
Thanks a lot Josep and scott_cunningham for your hints! now I undertsand how to do a function that returns a value in FBD