Professional Documents
Culture Documents
FC Vs FB PDF
FC Vs FB PDF
Application
An FC contains a program section that is always executed when the FC is called
by a different logic block. You can use functions for the following purposes:
x To return a function value to the calling block (example: math functions)
x To execute a technological function (example: single control function with a bit
logic operation).
Caution
In this case, if no data are written to an OUTPUT parameter in an FC, the block
may output random values!
As the calling block's local data area which is reserved for the copy is not assigned
to the OUTPUT parameter, no data will be written to this area. It will therefore
remain unchanged and the random value stored at this location will be output,
because local data are not automatically set to "0" by default, for example.
Note
Although the OUTPUT parameters of an FB or the INOUT parameters of an FC
and FB will not output random values (the old output value - or input value as
output value - is going to be maintained even if no data are written to the
parameter) you should still observe the points above in order to avoid unintentional
processing of "old" values.
Note
To avoid errors when working with FBs, read Permitted Data Types when
Transferring Parameters in the Appendix.
Application
An FB contains a program that is always executed when the FB is called by a
different logic block. Function blocks make it much easier to program frequently
occurring, complex functions.
)RUPDOSDUDPHWHU $FWXDOSDUDPHWHU
,QWHJHU%LWVVWDUW
6WDUW,17,1
6SHHG,17,1 ,QWHJHU%LWVVSHHG
+LVWRU\'7,1B287
5XQB7LPH7,0(,1B287 'DWHDQGWLPH%LWV
SRLQWHUWRWKHDGGUHVVRIWKHKLVWRU\
)%0RWRU '%0RWRUB
The following table shows which variables of the FB must be assigned actual
parameters.
Creating an Instance DB
Before you create an instance data block, the corresponding FB must already exist.
You specify the number of the FB when you create the instance data block.
&DOO)%'%XVHV
'%0RWRUB
GDWDIRUPRWRU
&DOO)%'%XVHV
)%0RWRUV '%0RWRUB
GDWDIRUPRWRU
&DOO)%'%XVHV
'%0RWRUB
GDWDIRUPRWRU
)%0RWRUSURFHVVLQJ '%
&DOO)%IURPDORJLFEORFN
&$//)%'%
9DULDEOHGHFODUDWLRQ 'DWDIRU0RWRUB
WUDQVIHUVGDWDIRU0RWRUB
VWDW0RWRUB)% 0RWRUB0RWRUB
VWDW0RWRUB)% 'DWDIRU0RWRUB &DOO)%IURPV)%
VWDW0RWRUB)% &$//0RWRUB
'DWDIRU0RWRUB &$//0RWRUB
&$//0RWRUB
)%0RWRUV
In this example, FB22 does not need its own instance data block, since its instance
data are saved in the instance data block of the calling FB.
'%3XPS $FFHVVRQO\IRU)%FDOO
)%3XPS
&$//)%'%
'% $FFHVVIRU)%)%DQG
)%$JLWDWRU
)%FDOO
'DWDIRUDJLWDWRU &$//)%'%
9DULDEOHGHFODUDWLRQ
WUDQVIHUVGDWDIRUDJLWDWRU
VWDW0RWRUB)%
'DWDIRU0RWRUB 0RWRUBXQG3XPSB
VWDW3XPSHB)%
&DOO)%IURP)%
&$//0RWRUB
'DWDIRU3XPSB &DOO)%IURP)%
&$//3XPSHB
)&
6KDUHG $FFHVVE\DOO
'% EORFNV
'%
)&
,QVWDQFH'% $FFHVVRQO\E\)%
)% '%