Reproductions or instances (copies) of a function block can be created⮫ “Function block”.
Each instance possesses its own identifier (the instance name), and a data structure which contains its inputs, outputs, and internal variables. Instances are declared locally or globally as variables, whereas the name of the function block is indicated as the type of an identifier.
Regard the recommendations on the naming ⮫ “Recommendations on the naming of identifiers”.
Example
Example of an instance with the name INSTANCE of the FUB function block:
fubInstance: FUB;
Function blocks are always called through the instances described above.
Only the input and output parameters can be accessed from outside of an function block instance, not its internal variables.
Example for accessing an input variable
The function block FB has an input variable in1 of the type INT.
PROGRAM prog VAR fbinst1:fb; END_VAR LD 17 ST fbinst1.in1 CAL fbinst1 END_PROGRAM
The declaration parts of function blocks and programs can contain instance declarations⮫ “Function block”. Instance declarations are not permitted in functions⮫ “Function”.
Access to a function block instance is limited to the POU in which it was declared unless it was declared globally.
The instance name of a function block instance can be used as the input for a function or a function block.
All values are retained after processing a function block until the next it is processed. Therefore, function block calls with the same arguments do not always return the same output values!
If at least one of the function block variables is a retain variable, the total instance is stored in the retain area.