FB_exit

If required, you have to implement FB_exit explicitly. If this method is present it is called automatically (implicitly) before the code of the function block instance is removed by the controller (e.g. even if TwinCAT is switched from Run mode to Configuration mode).

FB_exit 1:

Explicit calling is not recommended

The methods FB_init, FB_reinit and FB_exit are system functions that are called implicitly at different times (further information on this can be found under Operating cases). Explicitly calling these methods can have inadvertent consequences and is therefore not recommended.

FB_exit 2:

Automatic core dump on exception in FB_init/FB_reinit/FB_exit

If an exception error occurs within the FB_init/FB_reinit/FB_exit code, e.g. due to a programming error, the runtime system automatically stores a core dump on the target system (from TC3.1 Build 4024.25). This core dump is stored as a *.core file in the boot folder of the target system (by default under C:\TwinCAT\3.1\Boot\Plc) and can be used for the search of causes.

For more information on loading a core dump, see: Error analysis with core dump

Interface of the FB_exit method

METHOD FB_exit : BOOL
VAR_INPUT
    bInCopyCode : BOOL; // if TRUE, the exit method is called for exiting an instance that is copied afterwards (online change)
END_VAR

Through the evaluation of the FB_exit method parameter you can distinguish between the operating cases and adapt the implementation if necessary. (see Operating cases)

Method parameters

(first/new) download

Online Change

bInCopyCode

FALSE

TRUE

Return value

Implicit calls

If the methods are called implicitly the return value will not be evaluated by the system. Even if you adjust the return value, it will not be evaluated with an implicit call.

Explicit calls

If the methods are called explicitly you can evaluate the return value. You can thus return a meaningful return value.

FB_exit with derived function blocks

If a function block is derived from another function block, then the FB_exit method of the basic function block is automatically executed for this function block. If the FB_exit method of the derived function block is explicitly added, this is executed first and then the FB_exit method of the basic function block (see Behavior with derived function blocks).

See also: