Function Block POUs in PLCnext Engineer
This topic contains the following sections:
- General information on function block POUs
- Instance declaration
- Conditional execution of functions with EN/ENO
- Function block call in ST
- Function block call in FBD/LD
General information on function block POUs
A function block is a POU with multiple input/output parameters and internal memory. The value a function block returns depends on the value of its internal memory. Within a function block, it is possible to call another function block or functions but not a program. Recursive calls are not allowed.
To call a function block in another function block or program, an instance of the called FB with a unique instance name has to be created and declared in the calling POU. The instance declaration must be added to the variables table (directly or while editing code). In the variables table each FB instance has its own declaration consisting of the unique FB instance name, the function block name and the declaration keyword ('Usage') 'Local'.
Object-oriented function blocks: according to IEC-61131-3, 3rd edition, object-oriented function blocks are supported. By adding a method to a user-defined function block the function block is defined as an object-oriented function block. For further information on methods, click here.
You can create safety-related user FBs in the 'Programming' category of the COMPONENTS area for a safety-related application if a Safety PLC is available in the project.
Safety-related C Function Blocks (CFBs): CFBs can be created in order to implement safety-related (loadable) C functions. (In PLCnext Engineer, C functions are always represented as CFBs.) CFBs do not have a visible code worksheet. Instead, they have a configuration editor where you must specify the C function to be called by its identifier, the required stack size, and so on.
After creating and specifying CFBs, they can be released as Safety IEC library which can then be included in other projects. Adding CFBs to the project as safety-related library is mandatory. It is not possible, to create CFBs in the project and instantiate them directly in the safety-related program or in FBs.
To add a function block POU, right-click the folder 'COMPONENTS | Programming > Local > Functions & Function Blocks' (or any subfolder) and select the context-menu command 'Add Function Block' or 'Add SFC Function Block'. In case of an SFC function block POU, a 'Transition' subfolder with one 'Transition' is automatically created under the new SFC POU.
Safety-related function block POUs and C function blocks can only be added and edited while being logged on to the Safety-related Area. For creating and using CFBs you must have additionally purchased a special software license. Safety-related POUs are indicated by the overlay icon.
Instance declaration
In the variables table of the calling POU, an instance name has to be declared. In the following example, DrainCheck_1 is the name of the DrainCheck FB instance.
Note
A safety-related FB can only be called (instantiated) in safety-related programs/FBs. |
A call of this FB instance using this name in ST and FBD/LD/NOLD is shown below.
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 block call in ST
A function block call in ST basically has the following syntax:
instance(invar1:=1, invar2:=2, in_out_var:=MyVariable);
a:= instance.outvar1;
Alternative syntax:
instance(invar1 := 1, invar2:=2, outvar1 => a, in_out_var:=MyVariable);
In this example, an FB with the instance name 'instance' is called with its input parameters 'invar1' and 'invar2' (each with assigned value). The FB returns a result in form of the output variable 'outvar1'. In our sample call, the result value is stored to the variable 'a'.
The formal parameter 'in_out_var' is read and written by the FB. In the local variables table of the FB, it is declared with 'Usage = InOut'. Note that an in/output formal parameter is not a "real variable" but a reference to another variable. It can be compared to a pointer that points to the address of another variable. Thus, only variables are allowed at in/output parameters but no constants or literals.
The textual ST language is currently not supported for safety-related FBs. Use the safety-related graphical SNOLD editor instead.
Function block call in FBD/LD
In FBD/LD/NOLD/SNOLD, the function block instance name is indicated above the symbol and the name of the function block type within the block symbol.
The block color and the icon in the upper left corner of the symbol indicate the origin of the function block (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), FB instances are shown with a yellow block icon:
Further Info
The illustration in the topic "Instantiation: Program and FB Instances" explains the relation between types and instances and shows where instances of these types are possible. |