'The code below monitors all of the digital inputs and sends out a UDP 'packet if any of them change. The string that it sends contains the 'value of each digital input, with each separated by a comma. This 'can be easily imported into excel. Use the iplogger utility provided 'in the file section to listed for the packet. 'The code also toggles relay 1 every second. '----------------------------------- dim prev(8) 'declare an array for j = 1 to 8 prev(j) = 99 'initialize each array element to 99 (random #) next j udp1$ = "UDP:172.16.17.99:12345" 'set up connection string pack$ = "" 'initialize packet string to empty cos = 1 'set cos to 1 so that on power up, values are sent to server k=1 On TIMER1 GoSub 1000 'set timer handling routine Timer 1,100 'set up timer 1 to trigger every 100ms for event driven 'programming (subroutine at 1000) 10 for i = 1 to 8 inval = iostate(i+200) 'check state of input istr$ = sprintf$("%u",i) 'convert i to string val$ = sprintf$("%u",inval) 'convert input value to string if inval <> prev(i) then 'if value has changed cos = 1 'set bit to let us know prev(i) = inval endif if i < 8 then pack$ = pack$ + val$ + "," 'build string of values else pack$ = pack$ + val$ 'no comma after last value endif next i if cos = 1 then 'if an input has changed Open udp1$ as 1 'open udp connection Write 1,pack$,0,"172.16.17.99",12345 'send packet close 1 'close connection pack$ = "" 'reinitialize string to empty cos = 0 'rewrite change of state bit to 0 else pack$ = "" endif goto 10 1000 'this runs once every 100ms k = k * -1 if k > 0 then IOCTL 102,1 'close relay 1 else IOCTL 102,0 'open relay 1 endif Return END