General
DFB instances can be used in all languages [Instruction List (IL), Structured Text (ST), Ladder (LD) and Function Block Diagram (FBD)] and in all the tasks of the application program (sections, subroutine, etc.), except for SFC program transition.
General Rules of Use
When using a DFB, you must comply with the following rules for whatever language is being used:
It is not necessary to connect all the input, input/output or output parameters, except the following parameters, which it is compulsory for you to assign:
input/output parameters
generic data-type output parameters (ANY_INT, ANY_ARRAY, etc.)
The following parameters are optional:
generic data-type input parameters (ANY_INT, ANY_ARRAY, etc.)
STRING-type input parameters
Unconnected input parameters keep the value of the previous call or the initialization value defined for these parameters, if the block has never been called
All of the objects assigned to the input, input/output and output parameters must be of the same type as those defined when the DFB type was created (for example: if the type INT is defined for the input parameter "speed", then you cannot assign it the type DINT or REAL)
The only exceptions are BOOL and EBOOL types for input and output parameters (not for input/output parameters), which can be mixed.
Example: The input parameter "Validation" may be defined as BOOL and associated with a %Mi internal bit of type EBOOL. However, in the internal code of the DFB type, the input parameter actually has BOOL-type properties (it cannot manage edges).
Assignment of Parameters
The following table summarizes the different possibilities for assigning parameters in the different programming languages.
Parameter |
Type |
Assignment of the parameter (1) |
Assignment |
---|---|---|---|
Inputs |
EDT (2) |
Connected, value, object or expression |
Optional (3) |
BOOL |
Connected, value, object or expression |
Optional |
|
DDT |
Connected, value or object |
Optional |
|
Device DDT |
Connected or object |
Compulsory |
|
ANY_... |
Connected or object |
Optional |
|
ANY_ARRAY |
Connected or object |
Optional |
|
Inputs/outputs |
EDT |
Connected or object |
Compulsory |
DDT |
Connected or object |
Compulsory |
|
Device DDT |
Connected or object |
Compulsory |
|
IODDT |
Connected or object |
Compulsory |
|
ANY_... |
Connected or object |
Compulsory |
|
ANY_ARRAY |
Connected or object |
Compulsory |
|
Outputs |
EDT |
Connected or object |
Optional |
DDT |
Connected or object |
Optional |
|
ANY_... |
Connected or object |
Compulsory |
|
ANY_ARRAY |
Connected or object |
Compulsory |
(1) Connected in Ladder (LD) or Function Block Diagram (FBD) language. Value or object in Instruction List (IL) or Structured Text (ST) language.
(2) Except BOOL-type parameters
(3) Except for STRING-type parameters that is compulsory.
Rules when using DFBs with arrays
WARNING | |
---|---|
When using dynamic arrays, it is mandatory to check the sizes of arrays that are identical. In specific case, using dynamic arrays as an output or input/output, an overflow could lead to improper execution of the program and stop of the PLC.
This behavior occurs if the following conditions are fulfilled simultaneously:
Use of a DFB with at least one output or I/O parameter of dynamic array type (
ANY_ARRAY_XXX
).In the coding of a DFB, use of a function or function block (FFB of type FIFO, LIFO, MOVE, MVX, T2T, SAH or SEL). Note that, the function or FFB needs two
ANY
type parameters with at least one defined on the output.The DFB parameter of the dynamic array is used in writing during the FFB call (on the
ANY
type parameter). For otherANY
parameters, an array with a fixed size is used.The size of the fixed size array is bigger than the size of the dynamic array calculated to store the result.
Example for checking the size of arrays
The following example shows how to check the size of arrays
using the function LENGTH_ARWORD
in a DFB.

In this example, Table_1
is an array with
a fixed size, Table_2
is a dynamic array of type ANY_ARRAY_WORD
. This program checks the size of each array.
The functions LENGTH_ARWORD
compute the size of each
array in order to condition the execution of the MOVE
function.