rtuman
@thiagoralves,
My Persistent variables %MW300-301 reverted back to zero after reboot even though the Enable Persistent Storage Thread and Start OpenPLC in RUN mode are both checked in Settings. I could also change their values through MB TCP and verify their values on the Monitoring screen.

The hardware is a RPi4 with a Home Automation HAT. What could be the cause of the problem?

Please see the attached screen shot.
thiagoralves
What are the runtime logs?
Reply 0 0
rtuman
@thiagoralves,
RunTimeLog_0948_111321.txt is the log before reboot
RunTimeLog_0954_111321.txt is the log right after reboot
RunTimeLog_0959_111321.txt is the log after reboot and issuing Stop / Start PLC commands (to force Monitoring display)

The before and after Monitoring screens are also attached.

Thank you.
Reply 0 0
thiagoralves
Is there any change your persistent variables are rewritten in your ladder logic somewhere? From the logs (actually just the 0959 was useful as it shows the begining of program execution) it seems that the persistent storage module is loaded correctly. Try creating a blank program with some some %MW variables. Then write to them using Modbus, and then stop/start the PLC to check if the values you wrote before are still there. This is the simplest test to validate persistent storage.
Reply 0 0
rtuman
@thiagoralves,
I did what you suggested above by creating a blank program (actually a one rung Ladder program so OpenPLC can compile), and writing to %MW300 via MB TCP prior to rebooting.  It did not fix the problem.  The %MW variable still reverts back to zero.

I've attached the following for your reference:
  • The before and after reboot Monitoring screens 
  • The before and after RunTimeLogs
  • The RPi4 Directories before reboot
  • The complete set of project files (please rename the extension to .7z)
Can you please take a look?  I'm really puzzled.
Reply 0 0
thiagoralves
I tested your program on a Windows runtime and it worked perfectly. I wrote to %MW0, %MW1, %MW300 and %MW301 locations using modbus. They show up on the monitoring as expected, and after stopping / starting the PLC (no need for a reboot, since stopping the PLC is enough for all volatile data to be gone), the values were loaded back as expected, showing on the monitoring screen and on the modbus poll as well. Can you try a few other things?
1. Instead of rebooting the pi, just start / stop the PLC. This should have the same effect. If it works with just start / stop, then possibly something is erasing OpenPLC's persistent storage file during shutdown or reboot.
2. I saw that you're using the PSM driver. I don't know what is in your PSM code, so just to be sure it is not affecting the persistent storage module, can you try it again with PSM disabled? Use the blank driver instead.
Reply 0 0
rtuman

@thiagoralves@alexburcea,
1. I started and stopped the PLC with the existing PSM driver and it didn't work. The %MW's reverted back to zero.
2. The Blank driver did not work either (PLC would not run).
3. The Raspberry Pi driver works for keeping the persistent values in the %MW's, but the Ladder Logic now behaves differently with the first three digital inputs status reversed. Since I am using the Home Automation HAT, I think it needs the PSM module to run properly.  I've included the Monitor screen shots for both drivers for your reference.

My PSM code is listed below:

#import all your libraries here
import psm
import time
import libioplus

#global variables
counter = 0
var_state = False

def hardware_init():
#Insert your hardware initialization code in here
psm.start()

def update_inputs():
#Read optocoupled inputs
val = libioplus.getOpto(0)
for i in range(8):
var_state = False
if val & (1 << i) != 0:
var_state = True
psm.set_var("IX0." + str(i), var_state)#move OPTO state to IX0.0 .. IX0.7
for i in range(8):
valAdc = libioplus.getAdcV(0, i+1)
psm.set_var("IW" + str(i), int(1000 * valAdc)) #Update adc in value (mV) IW0 .. IW7

def update_outputs():
val = 0
for i in range(8):
a = psm.get_var("QX0." + str(i))
if a == True:
val+= 1 << i
libioplus.setRelays(0, val)
for i in range(4):
val = psm.get_var("QW" + str(i))# DAC value in mV
if val < 0:
val = 0
if val > 10000:
val = 10000
libioplus.setDacV(0, i+1, val/1000.0)

if __name__ == "__main__":
hardware_init()
while (not psm.should_quit()):
update_inputs()
update_outputs()
time.sleep(0.1) #You can adjust the psm cycle time here
psm.stop()




 
Reply 0 0
thiagoralves

With the blank driver you obviously will have no control of your IO as there is no driver to handle the IO for OpenPLC. In this case, OpenPLC runs as a soft-PLC. The logic is still there, but you don't see any action on the external world, unless you add slave devices.

It seems that PSM is disrupting the behavior of the persistent storage for some reason, as it works fine with the Raspberry Pi driver. The Raspberry Pi driver will treat each GPIO pin of the Raspberry Pi header as an individual IO that can be used according to the mapping on the openplcproject.com website. That's probably not the right mapping for your particular HAT.

The question of why PSM is disabling Persistent Storage remains a mystery. I'll investigate further and let you know.

Reply 0 0
rtuman
Thank you for looking into this!
Reply 0 0
rtuman
@thiagoralves
Were you able to look into the persistent storage problem with PSM?  Thanks
Reply 0 0
thiagoralves
@rtuman sorry for the delay on this. I've been putting my efforts mostly on the new beta version of the Editor and didn't have much time left to check this. But I finally managed to find the issue. It was a race condition on the persistent storage module. Drivers that took a little longer to initialize (which is the case for PSM) would make the runtime call persistent storage write before read, which means that the buffer was being written with zeroes before it was read from the file. I've already fixed the issue on github. If you just git clone and install the project again you should be good. Please let me know if it works for you.
Reply 0 0
rtuman
Thank you for getting back to me.  I'll try the fix and let you know the result.
Reply 0 0
rtuman
@thiagoralves
It did not work.

I re-installed the Home Automation software from github.com:

~$ git clone https://github.com/SequentMicrosystems/ioplus-rpi.git
~$ cd /home/pi/ioplus-rpi
~/ioplus-rpi$ sudo make install
~/ioplus-rpi$ ioplus
The program responded with a list of available commands.

After installing the software, I updated it to the latest version with the commands:
~$ cd /home/pi/ioplus-rpi
~/ioplus-rpi$ git pull
~/ioplus-rpi$ sudo make install

I reloaded the program and it started fine.  After I rebooted the RPi with the Home Automation HAT, the persistent variables went back to zero again.

What did I do wrong?  
Reply 0 0
thiagoralves
Well, this is not OpenPLC. You need to reinstall OpenPLC to get the latest OpenPLC code, not this.
Reply 0 0
rtuman
@thiagoralves
I reinstalled the OpenPLC runtime.  The persistent variables still went back to zero after I Stop/Start (or rebooted) the PLC.
The Runtime Log says:

OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
PSM: Starting PSM...
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued start_pstorage() command with polling rate of 10 seconds
PSM: Connected to PSM
Persistent Storage: Reading persistent.file into local buffers

Is OpenPLC_v3 still the right runtime to install?  Please help.
Reply 0 0
Reply