Skip to content

how to return a value in a function (type: ST)

edited October 2021 in PLCnext Engineer
Hello,

how to set a return value for a function (not a function block) Code-Type: ST.

Signatur:
[code type="markup"]
Returntype: LREAL
[/code]

Code:
[code type="markup"]
dwTemp := SHL(TO_DWORD(wHigh), 16) + wLow;
RETURN TO_LREAL(dwTemp);
[/code]
is not working. I get an Error, want a ";" after RETURN statement

I searched in the internet for a long time, but have found nothing.

Comments

  • That's a great question - I tried exactly the same thing at first, until I learned that the RETURN statement in ST doesn't do the same thing as it does in C/C++.

    In ST, the RETURN statement simply returns to the calling POU at that point, and in ST this statement doesn't take any parameters.

    To return a value from a function in ST, simply assign a value to the name of the function. So, if your function is called MyFunc, the statement would be:
    MyFunc := TO_LREAL(dwTemp);
    
    I hope this helps.
Sign In or Register to comment.