I use the B&R function BOOL_TO_STRING to convert Boolean values into strings. Basically, this works perfectly. The generated string is then transferred to a JSON script and processed there.
However, BOOL_TO_STRING returns the values “TRUE” and “FALSE” in uppercase letters. The JSON script only accepts ‘true’ and “false” in lowercase letters, which results in an error message.
Since the B&R function cannot be customized and a self-created FUNCTION cannot have STRING as a return value, I am looking for an elegant solution via a function call.
Does anyone have any tips on how to solve this in AS?
Many thanks in advance.
no words, thanks @alexander.hefner, colleagues have developed ToLower function, but totally true in this case a simple condition it’s enough.
Ciao
Valerio
You can create a function and pass as input a pointer to a string and then set the string value inside of the function.
Btw what’s the final goal? You want to convert a process variable to json?
I’m not sure if I understood it right: is your question about the return type of a function?
If yes, you’re right, the return type of a user function cannot be a STRING. I’m not aware of the exact details behind that, but as I know some of those “look alike”-functions are not really functions but are handled different by the backend parser and compiler (they are handled in background more like “defines” then like functions).
But you could achieve something similar wit a user library by:
using a function but passing your target string by a pointer (address to the string declared outside of the function)
using a function block instead of a function and passing the string as VAR_IN_OUT
I’ll try to make 2 examples of what I mean, but I’m not sure if I can finish them today.