Simple time delay E-Mail

rfeyer

Active Member
Finally starting to learn about PLC.
 
For a simple - send an e-mail every 30 min code, does the following look correct?
 
Start
  callsub periodic
 
periodic
  delay 180000
  email EM1
ret
 
 
Also, is it possible to specify that Temp and Humidity values should be sent ONLY in message body or Subject (i.e.: is it possible to have variables embedded in e-mail subject field)
 
 
Rainer
 
 
You always first type in first two lines:
START
END
 
then plugging your logic and subroutines in proper position.  I think your above code missed END
 
TY
That said, END being needed, would the code do what I intended it to? Send an E-Mail every 30 minutes?
And, is it possible to add certain info as variables into the Subject line 9such as TP1)?
 
Raienr
 
In each email, it contained all the IO values, unless you configured it not send them.
In the email header, it also has host name and time stamp inside.
 
Surely, if you block delay for 30 minutes, it will send once every 30 min or so.
However, the rest 29 minutes, it does nothing, but waiting.  A lot of time, people would not use delay 30 minutes, since you may have other tasks to do in PLC during that 30 minutes.
 
Ah - did not realize it is totally static during that time.
So it would make more sense to use the CH or CM function.
I will work on that - TY!!
 
Rainer
 
I looked at the sample codes again, and, maybe this would do the trick? Again, trying to send one e-mail every hour with Temp/ Humidity information. As it sounds, the T1 H1 values can not be embedded into the e-mail's subject line.
 
START
  CALLSUB HOURLY
END
 
HOURLY:
  TSTNE RAM1 CH
  GOTO T1
RET
 
T1:
  SET RAM1 CH
  EMAIL EM1
RET
 
During blocking delay, which is PLC DELAY command, PLC will not execute next command.  All other parts, like IOs still operates, just could not be controlled by PLC instructions, since PLC instruction is waiting delay to finish.
 
There is non-blocking delay with IO and VAR, or like you said, using CM and CH would be good, too.  Please make sure your logic including a flag indicate email has been sent already for that period.  Then has other logic reset that flag once the 30 minutes condition no longer meeting.
 
In your code, you use GOTO to label, that does not act like you expected.  GOTO and CALLSUB are different, GOTO does not RET, just execute command from new address -- starting from that label. CALLSUB push down an address pointer, RET pop up back to where was called before.  mix GOTO and CALLSUB, your stack might get confused later on.
 
TY Support!
 
2 questions:
  1 - does the RAM1 = CH not reset the flag since HOURLY: checks if RAM1 not = CH ? Is another flag needed?  Actually, the current code is sending 2 e-mails, this may be the reason
2 - Am I understanding correctly:
    CALLSUB goes to subroutine and returns where it started from at RET
    GOT goes to Subroutine but doe  NOT return to where it was called from even with RET statement?
 
Rainer
 
Yes another flag is needed indicating your job is done and you need to check it to see if you need to do your job again.
 
You need to think about CH. If you used lines of code to detect CH = 5, how often would that happen?
  It would happen thousands of times between 5:00 AM and 5:59:59 AM. Not every hour.
 
 
CALLSUB is to call a subroutine that will return.
  The return address of the "program counter" is pushed onto a memory "stack".  RET pulls it off again. The "stack" must be maintained or it will overrun your memory and take over areas it shouldn't, or underrun your memory and RET to places unknown.
 
GOTO is not for a subroutine call but rather to just "jump" somewhere else. Current "program counter" location is not kept or used.
 
I would just use one flag to indicate email sent.
then reset that flag when MOD CM by 30 != 0.  So when the time should not sent email, this flag being reset a lot, but that is okay.
But once CM MOD by 30 == 0, it will send one email if flag not set, then after email sent, set the flag.
This will take a bit in RAM1
 
I went over the code again, and, am confused:
 
 TSTNE RAM1 CH 
Isn't this to see if CH is NOT equal, would that not be the flag that stops recurrent emails in the same hour; i.e.: only send email if CH is actually different?
 
Rainer
 
When you compare TSTNE, it will set ZEROBIT to indicate the result is true or false.
However, with next instruction executed, the ZEROBIT will reflect next execution, NOT previous state.
you can not use ZEROBIT for your email sent flag because that is always changing based on each execution. A dedicate flag for indication that thing done is  A must.
 
I hope I am not a pain, but I do not understand the ZEROBIT concept - I will start a new thread with my questions on that.
The above code is currently working; I will build in a flag when I understand the ZEROBIT concept.
Hope I am not asking too many question,
 
Rainer
 
The ZERO BIT is just an internal PLC flag to carry the results of tests so that a branch or goto can use it to decide on it's course of action.
 
 
TSTEQ  RAM1  5
   this does a "mental" subtraction,  RAM1-5 = ??
   The ZERO BIT is set if the answer is 0
 
SUB  RAM1  5
  same results
 
Back
Top