//Run the program as fast as possible
#DIRECTIVE RUN_MAX_SPEED
 
Timestep OFF
VAR2 = 1
LOGFILE = "C:\iochange.log"
 
LABEL START
     //counter for all channels
     VAR2 = VAR2 + 1
     IF VAR2 = 0017 Then VAR2 = 1
     VAR3 = $IOIDLE(VAR2)
 
     //zero detected (I/O state changed)
     IF VAR3 = 0000 Then
          VAR3 = $ARRAY[VAR2]
          IF VAR3 = 0000 Then
               WRITELOG "<$xTIME> pulse train started on I/O $VAR2"
               ARRAY[VAR2] = 1
          END IF
     END IF
      
     //timeout (there was no pulse for 5 seconds)
     IF VAR3 > 0005 Then
          VAR3 = $ARRAY[VAR2]
          IF VAR3 = 0001 Then
               WRITELOG "<$xTIME> pulse train stopped on I/O $VAR2"
               ARRAY[VAR2] = 0
          END IF
     END IF
GOTO START

BACK TO SAMPLE OVERVIEW