How do I save and recall persistent variables? Where is this data stored?

How do I save and recall persistent variables? Where is this data stored?
none 0.0 0

I posed the following question to Codesys support and received the following reply. I would like to hear a response from Weintek also.

Where is data within Persistent Variables stored? When are they saved/stored?

From Codesys support - The PersistentVars list is stored on NVRAM or by use of a UPS, but this is dependent on the device you are using. The persistent variables will be saved every scan according to the task the variable is associated to.

There is also the possibility to save persistent variables with the application composer’s Persistent Manager. This allows users to save to, for example, an SD card and set the parameters on when the data should be saved. This would require your device to have access to a file system to store this data.

Here is some additional information on data persistence : Data Persistence

I believe the PersistentVARs are stored in a Weintek HMI’s flash memory. According to the Weintek Codesys datasheet, they are saved every 1 minute.

I have not heard of the Persistent Manager and am not sure if Weintek’s Codesys runtime supports this.

Hi Tim, thank you for the response. Are you going to dig some more to get definitive info on how this works in the Weintek? The datasheet is too vague. Thanks!

I am not sure what specific information you are looking for. To my knowledge, you can set up a list of Persistent variables within the Codesys IDE when you program Weintek Codesys. This method is suitable for most basic applications.
I am not going to look at the application composer’s Persistent Manager.
You can use the SysDir library to manage the directories in File System and use the SysFile library to open files stored in File System.

Then you can utilize the “VAR_ACCESS” to access your variables by two function blocks. Please see chapter 9 :

Hi @donnedved25,

If you have time, can you please advise what you are attempting to do within your project? This might help us determine what information we can provide that will help you with your application. As stated by @TimWusa, data that is retained is saved to the HMI in one minute intervals. We usually recommend creating an instance of “Persistent Variables” to retain data:

Just trying to understand the sequence. For reference, we know that ‘Download’ and ‘Login with online changes’ are two different functions. Also, we’ll assume data from a program was previously stored in the HMI as PersistentVars. Therefore,

  1. When a program ‘Download’ is required, is the data previously stored in the Weintek memory deleted? Or is it kept and loaded into the newly downloaded program?
  2. When a ‘Login with online changes’ occurs, same question as above, previous data deleted or loaded into program?
  3. In both cases above, if previous data is loaded into the program after ‘Download’ or ‘Login with online changes’, when does that occur?

Please see this table regarding your questions 1& 2

When your POUs change the values of the Persistent variables (or you manually change them within the Codesys IDE), the previous data will be overwritten.

Perfect Tim, thank you. May I ask where you found that table?

Last question - so the Weintek is saving Persistent Variables to memory and those values are loaded back in according to the above chart. What happens to variables in memory if they no longer exist in the Codesys program? Does the Weintek OS do any housekeeping to get rid of unused variables?

Hi @donnedved25,

Variations of the table advised by @TimWusa can be found in several locations including Codesys’s online help center: Link. Variables that are imported into EasyBuilder Pro from Codesys do not disappear if they are removed from the Codesys project. If you delete a tag, change the name of a tag, change the size of an array, or make any other notable changes please export the latest tag file and import it into EasyBuilder Pro. The same methodology should be used when working with any other tag-based device to prevent communication errors that can occur when attempting to poll data from a non-existent tag.

Although Codesys is “built-in”, it is essentially a separate entity with its own CPU core and communication modes. That is why it is not possible to start or stop the Codesys application within the HMI’s settings menu or allow the HMI to communicate using LAN-1.