Declaring VAR PERSISTENT Variables¶
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 activated the option for the textual view in the category Declaration editor in the options (menu command ).
Add the object Persistent Variables to the application object with the menu command .
- ⇒
CODESYS adds the persistent variable list
PersistentVars under 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 on the POU in the device tree.
- ⇒
The editor of the POU opens.
Enter the following declaration in the declaration part:
VAR PERSISTENT
ivarpersist2
: INT;END_VAR
Select the menu command
.- ⇒
The message window opens. If CODESYS has compiled the application without errors, close the message window and continue with the next step. Otherwise, rectify the error(s) and select the menu command
again.
Click on the tab PersistentVars to select the persistent variable list as the active editor and select the menu command .
- ⇒
CODESYS adds the persistent variable from the persistent variable list PersistentVars to the POU:
// instance path of the persistent variables created
POU.IVARPERSIST2: INT
See also