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.
(sorry for the german but RUC is in german in my case)
The template needs to contain the variables you want to read:
Using the CPU.per file and copy&paste the names this file can be created quite easy
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.
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?
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.
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?
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
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
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?
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.
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 ?