about sending 1 email a time

BTCAD

Active Member
Hi,
 
I wrote this code today and i would like to know why I receive a lot of email.
 
OP3 is ''ON'' when the board is running
 
If IP1 is triggered during 2 sec --->
- set OP8 during IP1 is triggered + 5 sec
- set OP1 (blink)
 
If IP1 is not triggered -->
- set OP2 (blink)
 
 
I want an email when OP8 is triggered Only 1. This code send a lot of eamil and I don't know why.
 
This is my first PLC code ever so please don't laught of me! ^_^
 
code:
 
START
 
LOOP:
SET OP3 1
TSTEQ IP1[2000] 1
CALLSUB IN1_ON
TSTEQ IP1[5000] 0
CALLSUB IN1_OFF
SET RAM2 0
TSTEQ OP8 RAM1
TSTEQ RAM1 1 RAM1
GOTO ENVOIE_1
SET RAM2 0
GOTO LOOP
 
END
 
IN1_ON:
 
SET OP8 1
SET OP1 1
DELAY 250
SET OP1 0
DELAY 250
GOTO LOOP
 
IN1_OFF:
 
SET OP8 0
SET OP2 1
DELAY 1000
SET OP2 0
DELAY 3000
GOTO LOOP
 
ENVOIE_1:
 
BNZ RAM2 LOOP
SET RAM2 1
EMAIL EM1
GOTO LOOP
 
callsubs should end in     ret     not     goto loop
 
 
TSTEQ OP8 RAM1
TSTEQ RAM1 1 RAM1
 
the other thing i see in loop you never set ram1 befor it is checked
 
When you making call using CALLSUB, please make sure in the subroutine, use RET instead of GOTO at the end, so that stack will not overflow.
 
In your PLC code, you have these three lines:
TSTEQ OP8 RAM1
TSTEQ RAM1 1 RAM1
GOTO ENVOIE_1
 
Since RAM1 was never set to any value, it has zero in it during power on the board.  For each TSTxy command, if TST result is true, it will execute next line. When it is false, it will skip next line and execute the line after next line, which is the line sending email.
 
i don't under stand bnz but this is how i send email
 
 
START    
      SET VAR8 0 --when power comes on resets all
 
LOOP:
      CALLSUB RESETRAMS  
      DELAY 1000
      TSTGT T5 1050   --if temp is greater then 105
     CALLSUB SEND_EM1
     goto loop
     end
 

RESETRAMS:
                TSTLT T5 1040 --only if temp goes below 104 var8 will be reset if not it will stay var8 1
                SET var8 0  
                ret

 
 
 
SEND_EM1:
            TSTEQ VAR8 0 
            EMAIL EM1   
            DELAY 1000 --gives it time to send   
            SET VAR8 1 --set to 1 so only 1 email will get sent unless var8 is reset back to 0  
            DELAY 1000   
           CALLSUB PH_OFF   
RET 
 
CAI_Support said:
When you making call using CALLSUB, please make sure in the subroutine, use RET instead of GOTO at the end, so that stack will not overflow.
 
In your PLC code, you have these three lines:
TSTEQ OP8 RAM1
TSTEQ RAM1 1 RAM1
GOTO ENVOIE_1
 
Since RAM1 was never set to any value, it has zero in it during power on the board.  For each TSTxy command, if TST result is true, it will execute next line. When it is false, it will skip next line and execute the line after next line, which is the line sending email.
 
 
 
Okay so what should I do?
 
TSTEQ OP8 RAM1    -----here you ck if equal to
WHAT DO YOU WANT IT TO DO?
TSTEQ RAM1 1 RAM1  
GOTO ENVOIE_1
 
This is a bunch I found in the owner manual. I don't care the method to use, I just want to send only 1 email when OP8 is engage.
 
 
 
START   
            SET OP3 1
            TSTEQ IP1[2000] 1 
            CALLSUB IN1_ON
            TSTEQ IP1[5000] 0 
            CALLSUB IN1_OFF 
 
END 
  
IN1_ON:
             SET OP8 1 
             SET OP1 1 
             DELAY 250  
             SET OP1 0 
             DELAY 250
RET  

IN1_OFF:
            SET OP8 0 
            SET OP2 1 
            DELAY 1000  
            SET OP2 0 
            DELAY 3000  
RET  
 
 
BTCAD said:
I just want to send only 1 email when OP8 is engage.
 
You need to set a flag once the email is sent, and then test it each each time after that so the email is only sent once.
 
RAM is set to 0 at power up. Once the email is sent set RAM to 1 and test RAM each time through the loop.
 
    TSTEQ    RAM7 1
    RET
    EMAIL    EM4
    SET    RAM7 1
    RET  
 
/tom
 
callsub email_1:
 
tsteq op8 1
email em1
 
 
ret
 
okay that is supose to send an email if op8 is engage, right?
 
here you go try this, i used var's so you can see what it is doing then you can change it to ram when you see how it works
if you need i can try to explane better
 
 
Start  
   set var1 0
 
loop:
    callsub reset
    tsteq op8 1
    callsub email
    goto loop
    end
 
reset:
     tsteq op8 0
     set var1 0
     ret
 
email:
     tsteq var1 0
     email em1
     delay 100
     set var1 1
     ret
 
Back
Top