DIM x1,y1,toggle_1,toggle_2,connected,cnt DIM t AS double DIM Pkt_Out~(6) AS byte DIM Pkt_In~(6) AS byte DIM ip$ AS string DIM port% AS integer,found AS integer DIM chksum~ AS byte DIM title AS imageview title=graphics.newimageview(350,5) title.loaDIMage("title.gif") DIM bezel_1 AS imageview bezel_1=graphics.newimageview(385,615) bezel_1.loaDIMage("Bezel_1.gif") DIM bezel_2 AS imageview bezel_2=graphics.newimageview(595,615) bezel_2.loaDIMage("Bezel_2.gif") DIM bezel_3 AS imageview bezel_3=graphics.newimageview(200,660) bezel_3.loaDIMage("Bezel_3.gif") DIM logo AS imageview logo=graphics.newimageview(10,10) logo.loaDIMage("logo.gif") DIM img AS imageview img=graphics.newimageview(350,100) img.loaDIMage("AB_Ping.gif") DIM led_1 AS imageview led_1=graphics.newimageview(140,200) led_1.loaDIMage("LED_OFF.gif") DIM led_2 AS imageview led_2=graphics.newimageview(700,200) led_2.loaDIMage("LED_OFF.gif") Pkt_Out~(1)=1 t=System.ticks t2=system.ticks sensors.setAccelRate(0.01) !!!!Create textfields to transmit and display data values DIM transmit AS TextField,receive AS textfield,ipaddress AS textfield,port AS textfield receive=graphics.newtextfield(850,50,300) transmit=graphics.newtextfield(850,10,300) ipaddress=graphics.newtextfield(390,620,130,20) port=graphics.newtextfield(600,620,50,20) receive.setcolor(10,10,10) transmit.setcolor(10,10,10) ipaddress.setbackgroundcolor(1,1,1,0) ipaddress.setcolor(10,10,10) port.setbackgroundcolor(1,1,1,0) port.setcolor(10,10,10) ipaddress.setalignment(2) ipaddress.settext("192.168.1.1") port.setalignment(2) port.settext("9750") DIM sc AS segmentedcontrol sc=graphics.newsegmentedcontrol(400,500,200,30) sc.insertsegment("R/C",1,1) sc.insertsegment("Ping",2,1) sc.insertsegment("Light",3,1) sc.insertsegment("Halt",4,1) sc.setselected(1) sc.setstyle(3) sc.settintcolor(10,10,10) DIM ip AS segmentedcontrol ip=graphics.newsegmentedcontrol(400,550,200,30) ip.insertsegment("Connect",1,1) ip.insertsegment("Disconnect",2,1) ip.setselected(2) ip.setstyle(3) ip.settintcolor(10,10,10) DIM label_1 AS Label label_1=graphics.newlabel(750,15,80) label_1.settext("TX_Data") label_1.setcolor(10,10,10) DIM label_2 AS Label label_2=graphics.newlabel(750,55,80) label_2.settext("RX_Data") label_2.setcolor(10,10,10) DIM label_3 AS Label label_3=graphics.newlabel(360,618,80) label_3.settext("IP") label_3.setcolor(10,10,10) DIM label_4 AS Label label_4=graphics.newlabel(550,618,80) label_4.settext("Port") label_4.setcolor(10,10,10) DIM label_5 AS Label label_5=graphics.newlabel(125,665,80) label_5.settext("Status") label_5.setcolor(10,10,10) DIM label_6 AS Label label_6=graphics.newlabel(220,665,600,20) label_6.settext("Offline") label_6.setcolor(10,10,10) label_6.setbackgroundcolor(1,1,1,0) DIM label_7 AS Label label_7=graphics.newlabel(920,95,40,20) label_7.settext("0") label_7.setcolor(10,10,10) DIM label_8 AS Label label_8=graphics.newlabel(750,95,220,20) label_8.settext("Checksum error") label_8.setcolor(10,10,10) graphics.setcolor(0.2,0.2,0.4) graphics.fillrect(0,0,graphics.width,graphics.height) System.showGraphics(1) SUB connect ON ERROR GOTO 100 Comm.openTCPIP(1,ip$,port%) t=system.ticks WHILE system.ticks - t < 1 IF comm.isreadyforoutput(1) THEN found=1 connected=1 ipaddress.setenabled(0) port.setenabled(0) t=t-1 END IF WEND IF not found THEN ERROR 53 ELSE ERROR 0 END IF 100 IF err.number=53 THEN label_6.settext(err.descriptiON) ipaddress.setenabled(1) port.setenabled(1) close #1 connected=0 ip.setselected(2) ON ERROR GOTO 0 END IF END SUB SUB nullevent(time AS double) a = sensors.accel Pkt_Out~(2) = (a(1) * 128) + 127 Pkt_Out~(3) = (a(2) * 128) + 127 IF System.ticks-t>0.1 THEN IF connected THEN ON ERROR GOTO 200 print #1,"W"; chksum~=0 FOR i=1 to 5 chksum~=chksum~ + Pkt_Out~(i) NEXT Pkt_Out~(6) =(255-chksum~) FOR i=1 to 6 put #1,,Pkt_Out~(i) NEXT ON ERROR GOTO 300 chksum~=0 t=system.ticks WHILE system.ticks - t < 0.04 wend FOR i=1 to 6 get #1,,Pkt_In~(i) chksum~ = (chksum~ + Pkt_In~(i)) NEXT IF chksum~ <>255 THEN !! at the moment this is where it keeps count and displays checksum errors cnt=cnt+1 end IF label_6.settext("Online") 200 IF err.number=24 THEN label_6.settext(err.description) found=0 ERROR 0 END IF 300 IF Err.number=55 THEN connected=0 found=0 close #1 ip.setselected(2) label_6.settext(err.description) ERROR 0 END IF END IF DEBUG_DISPLAY t=System.ticks END IF ON ERROR goto 0 END SUB SUB valuechanged(ctrl AS control,time AS double) IF ctrl=sc THEN IF sc.selected=4 THEN Stop ELSE bitpos~=1<190 and x1<240 THEN IF y1>200 and y1<250 THEN toggle_led1 END IF END IF IF x1>760 and x1<810 THEN IF y1>200 and y1<250 THEN toggle_led2 END IF END IF END SUB SUB touchUpInside (ctrl AS Button, time AS DOUBLE) IF ctrl=quit THEN STOP END IF END SUB SUB toggle_led1 IF toggle_1=0 THEN led_1.loadimage("LED_ON.gif") toggle_1=1 Pkt_Out~(1)=Pkt_Out~(1) bitxor 16 ELSE led_1.loadimage("LED_OFF.gif") toggle_1=0 Pkt_Out~(1)=Pkt_Out~(1) bitxor 16 END IF END SUB SUB toggle_led2 IF toggle_2=0 THEN led_2.loadimage("LED_ON.gif") toggle_2=1 Pkt_Out~(1)=Pkt_Out~(1) bitxor 32 ELSE led_2.loadimage("LED_OFF.gif") toggle_2=0 Pkt_Out~(1)=Pkt_Out~(1) bitxor 32 END IF END SUB SUB DEBUG_DISPLAY transmit.settext(str(Pkt_Out~(1)) & " " & str(Pkt_Out~(2)) & " " & str(Pkt_Out~(3)) & " " & str(Pkt_Out~(4)) & " " & str(Pkt_Out~(5)) & " " & str(Pkt_Out~(6))) receive.settext(str(Pkt_In~(1)) & " " & str(Pkt_In~(2)) & " " & str(Pkt_In~(3)) & " " & str(Pkt_In~(4)) & " " & str(Pkt_In~(5)) & " " & str(Pkt_In~(6))) label_7.settext(str(cnt)) END SUB