I need to save a variable after power off or any other reset of the controller.
I configured the variable as RETAIN (global var, INT type) using the checkbox, but it does not work (no error, the value is being reset after any shutdown/reset).
I tried to test the same controller(5APC2100_BY01_000) in the lab and it does not work as well: once I turn OFF and ON the controller the value is reset to 0.
One other thing to check - is it possible that the variables you’ve retained are getting a new value before you check them? For example, if you assign a variable a value in the INIT routine, that will overwrite whatever retained value it had on boot.
Also, you can check your AR version in Project → Change Runtime Versions in Automation Studio.
Then you can go to the Hardware Configuration of the PLC and check if the menĂĽ shows you the Editor for Permanent Variables (for APC2100 this is available)
Here you an add the Variable to the list and set up the fixed Offsets in Memory.
If your controller doesn’t support permanent variables, another option is to save the variables to the hard disk (CFast card). In my opinion, this is a good thing to do anyway because it ensures that the data persists on the memory card even if there is a cold start or the controller ever stops working.
The easiest way to do this is with mapp Recipe, which saves the variables you choose to a CSV or XML file. If you didn’t want to pay for the mapp Services license, you could also make your own solution by creating the CSV or XML file manually. You would then write the data to a file whenever it changes (or just before a cold start if you can predict that) and then read it again at startup. As a bonus, this file can be transferred to a different controller if you wanted to easily transfer the saved data to another machine. This is the method I use to save machine settings and configuration options in my projects and it works well. The only caveat is that these settings don’t change very often. If your variables are actively changing every cycle, you won’t want to write to the memory card that often.