Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

variables not retained through power cycle?

con2827
2016-06-28
2016-07-24
  • con2827 - 2016-06-28

    I have variables defined as RETAIN PERSISTENT, in a persistent variable list, but their values are not retained when power is cycled.

    Did I miss something in configuring these variables? What is the correct configuration so that they retain their values?

     
  • Anonymous - 2016-06-28

    Originally created by: scott_cunningham

    I believe from another post that the RPii does not support persistent retain. You will need a UPS and store you variables in a file. l viewtopic.php?f=21&t=6937&p=14993&hilit=Persistent#p14993 l

     
  • con2827 - 2016-06-30

    Thanks, I had seen other posts on this, but still have questions:

    1. It seems the recommendation is to have a ups, to allow a proper shutdown of the pi. But that doesn't necessarily help since it's not always possible to properly shut down the pi, ups or not.
    2. What is the purpose of having RETAIN PERSISTENT variables anyway, in this case?
    3. If the pi retains the logic/program/etc - which it does, I don't have to do a download after a power cycle - why not the variable data too?
     
  • Anonymous - 2016-07-04

    Originally created by: scott_cunningham

    To answer your questions:

    1. I am no help on this point - I work with industrial controls.

    2. Persistent retain are standard keywords of the PLCopen group, which was designed for industrial automation. They are not removed from the IDE based on what the hardware platform can or cannot support. CoDeSys's original target market was industrial automation and has been expanded to the Pi probably as a teaching tool support.

    3. For an industri PC, the program goes to the file system but persistent retains go to an NVRAM. Clearly, the Pi doesn't have NVRAM.

    You will have to make a workaround with storing values in your file system, or switch to a hardware platform that supports persistent retain (it won't be $30, however).

     
  • johan76swart - 2016-07-12

    Hi Con2827,

    It is important to keep in mind that the Raspberry Pi is not an Industrial PLC, however there is a workaround if you want to save variables.
    I do this by writing and reading variables to its own file. There is a library dedicated to achieve this, SysFile Library.

    Usually I have some User configurable variable which I would like to save, and then on startup load those variables back into program.
    First I have created a function block to make this operation more stream like.

    See this attachment for creating such a function block.

    You will see that I have use two separate triggers for the read and write functions.

    You could have a manual write or an action defined write on the write trigger, which essentially writes the variable to a file name of your choice.
    Usually I load my variables on startup with a timed pulse and inhibit any write actions for a few seconds.

    Hope you will find this info useful.

    BR,

    Johan.

    IMG: Read_WriteVariables.png

    Read_WriteFile.pdf [39.3 KiB]

     
  • adrian.nicola - 2016-07-24

    YES It not retain variable if its a power down.
    Whatever to retain some settings variable, in my projects i discover that if i give a restart command to raspberry it save and keep the variable used like persistent.

    i put a switch on web interface for save and reset.This switch it activate a GPIO pin. On raspbery OS i run cyclical a PYTHON script to read other GPIO pin and reset the raspbery when pin its active. This 2 GPIO pins are connected with a wire. when i push the switch from web interface i reset the raspbery

    I dont know why i dont manage to send a reset command from codesys to raspbery directly from software and i make this improvisation. if anybody succeed to send a software reset command from codesys to raspbery pls share here and i will not need this wire and python shit.

    whatever it works. i can save and retain my settings if its a power down if before was save with reset method

    I dont search the posts maybe somebody find some other methods. with this you dont need UPS

     

Log in to post a comment.