Skip to main content

Volatile and Retry Instances

Function Blocks (FBs)

FBs have internal variables that store their data during consecutive execution cycles. Depending on the application's needs, these FB instances can be configured as retentive (LOCAL_RETAIN or GLOBAL_RETAIN) or volatile (LOCAL or GLOBAL). The input and output variables associated with the FB can also be configured as retentive or volatile. Retentive variables retain their values after the device is shut down, while volatile variables retain their initial values after a reboot.

When we want a FB to retain its values after a device reboot, the FB instance and the variables associated with its inputs must be configured as retentive. This will ensure that the FB's internal variables and associated input variables retain their values from before the shutdown.

The example below shows the use of the TON (Delayed Enable Timer) block with instance and retentive variables:

Figure 1 - TP block with instance and retentive variables before reboot.

Figure 2 - TP block with instance and retentive variables 1 second after reboot.

When we want a FB to reset its values after the device is turned off, the FB instance and the variables associated with its inputs must be configured as volatile. This will cause the FB's internal variables and associated input variables to reset to their pre-shutdown values.

Below is an example of using the CTU (Incremental Counter) block with instance and volatile variables:

Figure 3 - CTU block with instance and volatile variables before reboot.

Figure 4 - CTU block with instance and volatile variables after reboot.

User Block (USERFB)

When using USERFB, you can define variables of type LOCAL, LOCAL_RETAIN, VAR_IN, VAR_OUT, and VAR_IN_OUT. Internal variables defined as LOCAL will always be volatile, and those of type LOCAL_RETAIN will always be retentive. The internal variables defined as VAR_IN, VAR_OUT and VAR_IN_OUT will be volatile if the USERFB instance is associated with the LOCAL or GLOBAL group and retentive if it is associated with the LOCAL_RETAIN or GLOBAL_RETAIN group.