Stoopid Net Trick
Dennis Crowley //

Lost? Back to the description of this project

' set up input and output buffers in memory:

dim outputBuffer(1 To 42) as byte 'remember, BX needs 9 bytes of its own // 42 bytes - 9 for bx = 31 chars in http GET command (see below)	
dim inputBuffer(1 To 11) as byte '9 bytes // 11 bytes - 9 for bx = 2 bytes for data from web page (which is only 2 chars anyway)	
' variables for dealing with incoming serial data:

dim bConnected as boolean 
dim 	gotaByte	as	boolean

dim	dataByte	as	byte
dim dataValue		as	byte
' strings for sending out through the CoBox:

dim	sendString 	as String
dim connectString	as String
dim sendGetInfo 	as String
' constants for the serial port and the ADC:	

const	serOutPin as	byte = 11
const	serInPin	as	byte = 12
'variables for CoBoxGame

dim inData as byte 
dim switchDown as byte 
dim helloString as String 

dim strData as String

Sub main() call delay(0.5) 'debug.print ":: start" debug.print "stage 2" bConnected = false 'connect to, port 80 connectString = "C128.122.253.189/80" & chr(10) debug.print "stage 3" ' set up serial port: call defineCom3(serInPin, serOutPin, bx1000_1000) ' open the input and output buffers: call openQueue(outputBuffer, 42) call openQueue(inputBuffer, 11) call openCom(3, 9600, inputBuffer, outputBuffer) ' connect: debug.print "stage 4" if bConnected = False then ' tell the coBox to open a connection: // this is basic serial shit from last semester call putQueueStr(outputBuffer, connectString) debug.print "connected" bConnected = True elseif bConnected = True then debug.print "connection = true" else 'added this before we figured out you could bump "Maxium String Length" in the BasicX env debug.print "connection = not getting into loop" end if 'add delays after the connect string (give the cobox some time to think)... call delay(0.5) sendGetInfo = "GET /~dc788/cobox/cobox.html" & chr(10) & chr(13) '31 chars + 9 for the bx = 40 buffer size call putQueueStr(outputBuffer, sendGetInfo) 'add delays after sending the GET command call delay(0.5) call doStuff end sub sub doStuff() do call serialCheck() call delay(1.0) loop End Sub sub serialCheck() ' find out if anything is in the queue. // gotaByte = true or false gotaByte = statusQueue(inputBuffer) debug.print cstr(gotaByte) if (gotaByte = true) then call getQueue(inputBuffer, dataByte, 1) strData = chr(dataByte) debug.print strData else 'if the bx starts spitting FALSE, then the buffer is empty. this sends the cobox back to refill the buffer call delay(1.0) call Main() 'i may need somthing here that CLOSES the connection end if end sub
(c) 2002, dennis crowley