Data Persistence

Persistent data are data that retain their values even when reloading the application. You can restore the values of persistent data after a download or a cold start.

CODESYS offers the following three mechanisms for achieving persistence:

See also

Note

A further possibility to keep data remanent is the RETAIN variables. Persistent data are always also RETAIN. Like the persistent variables the RETAIN variables retain their values in the case of a reset warm (power failure), but not in the case of a repeated download of the application that only the persistent data survive. You can also combine the remanent properties by means of a declaration with RETAIN + PERSISTENT. The variables declared only with VAR PERSISTENT are always treated as VAR RETAIN PERSISTENT or VAR PERSISTENT RETAIN. As a result you obtain data that are only re-initialized when resetting the controller to the delivery state (Reset Origin).

Which mechanism for which application?
Some common applications are considered here; the concrete examples in parentheses refer to a building controller:
  Application (A) VAR PERSISTENT (B) Persistence Manager (C) Recipes
         
1

Retention of appliance settings

(Power failure -> Venetian blind still ‘knows’ how long it needs to drive up)

suitable1

(preferential application, but it is also possible via VAR RETAIN; it is better to use retain variables if the variable definition has to be changed frequently in the practical case.

suitable2

Advantage: also usable for controllers without hardware support through special functions (double file buffering)

Possible, but very complicated
         
2 Retention of values even when the application program is changed/extended      
  2a: rare extensions (new switch and new light were installed, the remainder remains unchanged)

suitable1

(preferential application)

suitable2 Possible, but complicated
  2b: more liberal changes, also deletion or changing of the data type of variables (the building controller is running and is persistent, but now a new function is installed so that a further variable must be persistent in a function block; for example, the automatic switch-off of a forgotten lamp after a certain time) not suitable

suitable as far as possible 2

(preferential application)

Possible if textual, but complicated
3 Use of different value sets as required (it should be possible to store and if necessary load operating settings for summer, winter and vacation) not suitable not suitable

suitable

(preferential application)

         
4 Transfer of settings from one system to another that uses similar variables not suitable suitable2 suitable3
         
5 Settings should be textually readable (in order to be able to compare and edit states/changes) not suitable suitable2 suitable3

1 Disadvantage: runtime system must support the mechanism: NVRam memory or UPS; advantage: speed; recommended application: 1 and 2a

2 Disadvantage: long waiting periods during initialization and shutdown in case of large numbers of variables (> 10000) ; advantage: no special memory required; value retention even in case of changes/extensions/deletions;

3 Advantage: externally editable, transferable; disadvantage: complicated

See also