FB_BA_PersistentDataHandler

FB_BA_PersistentDataHandler 1:

When activated, the function block FB_BA_PersistentDataHandler first saves the persistent data in the file Port_xxx.bootdata. 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.

FB_BA_PersistentDataHandler 2:

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.

FB_BA_PersistentDataHandler 3:

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:

FB_BA_PersistentDataHandler 4:

Sample in CFC:

FB_BA_PersistentDataHandler 5:

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 is then no longer updated in the file xxx.bootdata.

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 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.

FB_BA_PersistentDataHandler 6:

The backup file Port_xxx.bootdata-old is also used when the controller is de-energized. In this case, too, the currently valid persistent data is not saved in Port_xxx.bootdata. When the system is restarted, only the old data is available, unless a more up-to-date file was generated by the function block FB_BA_PersistentDataHandler before the system was switched off.

FB_BA_PersistentDataHandler 7:

Syntax

FUNCTION_BLOCK FB_BA_PersistentDataHandler IMPLEMENTS I_BA_PersistentDataHandler
VAR_INPUT
  bStt                : BOOL;
  {attribute 'parameterUnit':= 's'}
  nInitSttDly         : UDINT := 10;
VAR_OUTPUT
  bBusy               : BOOL;
  nRemTnInitSttDly    : UDINT;
  bErr                : BOOL;
  sErrDescr           : T_MaxString;
END_VAR

FB_BA_PersistentDataHandler 8: Inputs

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.

FB_BA_PersistentDataHandler 9: Outputs

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.

FB_BA_PersistentDataHandler 10: Properties

Name

Type

Access

Description

Busy

BOOL

Get/Set

Signals the processing of the function block.

FB_BA_PersistentDataHandler 11: Methods

Name

Description

Utilize

Manages the information internally that there is a provider that makes persistent data available.

The call is accepted if active write operations are being carried out.

Write

Possibility to start the function block via the interface.

WritePersitentData

Method for writing persistent data.

FB_BA_PersistentDataHandler 12: Interfaces

Type

Description

I_BA_PersistentDataHandler

Interface for displaying the FB_BA_PersistentDataHandler.

I_BA_PersistentDataProvider

Interface for storing persistent data in the boot folder.

Requirements

Development environment

Required PLC library

TwinCAT 3.1 4024.56

Tc3_BA2_Common from V2.2.23.0