The lifespan of a variable and its data begins at the time when the variable is created and ends at the time when the variable is deleted and its memory is freed. The time when the variable is created, initialized, or instantiated depends on the declared scope. The time when the memory is freed usually depends on the scope as well. For example, the memory of global variables is freed by exiting the application.
They can retain data longer than usual. The following mechanisms in CODESYS are provided for this purpose.
Mechanisms for data retention
-
(A): ⮫ Persistent global variable list
with the
PERSISTENT RETAIN
keywordPersistent variables retain their values when the application is reloaded. Moreover, the values are restored after a download, warm start, or cold start.
-
(B): ⮫ Retain variables with the
RETAIN
keywordRetain variables retain their values after a warm start, but not after reloading the application, a download, or a cold start.
-
(C): ⮫ Variables of the Persistence Manager of the CODESYS Application Composer
Variables of the Persistence Manager are stored in an external file.
-
(D): ⮫ Recipe variables
Recipe variables and their values are stored in a recipe file.
-
Mechanisms in Comparison
-
Lifespan of variables when calling online commands
-
Lifespan of variables when loading a boot application
-
Preserving Data with Persistent Variables
-
Preserving Data with Retain Variables
-
Retaining Data with Variables of the Persistence Manager
-
Preserving Data with Recipes
-
Declaring VAR PERSISTENT Variables
-
Saving the Values of a Persistent Variable List to a Recipe