reading SERIAL port with SERIN
I'm just getting started with PBASIC, but prtty good at Visual Basic.· I wrote a PBASIC program to scan a servo back and forth to pan a webcam back and forth.· It also has the ability to step left, step right and center.· On the scan command it should scan back and forth until it sees a new command to do something else.· The command are simply 1(step left), 2(step right), 3(center), 4(scan).· It uses SERIN to get the command from the SERIAL prot written by a VB program with a GUI interface that shows the webcam and has 4 control buttons to send the commands to the SERIAL port.
So all this works fine, except the PBASIC code for scan does a SERIN read after each scan to see if it should continue scanning or do something else.· After a left/right scan I do another SERIN to see if a new command is present.· Problem is if I hit Center in teh VB program for instance during the scan, when the scan is done the SERIN command just waits for a command.· I put in a timeout in SERIN and if i send a VB command during the wait period the PBASIC accepts the command properly.
I am assuming this means that SERIN must see an "interupt" from the SERIAL port to read.· Sending a command then reading with SERIN doesn't work.
Is it possible to read a "pre loaded" command on the SERIAL port with SERIN?
This may be too confusing, so ask.
Thanks
John
So all this works fine, except the PBASIC code for scan does a SERIN read after each scan to see if it should continue scanning or do something else.· After a left/right scan I do another SERIN to see if a new command is present.· Problem is if I hit Center in teh VB program for instance during the scan, when the scan is done the SERIN command just waits for a command.· I put in a timeout in SERIN and if i send a VB command during the wait period the PBASIC accepts the command properly.
I am assuming this means that SERIN must see an "interupt" from the SERIAL port to read.· Sending a command then reading with SERIN doesn't work.
Is it possible to read a "pre loaded" command on the SERIAL port with SERIN?
This may be too confusing, so ask.
Thanks
John
Comments
This can be take valuable program time·which can be optimized. One way would be to transmit a "ready" command from the Stamp just before the SERIN.
example
SEROUT tx,baud,[noparse][[/noparse]"RDY",CR]
SERIN rx,baud,100,timeout,[noparse][[/noparse]data]
the RDY would be captured with the OnComm or DataReceived event depending on your version. Timeout gives VB time to respond, if no response the program continues.
Jeff T.
EDIT: which agrees with Mike's posting
http://www.rhombus-tek.com/co-processors.html
The "Simple Multi-Tasking" processor provides a recieve-only serial buffer of 11 bytes, which works without needing a MAX-232 or anything.
Post Edited (allanlane5) : 8/29/2007 1:31:10 PM GMT