How do you determine the block number of the "Data Types for Parameters" in the program and how can you pass this parameter on to an FC?
Using the following program codes, you can determine the number of the "Data Types for Parameters" (BLOCK_FC, BLOCK_FB, TIMER or COUNTER).
Example 1 for function blocks
In FB1, the "Time_1" variable of the "Timer" type is declared in the variable declaration and when FB1 is called in FB2, the "Time_1" variable is parameterized with the "T5" timer. The number 5 is determined for "T5" in the program code shown in Fig. 01.
Example 2 for functions
In FC1, the "Time_1" variable of the "Timer" type is declared in the variable declaration and when FC1 is called in FC2, the "Time_1" variable is parameterized with the "T8" timer. The number 8 is determined for "T8" in the program code shown in Fig. 02.
In the case of function blocks with multi-instances, you have to make an addition to the program in Fig. 01:
TAR2 //Address offset of the multi-instance
+AR1 //Add address offset of the multi-instance to the current address
When a function (FC) is called, it is not permissible to transfer directly a parameter of the "BLOCK_DB" type, for example. If you attempt to use a parameter type as current parameter when a function is called, you get the following error message:
"Illegal parameter assignment for <parameter name>"
It permissible to pass on a BLOCK_DB parameter type only when an FB is called (from an FB or an FC).
Direct passing on of parameter types is not permissible when a function is called (from an FB or an FC). More detailed information on this is available in the Online Help of STEP 7 under the topic of "Legal data types in the transfer of parameters".
However, if you still wish to pass on information from the BLOCK_DB parameter to an FC, the DB number can be determined and be transferred in an FC call by means of an elementary data type (e.g. WORD).
In the following example, the FB100 function block has an IN parameter of the "BLOCK_DB" (InData) type. In order to pass on this parameter during an FC101 call, the number of the data block transmitted with "BLOCK_DB" is determined and is saved in a temporary WORD variable (DB_No.). When the function is called, the data block number is transmitted as a WORD parameter instead of the BLOCK_DB parameter.
If the interface of the caller FB can be made with a WORD parameter for transferring the DB number, this parameter can be passed on directly to the FC that is being called.