do programmers share code?

ganutenator

Lifetime Supporting Member
Join Date
May 2002
Location
kansas
Posts
1,440
I will, but no one ever asked.

Any got the programming code to read the last plc stop on an M340 plc?
 
Code:
(*
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;
 
Gauter, do you come from O hi am l.
just taking the mickey (not the " Mickey").
You most probable have now looked at the downloads, and if it hasn't got Lances name beside it, take it with a stiff drink or something else.
Me, personal, myself, as an individual, l find your humour refreshing (except when you take criticism as personal criticism and the bong hits the keyboard).
Keep the quirky up in the New Year.
I wish for all, a peaceful and prosperous and all dreams a reality year to come for all of us, including some who wish us harm, so they can see their error in ther ideology. Regards
Kevin
 
the rest

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;
 
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;

Actually this is Last PLC boot. If PLC goes only to stop, then there is no way write PLC stop moment to variables :whistle:

There is also inbuild block PTC for this
 
PTC block reads same system words

PTC

Output: Array [0..4] of int

Table of 5 integers containing the date in the first four words (equivalent of %SW54 to %SW57) and the error code in the last word.

The error code is the one indicated in the %SW58 system word:
1 = switch from RUN to STOP by the terminal,
2 = stop on software fault (PLC task overflow),
4 = mains power cut,
5 = stop on hardware fault,
6 = stop on HALT instruction.

Example: Stop at 22:53:10 on January 8, 2001. The contents of Stop_Date were as follows:
Stop_Date[0]=16#1000
Stop_Date[1]=16#2253
Stop_Date[2]=16#0108
Stop_Date[3]=16#2001
Stop_Date[4]=16#0006
 
cool
another way
I do prefer the roll your own
plus i learned a new trick w/ the modulus 256 thingy.
thank you bill ebie from schneider
 
probably should do the message conversion in the hmi though so that the hmi doesn't have to read a string of length 52
 
it works though.
is it legit enough to put in the modicon download section?
p.s. i'm not the smartest guy on here
 

Similar Topics

Good morning all. I'm working on a rehab where they had a standalone InTouch 2014 HMI that they called a SCADA, but it's really basic stuff. The...
Replies
4
Views
190
Yes or now and if yes what would you include or test for as a minimum standard? I can think of things like DeMorgan's theorem Karnaugh maps -...
Replies
60
Views
23,173
Just wanted to get some thoughts on dealing with co-workers who go off script. We are a large manufacturing facility with multiple/ similar...
Replies
93
Views
42,335
Hi All, Looking for someone to help one of my customers with a very old Siemens S5 PLC that we need to try and get up and running again while we...
Replies
8
Views
2,091
Back
Top Bottom