A function is a ⮫ POU, ⮫ POU, ⮫ POU which supplies precisely one data element when executed and whose call in textual languages can occur as an operator in expressions. The data element can also be an array or a structure.
The object is added to the application or the project by clicking “Project Add Object POU”. In the device tree or in the “POUs” view, function POUs have the “(FUN)” suffix.




NOTICE

Functions have no internal status information, which means that functions do not save the values of their variables until the next call. Calls of a function with the same input variable values always supply the same output value. Therefore, functions must not use global variables and addresses.
The editor of a function consists of the declaration part and the implementation part.
The top line of the declaration part contains the following declaration:
FUNCTION <function> : <data type>
Below that, you declare the input and function variables.
The output variable of a function is the function name.




NOTICE

If you declare a local variable in a function as RETAIN
, this has no effect. In this case, CODESYS issues a compiler error.




NOTICE

You cannot mix explicit and implicit parameter assignments in function calls in CODESYS V3. This means that you have to use either only explicit or only implicit parameter assignments in function calls. The order of the parameter assignments when calling a function is arbitrary.
-
Calling a function
-
Functions with additional outputs