Parsing input parameters
bryan costanich
Posts: 29
hey all, i have a .net 2.0 winforms app that send info to the basic stamp and the stamp does some stuff based on the input. this works just fine. right now it's making an LED blink based on the number passed in. in the bs2 file i'm using:
SERIN 16, BAUD_9600, [noparse][[/noparse]DEC numberOfBlinks] ' receive one byte
like i said, this works fine. however, i want to send in multiple parameters. and before i go off writing a routine to parse input parameters and types and was wondering if anyone had already solved this in pBasic. if you have, i'd love to see your code, rather than having to sit down and write it myself.
also, if anyone wants the source code to the winforms app, i've attached it. note that it also listens for the output from the stamp (i'm sending back the iteration it's on) and displays that in the app.
i've also attached the bs2 file if you're interested.
SERIN 16, BAUD_9600, [noparse][[/noparse]DEC numberOfBlinks] ' receive one byte
like i said, this works fine. however, i want to send in multiple parameters. and before i go off writing a routine to parse input parameters and types and was wondering if anyone had already solved this in pBasic. if you have, i'd love to see your code, rather than having to sit down and write it myself.
also, if anyone wants the source code to the winforms app, i've attached it. note that it also listens for the output from the stamp (i'm sending back the iteration it's on) and displays that in the app.
i've also attached the bs2 file if you're interested.
Comments
One thing you could do is to pad your packet with a Header and use the WAIT modifier to catch that header and input a specific number of bytes and possibly a checksum value. Starting from a known point you could input multiple bytes into different variables for your different needs. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Jeff T.
Your program waits for a "?" character from the Stamp indicating it's ready to receive data.
Your program sends data in this format:
second string(1 character) indicates servo to adjust(1 thru 8)= "1"
third string indicates position to set servo(4 characters)= "0025"
fourth string indicates speed of rotation (2 characters) = "09"
The command string looks like this:· "!1002509"
The Stamp code looks something like this:
Redo:
······· DEBUG "?",CR· 'stamp requests·data from your program
······· SERIN 16, $4054, 5000, Redo,[noparse][[/noparse]WAIT ("!"),DEC1 servo,DEC4 position,DEC2 speed]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 2/13/2007 4:12:04 AM GMT
SERIN 16,16468,[noparse][[/noparse]HEX2 in_byte]
device=in_byte.HIGHNIB
command=in_byte.LOWNIB
Jeff T.
If you don't use pin port 16, you won't have that problem (echo). Use another pin port, since the echo will only appear on the programming port (pin port 16).
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
I make sure the input buffer is empty
I hold the length of my transmit string in a variable
then I wait for the input buffer to equal the length of the last transmit string
I discard that string as the echo
the next data recieved should be valid
Jeff T.