PLC

Methods FB_init, FB_reinit and FB_exit

You can use the methods explicitly to influence the initialization of function block variables and the behavior when function blocks are terminated.

FB_init
FB_reinit
FB_exit

See also the information on operating cases for these methods.

 

Return value

By default, the return value of the methods FB_init, FB_reinit, and FB_exit is not used, and FALSE is returned. If these methods are called implicitly, the return value is not evaluated.

If you want to call the methods explicitly, you can return a meaningful return value and evaluate it when you explicitly call the methods. Keep in mind that, even if you adjust the return value, it is not evaluated in an implicit call.

 
 

Behavior with derived function blocks

When using the methods FB_init, FB_reinit and FB_exit in the context of derived function blocks, please note the following.

 

FB_init with derived function blocks

If a function block is derived from another function block, the FB_init method of the derived function block – if this is to be available in explicit form – must define the same parameters as the FB_init method of the basic function block. Further parameters can be added, in order to set up a special initialization for the derived instance.

 
 

FB_reinit with derived function blocks

To reinitialize the basic implementation of the function block, FB_reinit must be called explicitly for the basic function block (via SUPER^.FB_reinit()). The return value can be evaluated.

 
 

Sample of the call sequence for derived function blocks

The function blocks FB_Base, FB_Sub and FB_SubSub are derived from each other. The motto is:

FB_Sub EXTENDS FB_Base
FB_SubSub EXTENDS FB_Sub

Situation:

All three function blocks have their own FB_init, FB_reinit and FB_exit methods.
The function block FB_SubSub is instantiated. An additional variable is added to the function block via Online Change.

Assumption - case 1:

No reinitialization of the basic implementation is required. This means that the call SUPER^.FB_reinit() does not exist in the method FB_SubSub.FB_reinit.

Call sequence:

The call sequence for the methods FB_exit, FB_init and FB_reinit for the function block instance fbSubSub is then as follows:

1.
Call of FB_SubSub.FB_exit(TRUE) for fbSubSub
2.
Call of FB_Sub.FB_exit(TRUE) for fbSubSub
3.
Call of FB_Base.FB_exit(TRUE) for fbSubSub
4.
Call of FB_Base.FB_init(FALSE, TRUE) for fbSubSub
5.
Call of FB_Sub.FB_init(FALSE, TRUE) for fbSubSub
6.
Call of FB_SubSub.FB_init(FALSE, TRUE) for fbSubSub
7.
Call of FB_SubSub.FB_reinit() for fbSubSub

Assumption – case 2:

A reinitialization of the basic implementation is required. This means that the methods FB_SubSub.FB_reinit and FB_Sub.FB_reinit contain the call SUPER^.FB_reinit().

Call sequence:

The call sequence for the methods FB_exit, FB_init and FB_reinit for the function block instance fbSubSub is then as follows:

1.
Call of FB_SubSub.FB_exit(TRUE) for fbSubSub
2.
Call of FB_Sub.FB_exit(TRUE) for fbSubSub
3.
Call of FB_Base.FB_exit(TRUE) for fbSubSub
4.
Call of FB_Base.FB_init(FALSE, TRUE) for fbSubSub
5.
Call of FB_Sub.FB_init(FALSE, TRUE) for fbSubSub
6.
Call of FB_SubSub.FB_init(FALSE, TRUE) for fbSubSub
7.
Call of FB_SubSub.FB_reinit() for fbSubSub
8.
Call of FB_Sub.FB_reinit() for fbSubSub
9.
Call of FB_Base.FB_reinit() for fbSubSub
 
 

See also:

Object Method
Attribute 'call_after_init'
Attribute 'no_copy'
Attribute 'no-exit'
Additional information
FB_init
FB_reinit
FB_exit
Operating cases