Function Blocks

Top  Previous  Next

 

1        Task

Function blocks (FB) are very similar to functions. The difference between these two is that calling a function block nearly always a data block is specified in which the data, the block shall work with, are saved. This data block is named instance-data block. Its structure is adjusted while programming the FB and the access to its data is very comfortable within the FB.

 

In function blocks there are further kinds of variables: the static variables. These variables keep their value from one call of the function block to the next one.

 

2        Instance-data block-model

After having declared the parameter and variables of a function block and after having programmed the block you have to call it anywhere otherwise it is not executed. If you program the call you will have to specify a data block number. The development system now creates a data block with this number and makes it so big that all parameter and (static) variables have got enough space in it. Also the names, data types and the comments are taken over out of the declaration part of the function block. The values of the data words (-bits, -bytes, -double bytes) are set to the default values that are specified in the header of the function block while creating.

 

Executing the program this data block will be opened automatically if the function block is called. Now it is the instance-data block. The values of the actual-operands which are declared as In-Out-parameter are copied in the data block. All write- and read-accesses in the function block which you have programmed by using the parameter names refer to the data in the instance-data block. Returning to the calling block the In-Out- and Out-parameter are copied from the instance-data block into the connected operands. The use of the procedure will be clear if you program several calls for the same function block, and this with different data blocks. Each of these DBs is created according to the mask of the function-block-header.

 

A standard example for this use of the instance-data-model is an operating time counter in a FB in whose header you have declared an In-BOOL-parameter with the meaning ‘Engine Runs’ and a Stat-INT-variable with the meaning ‘Operating Minutes’. This FB you call for motor 1 with the DB 1, for motor 2 with the DB 2 etc.. At each process of the FB the data which are assigned to the engine are executed automatically.

 

See also: Local instance

 

3        Temporary variables

The temporary variables in function blocks are saved on the stack just like the ones of functions. They are not part of the instance data block.