Skip to main content

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 selected the option for the textual view in the Declaration Editor category of the options (Tools → Options menu command).

  1. Click Project → Add Object to add the Persistent Variables object to the application object.

    CODESYS adds the persistent variable list _cds_icon_gvl_persistence.png PersistentVars below the application object in the device tree, and the editor opens.

  2. In the editor, enter a variable declaration, for example ivarpersist1 : INT; between VAR_GLOBAL PERSISTENT RETAIN and END_VAR.

  3. Double-click the POU in the device tree.

    The editor of the POU opens.

  4. Specify the following declaration in the declaration part:

    VAR PERSISTENT RETAIN

    ivarpersist2 : INT;

    END_VAR

  5. 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 click Build → Build.

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