FB_BA_WrtPersistDat
When activated, the function block FB_BA_WrtPersistDat first saves the persistent data in the Port_xxx.bootdata file. It is not necessary to explicitly specify the port or runtime system at which the PLC is located; this is determined internally. Once the data has been written, the content of the file Port_xxx.bootdata is copied to the backup file Port_xxx.bootdata-old. Thus both files are always synchronized. In case the original file with the persistent data is not readable, the backup copy, which is then read, contains the same data.
In any case, the checkmark for "Clear Invalid Persistent Data" must be removed (see Description of persistent data handling under TwinCAT3). |
The function block can be started in two ways:
Via a positive edge at input bStt, if the function block is not in the set start-up phase.
Initially once the start-up phase is completed after a reset or TwinCAT restart. The duration is set at nInitSttDly in seconds. If "0" is entered there, the duration of the start-up phase is 0 and an initial execution of the function block is skipped.
No commands are accepted at bStt during the start-up phase.
If errors occur while reading, writing, opening or closing the files, this is indicated by a corresponding error message at bErr/sErrDescr. After an internally fixed waiting time of two seconds, the function block automatically attempts to execute the command (read, write, open or close) again.
It is therefore advisable to keep an eye on the error outputs or to evaluate them.
It is also important to note whether the backup file for the persistent data was loaded during the TwinCAT restart or after a reset. This indicates that the original file cannot be read and that the memory card of the controller is defective. It can be queried for each runtime system with the boolean assignment of TwinCAT_SystemInfoVarList._AppInfo.OldBootData (see PlcAppSystemInfo).
Sample in ST:
Sample in CFC:
Notice | |
File handle conflicts Make sure that only this function block and only one instance of it accesses the persistent data. If several function blocks open a file and do not close it again, unforeseen file handle conflicts can occur which cannot be intercepted. The persistent data will then no longer be updated in the xxx.bootdata file. |
Description of persistent data handling under TwinCAT 3
TwinCAT saves the persistent data for each runtime system in a file during each orderly shutdown, i.e. when switching from Run to Config or Stop mode.
The file name consists of the ADS port name of the runtime system with the file extension .bootdata, e.g.: Port_851.bootdata and is stored in the TwinCAT directory under TwinCAT\3.1\Boot\PLC.
When the system is restarted, i.e. when switching to run mode, this file is read and then saved as Port_xxx.bootdata-old.
If the file Port_xxx.bootdata-old already exists, it is overwritten.
The original file Port_xxx.bootdata then no longer exists. It is created again automatically when switching to Stop mode or by the function block FB_WritePersistentData from the TC2_Utilities library.
This behavior applies to each runtime system; each system has its own files with persistent data.
If the file is defective when the TwinCAT system is restarted, the system automatically accesses the backup file Port_xxx.bootdata-old. However, this behavior only applies if the Clear Invalid Persistent Data checkmark is unchecked in the runtime settings. If it is checked and the original file is defective, no data will be read.
The Port_xxx.bootdata-old backup file is also used when the controller is de-energized. In this case, too, the current persistent data is not stored in Port_xxx.bootdata. When the system is restarted, only the old data is available, unless a more up-to-date file was created by the function block FB_WritePersistDat before the system was switched off.
Inputs
VAR_INPUT
bStt : BOOL;
nInitSttDly : UDINT;
END_VAR
Name | Type | Description |
---|---|---|
bStt | BOOL | A rising edge at this input starts the function block if it is not in the start-up phase. |
nInitSttDly | UDINT | Start-up phase after a reset or TwinCAT restart. The duration is set in seconds. Once the start-up phase has elapsed, the function block is automatically started once. No commands are accepted for bStt during the start-up phase. If "0" is set at nInitSttDly, the start-up phase is skipped. This input is preconfigured with 10 s. |
Outputs
VAR_OUTPUT
bBusy : BOOL;
nRemTiInitSttDly : UDINT;
bErr : BOOL;
sErrDescr : T_MaxString;
END_VAR
Name | Type | Description |
---|---|---|
bBusy | BOOL | The function block is being executed. |
nRemTiInitSttDly | UDINT | Countdown of the set start-up phase. |
bErr | BOOL | This output is switched to TRUE if the parameters entered are erroneous. |
sErrDescr | T_MAXSTRING | Contains the error description. |
Error description |
---|
01: Error: The number of the ADS port issued by the PLC is "0". |
02: Warning: Error when writing the persistent data via the internal function block FB_WritePersistentData. Additionally its error number. |
03: Warning: Error when opening the backup file (xxx.bootdata-old) via the internal function block FB_FileOpen. Additionally its error number. |
04: Warning: Error when reading the original file (xxx.bootdata) via the internal function block FB_FileRead. Additionally its error number. |
05: Warning: Error when writing the backup file (xxx.bootdata-old) via the internal function block FB_FileWrite. Additionally its error number. |
06: Warning: Error when closing the original file (xxx.bootdata) via the internal function block FB_FileClose. Additionally its error number. |
07: Warning: Error when closing the backup file (xxx.bootdata-old) via the internal function block FB_FileClose. Additionally its error number. |
Requirements
Development environment | Required PLC library |
---|---|
TwinCAT from v3.1.4024.22 | Tc3_BA2 from v5.2.5.0 |