ganutenator
Lifetime Supporting Member
I will, but no one ever asked.
Any got the programming code to read the last plc stop on an M340 plc?
Any got the programming code to read the last plc stop on an M340 plc?
(*
Get the date and time of the last plc stop
/256 to get the high byte
mod 256 to get the low byte
*)
LastStopSec:= bcd_to_int(%SW54);
LastStopHrs:= bcd_to_int(%SW55 / 256);
LastStopMin:= bcd_to_int(%SW55 Mod 256);
LastStopMonth:= bcd_to_int(%SW56 / 256);
LastStopDay:= bcd_to_int(%SW56 Mod 256);
LastStopYear:= bcd_to_int(%SW57);
(*
get the sd reason
1 = change from RUN to STOP
2 = stop by Watchdog timer
4 = Power outage
5 = Hardware Fault
6 = Software Fault
*)
LastStopCode:= bcd_to_int(%SW58 Mod 256);
Case LastStopCode Of
1: sShutdownReason:= 'PLC changed from RUN to STOP';
2: sShutdownReason:= 'PLC Stopped by Watchdog Timer';
4: sShutdownReason:= 'Power Outage';
5: sShutdownReason:= 'PLC Hardware Fault';
6: sShutdownReason:= 'PLC Software Fault';
End_Case;
(*date to string*)
sLastStopMonth:= int_to_string(LastStopMonth);
sLastStopMonth:= RIGHT_INT(sLastStopMonth, 2);
sLastStopDay:= int_to_string(LastStopDay);
sLastStopDay:= RIGHT_INT(sLastStopDay, 2);
sLastStopYear:= int_to_string(LastStopYear);
sLastStopYear:= RIGHT_INT(sLastStopYear, 4);
(*time to string*)
sLastStopHrs:= int_to_string(LastStopHrs);
sLastStopHrs:= RIGHT_INT(sLastStopHrs, 2);
sLastStopMin:= int_to_string(LastStopMin);
sLastStopMin:= RIGHT_INT(sLastStopMin, 2);
sLastStopSec:= int_to_string(LastStopSec);
sLastStopSec:= RIGHT_INT(sLastStopSec, 2);
(*create string message*)
sShutdownMessage:= Concat_Str(sShutdownReason, ' ');
sShutdownMessage:= Concat_Str(sShutdownMessage,sLastStopMonth);
sShutdownMessage:= Concat_Str(sShutdownMessage, '/');
sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopDay);
sShutdownMessage:= Concat_Str(sShutdownMessage, '/');
sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopYear);
sShutdownMessage:= Concat_Str(sShutdownMessage, ' ');
sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopHrs);
sShutdownMessage:= Concat_Str(sShutdownMessage, ':');
sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopMin);
sShutdownMessage:= Concat_Str(sShutdownMessage, ':');
sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopSec);
(*looks to see if the message changed
if it did, set an alarm bit for the hmi*)
If sShutdownMessageLast <> sShutdownMessage Then
PlcSdAlarm:= true;
sShutdownMessageLast:= sShutdownMessage;
End_if;
Code:(*date to string*) sLastStopMonth:= int_to_string(LastStopMonth); sLastStopMonth:= RIGHT_INT(sLastStopMonth, 2); sLastStopDay:= int_to_string(LastStopDay); sLastStopDay:= RIGHT_INT(sLastStopDay, 2); sLastStopYear:= int_to_string(LastStopYear); sLastStopYear:= RIGHT_INT(sLastStopYear, 4); (*time to string*) sLastStopHrs:= int_to_string(LastStopHrs); sLastStopHrs:= RIGHT_INT(sLastStopHrs, 2); sLastStopMin:= int_to_string(LastStopMin); sLastStopMin:= RIGHT_INT(sLastStopMin, 2); sLastStopSec:= int_to_string(LastStopSec); sLastStopSec:= RIGHT_INT(sLastStopSec, 2); (*create string message*) sShutdownMessage:= Concat_Str(sShutdownReason, ' '); sShutdownMessage:= Concat_Str(sShutdownMessage,sLastStopMonth); sShutdownMessage:= Concat_Str(sShutdownMessage, '/'); sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopDay); sShutdownMessage:= Concat_Str(sShutdownMessage, '/'); sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopYear); sShutdownMessage:= Concat_Str(sShutdownMessage, ' '); sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopHrs); sShutdownMessage:= Concat_Str(sShutdownMessage, ':'); sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopMin); sShutdownMessage:= Concat_Str(sShutdownMessage, ':'); sShutdownMessage:= Concat_Str(sShutdownMessage, sLastStopSec); (*looks to see if the message changed if it did, set an alarm bit for the hmi*) If sShutdownMessageLast <> sShutdownMessage Then PlcSdAlarm:= true; sShutdownMessageLast:= sShutdownMessage; End_if;