I'm still working on this, but if you use the code here https://forge.codesys.com/forge/talk/Engineering/thread/1f8eee253c/
I'm using a struct to store all my different variables and then using the pointer to the struct memory location and then setting the data length greater than what is in the struct. My plan is to modify the FB so it automatically reads the length of the data and so you can assign the struct directly to it. Have not had time to do this yet.
Your next issue will be the SD card getting corrupt from the sudden power loss, the best way to try prevent this is to use a read only file system for the OS. I have not tried this yet and will be giving it a go soon.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I need one variable and array to writΔ, read during program working and remember them after power failure, so I create Persistentvars:
Read and write form my PLC_PRG works fine. But after restart/ turn off my RPi and run my variable and array are empty , why ?
Hi Damian,
Have a read through this https://forge.codesys.com/forge/talk/Engineering/thread/74485fd9ed/ hopefully it puts you on the right track. It's because they only get saved with a clean shutdown.
so, what should I do on event the power failure to keep my values ?
I'm still working on this, but if you use the code here
https://forge.codesys.com/forge/talk/Engineering/thread/1f8eee253c/
I'm using a struct to store all my different variables and then using the pointer to the struct memory location and then setting the data length greater than what is in the struct. My plan is to modify the FB so it automatically reads the length of the data and so you can assign the struct directly to it. Have not had time to do this yet.
Your next issue will be the SD card getting corrupt from the sudden power loss, the best way to try prevent this is to use a read only file system for the OS. I have not tried this yet and will be giving it a go soon.