I need one variable and array to writę, read during program working and remember them after power failure, so I create Persistentvars:
VAR_GLOBAL PERSISTENT RETAIN
mem_trans_arr: ARRAY[0..99, 0..1] OF STRING;
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 ?
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
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.
Log in to post a comment.