Function POUs in PLCnext Engineer
This topic contains the following sections:
- General information on function POUs
- Conditional execution of functions with EN/ENO
- Function call in ST
- Function call in FBD/LD
General information on function POUs
A function is a POU with multiple input parameters and exactly one output parameter (return value). Calling a function with the same values returns always the same result. Return values can be single data types. Within a function, it is possible to call another function but not a function block or a program. Recursive calls are not allowed.
For each function the data type of the return value must be set. This is done using the 'Signature' editor (see figure below).
To add a function POU, right-click the folder 'COMPONENTS | Programming > Local > Functions & Function Blocks' (or any subfolder) and select the context-menu command 'Add Function'.
Write access to input formal parameters of functions can be permitted by setting the compiler option 'Allow write on variables with usage input'. Select 'Extras > Options' and open the category 'Compiler | IEC Compiler Settings' and select the respective checkbox.
Note
User-defined safety-related function POUs are not supported. Only safety-related functions from included libraries can be used. |
Conditional execution of functions with EN/ENO
EN/ENO allows an optional conditional execution of functions and function blocks according to the IEC 61131-3 standard. EN is an enable input, ENO an enable output formal parameter.
EN/ENO is not supported in safety-related code.
Refer to the help topic "Execution Control: EN/ENO" for details.
Function call in ST
In ST, a function call basically has the following syntax:
OutVariable := functionName(InVar1, InVar2);
The names of the required input variables are noted (in parentheses) after the function name. The function's return value (result) is assigned to an output variable.
Function call in FBD/LD
In FBD/LD, the function name is indicated within the function symbol.
The block color and the icon in the upper left corner of the symbol indicate the origin of the function (locally created, contained in a user library or system library). Refer to the section "FU/FB symbol indicates origin" for details.
In safety-related code worksheets programmed in SNOLD (Safety Network Oriented Ladder), library functions are shown with a yellow block icon: