In this example we are going to explain how to make a Backup of the persistent memory of a PLC with Codesys.
When we program the automation of a machine with a PLC, it is very likely that we use persistent variables where we will store machine configuration parameters or recipe parameters.
It is important to have a Backup or safeguard of the value of these variables since it may happen that one day they are deleted or someone modifies them and the machine stops working, having this Backup it will be easy to restore the machine with the default values.
To know how to create Persistent Variables in Codesys you can consult this article.
Permanent backup of variables from PLC to Codesys
IF we open the Persistent Variables editor, place the mouse over one of the variables and press the right mouse button and select «Save Current Values to Recipe»
A new recipe element called «Recipe Manager» will automatically be created in the project tree from which the «PersistentVariables» element hangs.
If we open «Recipe Manager» – «PersistentVariables» we can see the current value of the variables «Current Value» and the saved value «PersVar» (in this image it is the same, 100, since it has not been modified)
With this we would already have saved the value of the Permanent Variables in our project.
Save Backup of Permanent variables in a file external to Codesys
If we are interested in saving the data in a file external to the Codesys project, we can do the following:
Being in «Recipe Manager» – «PersistentVariables» we put the mouse over «PersVar», it is important that it be placed on top of this since otherwise the following options will not appear and we click on the Right Mouse Button,
We will see the following option «Save_Recipe»
This will open a dialog to indicate where we want to save the file
Once saved, we can open it with the «Notes block» and consult the values of the variables
Load permanent variables from Codesys to PLC
Once we have stored the variables, it may be the case that they have to be loaded to the PLC since, as we have commented before, they have been deleted or someone has modified them.
To do this, if we open the Persistent Variables editor, place the mouse over one of the variables and press the right mouse button and select «Restore Values from Recipe»
This will write in the PLC Variable the value saved in the Backup