//Mail checking script
//+ IO channel 12 lights when connected to server
//+ IO channel 13 lights when there is mail
//+ IO channel 14 lights when there is an error
 
 
//make connection, use events to detect acception
Timestep OFF
 
LABEL LOOP
     IF CONNECTED = 1 Then
          SETIO 12
     ELSE
          CLEARIO 12
     END IF
 
     //check mail only if I/O channel 1 is set
      IF IO01 = 1 Then
          ClearIOn 0000000011111111
          CONNECT TCP,ENTER-SERVER-HERE,110
          LABEL WAIT_FOR_OFF
          IF IO01 = 1 Then GOTO WAIT_FOR_OFF
     END IF
GOTO LOOP
 
 
 
SUB EVENT_CONNECTION_ESTABLISHED
     //set receiving level to 0
     VAR1 = 0
END SUB
 
 
 
 
SUB EVENT_CONNECTION_DATAARRIVAL
     //increase receive level counter
     IF VAR1 < 0004 Then VAR1 = VAR1 + 1
 
     IF VAR1 = 0001 Then
          //server sends +OK to the client,if succeed
          TEXTVAR = "+OK"
          IF TEXTVAR isin INDATA Then
               //+OK was found
               SEND "user ENTERYOURUSERNAMEHERE"
               EXIT SUB
          ELSE
               //+OK was not found. set error light an disconnect
               SETIO 14
               DISCONNECT
               EXIT SUB
          END IF
     END IF
 
 
     IF VAR1 = 0002 Then
          //server sends +OK to the client,if succeed
          TEXTVAR = "+OK"
          IF TEXTVAR isin INDATA Then
               //+OK was found
               SEND "pass ENTERYOURPASSWORDHERE"
               EXIT SUB
          ELSE
               //+OK was not found. set error light an disconnect
               SETIO 14
               DISCONNECT
               EXIT SUB
          END IF
     END IF
 
 
     IF VAR1 = 0003 Then
          //server sends +OK to the client,if succeed
          TEXTVAR = "+OK"
          IF TEXTVAR isin INDATA Then
               //+OK was found
               SEND "stat"
               EXIT SUB
          ELSE
               //+OK was not found. set error light an disconnect
               SETIO 14
               DISCONNECT
               EXIT SUB
          END IF
     END IF
 
 
     IF VAR1 = 0004 Then
          //server sends +OK to the client,if succeed
          TEXTVAR = "+OK 0 0"
          IF TEXTVAR isin INDATA Then
               //new mail!
               CLEARIO 13
               DISCONNECT
          ELSE
               //no new mail!
               SETIO 13
               DISCONNECT
          END IF
     END IF
 
 
END SUB
 
 
 

BACK TO SAMPLE OVERVIEW