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

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

  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

    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 select the menu command Build ‣ Build again.

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