Functions

Functions are program organization units (POUs) having one or more input parameters and one output parameter. A function can be called by a program, a function or a function block. A function has no instance meaning that local data is not stored and is usually lost from one call to the other.
The execution of a function is driven by its parent program. Therefore, the execution of the parent program is suspended until the function ends:
Any POU of any section can call one or more functions. A function can have local variables.
Recursivity is not supported during function calls. When a function of the Functions section is called by itself or one of its called functions, a run-time error occurs. Furthermore, functions do not store the local values of their local variables. Since functions are not instantiated, these cannot call function blocks.
The interface of a function must be explicitly defined with a type and a unique name for each of its calling (input) parameters or return (output) parameter. A function has one return parameter. The value of the return parameter for a function differs for the various programming languages.
Functions within a project and the global library must have unique names within a scope. Function names and function parameter names are limited to 128 characters beginning with a letter followed by letters, digits, and single underscores. The last character for a function name must be a letter or digit; function names cannot end with an underscore character. Reserved words, defined words, or data types, such as elementary, structures, or arrays are not valid names.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal