6.6 Function and Function Block
6.6 Function and Function Block
Functions and function blocks can be invoked from programs. Functions and function blocks
can be created with POU objects.
The differences between functions and function blocks are as below.
■
Function (FUN)
● Functions can be used without being declared in the declaration section.
● Only one output is generated. However, additional outputs can be defined.
● Output variable and internal variable values are not saved.
■
Function block (FB)
● Function blocks can be used by declaring instances in the declaration section.
● Multiple outputs can be generated.
● Output variable and internal variable values are saved.
● Object-oriented definitions can be made by using EXTENDS (inheritance), IMPLEMENTS
(interface implementation), or access qualifiers.
6.6.1 Function
A function generates one output in response to one or more inputs. Functions can be used
without declaring variables.
For example, use the following procedure to create and invoke function "ADD_SUB", which
uses three INT type arguments as inputs, calculates (first argument) + (second argument) -
(third argument), and output the result.
1.
Right-click the [Application] object in the navigator pane and then select Add Object>POU
from the context-sensitive menu that is displayed.
The "Add POU" dialog box will be displayed.
6-32
WUME-GM1RTXOP-01