Issues with SERIN
Grantus
Posts: 5
I am attempting to read in a serial packet that is being sent out from my computer program to the basic stamp....
The packet has a [noparse][[/noparse]HEAD],[noparse][[/noparse]COMMAND],[noparse][[/noparse]X],[noparse][[/noparse]Y],[noparse][[/noparse]TAIL]
Each part of this packet is a byte.
Head = 0x55 or ($55)
COMMAND = varies depending on command
etc..
Tail = 0xAA
No matter how i use the serin command in pbasic i alwarys seem to read in a hex value of like 7E or 7F????
I need to read in the serial message, if the first byte is a correct header then continue to read in the rest, check the tail, then perform the commands...
Is this possible with PBasic?
Grantus
The packet has a [noparse][[/noparse]HEAD],[noparse][[/noparse]COMMAND],[noparse][[/noparse]X],[noparse][[/noparse]Y],[noparse][[/noparse]TAIL]
Each part of this packet is a byte.
Head = 0x55 or ($55)
COMMAND = varies depending on command
etc..
Tail = 0xAA
No matter how i use the serin command in pbasic i alwarys seem to read in a hex value of like 7E or 7F????
I need to read in the serial message, if the first byte is a correct header then continue to read in the rest, check the tail, then perform the commands...
Is this possible with PBasic?
Grantus
Comments
You could leave out the tail byte, but it will give you a way to double-check the packet.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 12/15/2004 5:39:08 AM GMT
Cheers, i will give that a go...
Grantus
I am using a program called "Serial Monitior" to check that my program is sending the correct data... and i believe that it is ...
Something like 55 01 38 38 AA (55 header, 01 goto, x,y, AA tail)... and that seems correct.
See i am trying to write a program that will make a camera mounted on 2 servos track certain objects.
When the tracker finds something to lock onto it sends a GOTO command with a X and Y value to the stamp, which should then move my seros, and thus the camera....
my code so far :
... some definitions up here ...
pollLoop:
TOGGLE LED
SERIN Rpin, 9600,badData,2000,skipSerin,[noparse][[/noparse]WAIT(HEAD),sCommand,sXValue,sYValue,WAIT(TAIL)]
TOGGLE LED
DEBUG "-- Recieved Packet...",CR
GOTO processPacekt 'process packet do the specified command
' If nothing is recieved then resart the loop.
skipSerin:
DEBUG "-- Nothing ...",CR
GOTO pollLoop
' If bad data is recieved then resart the loop.
badData:
DEBUG "-- Parity Error ...",CR
GOTO pollLoop
GOTO pollLoop
... some other subroutines down here...
I'm guessing a debug statement....
You sure you have the declarations right?
debug HEX xvalue· ??· or is it signed HEX (SHEX)?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
http://www.geocities.com/paulsopenstage
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
WAIT(TAIL)
Once you've got the data you need, move on... unless you need that tailbyte?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
I have now taken the tail part out of the command...
I am sure that the data is being transferred is using 9600 baud. But how does one "DO" a baud of 9600 in the serin statement?
And im not sure whether the mode is true or inverted... how do i check this?
Cheers for your quick responses
Grantus.
(basically meaning that a digital 1 is represented by a -12V level in RS232; inversely, a digital 0 is represented by a +12V level).
TRUE would be a straight digital 1 = +5volts and vise versa....this is good for uProc to uProc communication as you don't need an rs232 level shifter in there (less hardware).
Look up the SERIN command in the Pbasic help file and it'll give a table with the values to use for your given needs.
This is what you used:
"SERIN Rpin, 9600,badData,2000,skipSerin,[noparse][[/noparse]WAIT(HEAD),sCommand,sXValue,sYValue,WAIT(TAIL)]"
Using your value of 9600 equates to somewhere near 7bits at 800baud.
So I wouldn't think it'd work!
Anyhow, for a BS2 with 9600 N81 Inverted...you should use this:
"SERIN Rpin, 16468,badData,2000,skipSerin,[noparse][[/noparse]WAIT(HEAD),sCommand,sXValue,sYValue,WAIT(TAIL)]"
It's nice to use a constant at the beginning of your program:
ie: N9600 con 16468
So your code line should look like:
"SERIN Rpin, N9600,badData,2000,skipSerin,[noparse][[/noparse]WAIT(HEAD),sCommand,sXValue,sYValue,WAIT(TAIL)]"
(that'll at least get you started...don't know about your scommand and waits and all).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
http://www.geocities.com/paulsopenstage
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
Grantus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office