FB_HVACPersistentDataHandling
Application
With this function block, all PLC variables that are declared as persistent (VAR PERSISTENT) are written fail-safe to a file. The PLC variables declared as persistent within the function blocks from the TcHVAC.lib are written to this file in case of a change. This file is saved under ..\TwinCAT\Boot directory and is named as follows: TCPLC_T_x.wbp (x = number of the runtime system). So that the new status is not saved immediately after a change of the persistent variables, a timeframe of 5 sec is built into the standard setting. This timeframe can be changed by the user. He must assign the new time to the globally-declared constant variable g_tHVACWriteBackupDataTime : TIME := t#5s.
The new status is only saved after the timeframe has elapsed. In the worst case this can mean that changes made within the last timeframe are not saved if a power failure occurs during that time.
Each time the controller is restarted, the status of the persistent data is read from the file. The output variable udiStatus indicates whether or not the data is valid.
In order to secure the persistent variables inside the function block voltage failure safe, it is necessary to start an instance of the FB_HVACPersistentDataHandling block in the MAIN program. The handling of this function is described in more detail on the basis of the following application example.
see also application example: Example_PERSISTENT.zip
The behavior of the function block looks as follows if everything was correct at startup:
udiStatus:= 1;
iPersistCount:= 1;
bDone:= FALSE
If the result of the query of usiStatus=1 this means that the persistent variables have been read from memory. bDone becomes TRUE only when the persistent variables have been written successfully.
The following setting must be made in the TwinCAT System Manager:
Under PLC Configuration in the PLC Settings (Target System) tab
the option Delete invalid persistent data must be disabled!! The deactivation must be performed using the Apply button.
VAR_INPUT
sNETID : T_AmsNetId;
TMOUT : TIME;
ePersistentMode : E_PersistentMode;
sNETID : AmsNetId of the TwinCAT computer on which the function should be executed. If it is to be run on the local computer, an empty string can be entered.
TMOUT : states the length of the timeout that may not be exceeded by execution of the ADS command.
ePersistentMode: mode in which the persistent data should be written. See also E_PersistentMode.
VAR_OUTPUT
udiStatus : UDINT;
iPersistCount : INT;
bDone : BOOL;
bBusy : BOOL;
bError : BOOL;
udiErrorID : UDINT;
udiStatus : 0 = No status
1 = Persistent data read successfully
2 = Backup from persistent data read
3 = Neither persistent nor backup data read
iPersistCount: counter that is incremented by 1 after successful writing.
bDone: will be set to TRUE if the function block is executed.
bBusy: when the function block is activated the output is set, and it remains active until execution of the command has been completed.
bError: this output is set to TRUE if an error occurs during the execution of a command.
udiErrorID: contains the command-specific error code. Please see ADS Return Codes.