agarciaoteros
Hi,
I would like keep values of outputs after reboot, I have very simple logic.
 
Captura.jpg
 
I have my own hardware layer for my HW (BeagleBone with Debian).
I can read last status of outputs throught i2c and drivers IO after reboot, I would like restore these value of outputs.
Somebody could suggest to me ways to do that.
Thanks in advance.
Reply 0 0
thiagoralves
OpenPLC always resets all outputs to zero (or whatever default state it was programmed to be) upon restart. It wouldn’t be safe to do otherwise. The only way to preserve values through reboots is to programmatically enforce it using Persistent Storage. You can enable Persistent Storage on the runtime settings. This will preserve all your %M variables in a file on disk that is loaded back every time the runtime starts. Then on your PLC logic you must create a first scan logic that will drive your outputs depending on what is stored in your %M variables
Reply 0 0
fg71
The way I see it...
 
  1. Store data to EEPROM
  2. After reboot, read the data from EEPROM
When you use EEPROM library for your board you could clear, write and read to it. In OpenPLC Editor you could use Arduino extension
to setup your output variable state to write to your EEPROM for your board. When you reboot your hardware the it will read the state
from the EEPROM.
 
Here is a example in Nano Esp32
 
  1. First you make a sketch to write HIGH to pin 13 (LED_BUILTIN) there you include EEPROM.write(address, value);
  2. The address is byte and the value is the state of your output.
 
Now you could run this sketch to read the state in EEPROM and write the state to the pin.
This will give you some ideas how you could do that in Arduino extension.
 
You could visual the reading of EEPROM by upload empty sketch to your board and next run the script below.
In other words if the EEPROM address 0 store byte 1 then it will write that to pin 13.
 
I'm not the person to suggest but maybe a simple approach would be to change hal .cpp to include EEPROM read and write
 
#include <Arduino.h>
#include <EEPROM.h>

#define ADDRESS 0
#define EEPROM_SIZE 1
int ledState;

void setup()
{
  Serial.begin(9600);
  EEPROM.begin(EEPROM_SIZE);

  pinMode(LED_BUILTIN, OUTPUT);

  ledState = EEPROM.read(0);
  Serial.println(ledState);
}
  
void loop()
{
  // write the current state to the pin
  digitalWrite(LED_BUILTIN, ledState);
}
 
Reply 0 0
thiagoralves
EEPROM only works on Arduino-compatible boards. The OP is using a BeagleBone board running Linux. In that case the only option available for him is Persistent Storage. It will work similarly to the EEPROM approach, although the saving and restoring is done under the hood automatically for the user.
Reply 0 0
agarciaoteros
Thanks for your answers. I try to solve like you recommend to me. I have created this Ladder programm:
[203128%2F9067062%2Fmceclip0]
 
 
Where I try to save each output under %MW variable.
I see that save well under persistent.file
[203128%2F9067064%2Fmceclip0]
 
But whe I try to restore values of this file, stop and start program,
I see that read well values
 
[203128%2F9067065%2Fmceclip0]
 
But later dont apply this changes:
[203128%2F9067071%2Fmceclip0]
 
I think that I did something wrong, could you give some light... Thanks in advance.
Reply 0 0
thiagoralves
Since INIT_VAR_MEM takes 2 seconds to be true, in the first scan cycles the value of your mem variables are all replaced with zero. Remember that a false contact does not disable the rung, it just makes the rung evaluate to false (zero).
Reply 0 0
agarciaoteros
Works , thanks a lot for your help.
 
I would like you to give me your opinion about my device.
I want to save the last state to restore the value of the outputs in case of a reboot,
 
Using the Persistence functionality, but I know that the eMMC can be corrupted if I force it too much (writes)
What is your point of view, how can I resolve it. My device is a clone of the Beaglebone Black.
Thanks in advance.
Reply 0 0
thiagoralves
You can adjust the rate at which Persistent Storage will make a copy of your variables. The default is 10 seconds, which is not very often, so you should be good. If you want to be extra cautious you can increase this rate to anything you want. Also, since the data is quite small (just a few hundred bytes), there is a great chance your eMMC will be smart enough to just alternate banks so not to wear up your storage too quickly.
Reply 0 0
Reply