PersistentVars RPi

damian177
2022-01-26
2022-01-27
  • damian177 - 2022-01-26

    Hi,
    I need one variable and array to writΔ™, read during program working and remember them after power failure, so I create Persistentvars:

    {attribute 'qualified_only'}
    VAR_GLOBAL PERSISTENT RETAIN
        mem_trans_arr: ARRAY[0..99, 0..1] OF STRING;   
        id_trans:BYTE;
    END_VAR
    

    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 ?

     
  • damian177 - 2022-01-27

    so, what should I do on event the power failure to keep my values ?

     
    • matthew - 2022-01-27

      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.

       

Log in to post a comment.