Easy and quick way to save/restore values of permanent variables?

Hello,

We are routinely saving the values of the permanent variables of our machines but the process can be a bit tedious. We are currently using the option ‘Variable list’ from ‘Runtime Utility Center’ and we have to manually create the variable list file for each machine.

Is there a way to automatically get the values of the variables declared in the ‘Cpu.per’ and save them into a file? And then use this file to restore the values if needed?
We’ve tried to use the ‘Watch’ window in Automation Studio but the process takes even longer.

Thank you!

Hello,

I use mapp recipe “MpRecipeXml”.
so I can save all variables which I want as XML file on the PLC.

With this library you can also load the variables back from the XML file in the PLC.

There are good videos at the tutorial portal.

Then you can programme a trigger that automates the process.

Best regards
Eric

Hello and welcome !

I would use RUC as well but with a template file


(sorry for the german but RUC is in german in my case)

The template needs to contain the variables you want to read:
image

Using the CPU.per file and copy&paste the names this file can be created quite easy
image

As a result you get a variable list back which only contains the variables in your template - if you directly write this into a file using RUC you can then use this created list directly to restore the values on this PLC.

So basically you would need a template file for every machine you run.

Here is another way of storing permanent variables (using an open-source library from Loupe):
Persist :: Loupe Documentation (loupeteam.github.io)

Installation:
GitHub - loupeteam/Persist: AR Library for storing variables to permanent memory

Hello @jordi.mauri

It looks like you got some good suggestions from multiple users here, and it has been a couple of weeks since the last activity on this post. If the answers helped you with your question, can you help the next person with the same question by marking the solution on the information which helped you the most. If you still have open questions on this topic, can you provide an update?

Thank you!

Hello @lukas.struber

All the ideas were good but it wasn’t exavtly what I had in mind. I think it would be possible to do what I want using this python wrapper for PVI:
https://github.com/hilch/Pvi.py
But I haven’t had the time to fully develop the idea.

Ideally it would be a python scripts that autmatically reads the variable names in ‘Cpu.per’, connects to the PLC and reads their values using the PVI python wrapper and stores everything in a .csv or .txt file.

HI @jordi.mauri ,

permanent variables must have a global scope.
To read them you can use the attached script as a starter.

(well, it would be some more work to read all elements of structures if some of them would be used to store permanent values)

read_global_vars.zip (801 Bytes)

Cpu.per uses a simple syntax so it should not be to much work to read the content and compare it with the complete list of global variables.

1 Like

Hello @christoph.hilchenbac ,

I have now prepared three python scripts:

  • Reads Cpu.per and saves the variable names into a .txt file
  • Reads the variable names in the .txt file and uses PVI to read their value. Variable name and value is saved into a .pkl file
  • Reads the variable names and values from the .pkl file and writes them to the CPU using PVI

I’ll share them when they are more polished.

The only big issue remaining is that I’m not able to write ‘datetime’ variables (i.e. (‘tsG_ManufacturingData.DeliveryDate’, datetime.datetime(1970, 1, 1, 1, 0)) ). I get the following error ‘[Errno 22] Invalid argument’. Do you have any idea how I could solve this?

Thank you!

Hello @jordi.mauri

The only big issue remaining is that I’m not able to write ‘datetime’ variables (i.e. (‘tsG_ManufacturingData.DeliveryDate’, datetime.datetime(1970, 1, 1, 1, 0)) ). I get the following error ‘[Errno 22] Invalid argument’

it looks like this is a Python errorwith datetime.timestamp() that has not yet been solved :frowning:

e.g.

datetime(1970, 1, 1, 1, 0).timestamp()

fails

datetime(1970,1,2,1,0,0)

should be used as oldest timestamp as a workaround

Thanks! I didn’t think it could be a Python error. I modified the script to handle this case.

These are the scripts I made using your PVI library:
VariableListReaderWriter.zip (3.0 KB)

They should work well for almost all situations, but yesterday I noticed one small thing when reading the value of the variables. If there are any arrays inside a strucutre, only the first element is read. Could this be an issue from the PVI library?

Thank you!

Hey cool, thanks for sharing !

Even if this task is a bit special, it is a clear example of how Python can also be used for such tasks.

If there are any arrays inside a strucutre, only the first element is read. Could this be an issue from the PVI library?

I just did a short test with an array of INT and this one worked for me. If you still found no error in your code please create an issue on the github and do not forget a sample.

image

If we stick to your original post, then we have heard many ways to realize the task. So it seems to me we can consider this thread solved, right ?

Thanks for your help @christoph.hilchenbac . I’ll mark the thread as solved.

1 Like