Author Topic: Save value from slave during power loss  (Read 6518 times)

congo

  • Newbie
  • Posts: 16
  • I'm a llama!
    • View Profile
Save value from slave during power loss
« on: April 29, 2016, 10:44:10 AM »
If a slave PLC is being read by the master (via MB) and the slave loses power without backup memory installed, does anyone have a suggestion for saving the last good DM[] value in the master PLC?

For instance if a counter value (in slave PLC) is being read by the master into DM[] when the slave suddenly loses power the current number of counts is lost. Could a line of code be written to capture the counts continously but keep the last good value in this situation? Is there a code solution to this rather than installing extra memory in all the slaves?

Thanks.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Save value from slave during power loss
« Reply #1 on: April 29, 2016, 11:15:07 AM »
If you can define what you can considered as "invalid" counter value which is caused by the slave losing power, then you sure can save that last known data into non-volatile memory on the master.

That means you should capture the counter values into a temporary DM memory on the master, and then check how it compares with the previous stored value. If the value seems invalid (e.g. if the slave counter should be increasing and it suddens start from low value near zero, it probably suggest that the slave has been reset) then you need to either discard it or store the new value into a new location. You could even try to restore the last good counter values from the master to the slave using the WRITEMODBUS command. However, you have to decide if this make sense if the slave counter is already in motion and you could lose some counts.

E.g.

DM[100] = READMODBUS 13, 1, 1001   ' DM[100] is temporary location

Assuming the last good count was stored in DM[150]

IF (DM[150] - DM[100] > xxx)    ' differences too large to be valid
   .....   ' do something about the new value - discard or store
ELSE
     DM[150] = DM[100]     '   seems like good counter value, store it.
ENDIF





« Last Edit: April 29, 2016, 11:15:35 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

congo

  • Newbie
  • Posts: 16
  • I'm a llama!
    • View Profile
Re:Save value from slave during power loss
« Reply #2 on: April 29, 2016, 08:53:35 PM »
That worked well thanks. I also am testing to implement your suggestion for restoring the good count value in the slave, but having difficulty figuring how to write to the same DM[] as the slave HSC is.

In the slave PLC DM[1] =HSCPV[1], and the master is reading the same DM[1] for the count value. When I send a restored count from the master, DM[1] just gets overwritten by HSCPV[1] in the slave.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Save value from slave during power loss
« Reply #3 on: April 30, 2016, 09:27:28 AM »
You will need to perhaps write to a different location (E.g  X ) and inside your slave PLC program you can periodically monitor this X and if it is non-zero, you can then assign HSCPV[1] to it.

e.g inside a function that runs every scan:

IF X <> 0
    HSCPV[1] = X  
    X = 0       ' indicate that it is done.
ENDIF

Of course you can also use other numbers as a new data marker instead of zero if you ever need to send a zero to the slave HSC. E.g  

IF X <> -99999999 (an unlikely number)
     HSCPV[1] = X
     X = -99999999
ENDIF

Note that HSCPV[n] is a 32-bit variable. Unless your range of number is -32768 to 32767 you will need to use a 32-bit variable (e.g. DM32, which is formed by two adjacent 16-bit DMs) in the slave to assign to the HSCPV[].
Email: support@triplc.com
Tel: 1-877-TRI-PLCS