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 Tools ‣ Options ).

  1. Add the object Persistent Variables to the application object with the menu command Project ‣ Add object .

    ⇒ CODESYS adds the persistent variable list PersistentVars under 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 on the POU in the device tree.

    ⇒ The editor of the POU opens.

  4. Enter the following declaration in the declaration part:

    VAR PERSISTENT

    ivarpersist2 : INT;

    END_VAR

  5. Select the menu command Build ‣ Build .

    ⇒ 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 Build ‣ Build again.

  6. Click on the tab PersistentVars to select the persistent variable list as the active editor and select the menu command 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

See also