Below you will declare persistent variables in a persistent variable list and in a POU.
Requirement: A project is opened and contains a program POU. You have selected the option for the textual view in the “Declaration Editor” category of the options (menu command in “Tools Options”).
-
Add the “Persistent Variables” object to the application object with the menu command “Project Add Object”.
CODESYS adds the persistent variable list
“PersistentVars” below the application object in the device tree and the editor opens.
-
In the editor, enter a variable declaration, for example
ivarpersist1 : INT;
betweenVAR_GLOBAL PERSISTENT RETAIN
andEND_VAR
. -
Double-click the POU in the device tree.
The editor of the POU opens.
-
Specify the following declaration in the declaration part:
VAR PERSISTENT RETAIN
ivarpersist2
: INT;END_VAR
-
Click “Build Build”.
The message view opens. If CODESYS has compiled the application without errors, then close the message window and continue with the next step. Otherwise, correct the error(s) and select the menu command “Build Build” again.
-
Set the focus in the “PersistentVars” editor. Click “Declarations Add All Instance Paths”
CODESYS adds the persistent variable from the persistent variable list “PersistentVars” to the POU:
// instance path of the persistent variables created
POU.IVARPERSIST2 : INT