A function block is a POU which provides 1 or more values during the processing of a controller program. As opposed to a function, the values of the output variables and the necessary internal variables shall persist from one execution of the function block to the next. Therefore, invocation of a function block with the same arguments (input parameters) need not always yield the same output values.
In addition to the functionality described by standard IEC11631-3, object-oriented programming is supported and function blocks can be defined as extensions of other function blocks. They can include interface definitions concerning Method invocation. Therefore, inheritance can be used when programming with function blocks.
A function block always is called via an instance, which is a reproduction (copy) of the function block.
To add a function block to an existing application, select the respective node in the
, click the green plus button and select . Alternatively you can right-click the node and execute the command . To create a function block that is independent of an application, select the node of the .In the
dialog box, select the option , enter a function block (<identifier>) and choose the desired .Additionally, you can set the following options:
Option |
Description |
---|---|
|
Enter the name of another function block available in the project, which should be the base for the current one. For details, refer to Extension of a Function Block. |
|
Enter the names of interfaces available in the project, which should be implemented in the current function block. You can enter several interfaces separated by commas. For details, refer to Implementing Interfaces. |
|
For compatibility reasons, access specifiers are optional. Specifier is available as an equivalent for having set no specifier.Alternatively, choose one of the options from the selection list:
|
|
Choose the desired programming language for all method and property objects created via the interface implementation, independently from that set for the function block itself. |
Click
to confirm the settings. The editor view for the new function block opens and you can start editing.Syntax
FUNCTION_BLOCK <access specifier> <function block name> | EXTENDS <function block name> | IMPLEMENTS <comma-separated list of interface names>
This is followed by the declaration of the variables. You can also group the inputs and outputs for quick fading out and in when the function block is used in an FBD or LD editor. Also refer to the chapter Attribute Pingroup.