Decoding serial input
DiverBob
Posts: 1,110
It's getting late and my mind has decided it doesn't want to play anymore! A search through the forum didn't help so I'll ask here.
I want to output a series of numbers using the Parallax Serial Terminal object. The series will consist of a "T" for a start indication, a comma, a number, comma, and another number ("T",n,nnn). I can type the series into the serial terminal but my attempts at decoding it in the prop are falling flat. Any similar examples available out there?
Thanks
I want to output a series of numbers using the Parallax Serial Terminal object. The series will consist of a "T" for a start indication, a comma, a number, comma, and another number ("T",n,nnn). I can type the series into the serial terminal but my attempts at decoding it in the prop are falling flat. Any similar examples available out there?
Thanks
Comments
Well that's straightforward in Forth but you can do something similar in Spin by simply sitting in a loop which tests for digits and shifts them into an accumulator ( acc := (acc*10) + (char-$30). So when you encounter a non-digit you simply terminate with the result as the number. So this will work with commas or end-of-line but the T should be passed in a variable so that the app knows to disregard the result and synch or whatever. Not quite sure why you need to say "T" with the quotes though, it seems very redundant. Personally I would just use a symbol like a colon immediately followed by the first number :n,nnn
I'm a bit confused by your post. You say you want to output (from the Prop) data in the given format, but the title and subsequent comments seem to indicate an input (to the Prop) operation. Which is it?
-Phil
Last night I couldn't figure out how to parse the input string into its different components. This morning I'm doing better and have a couple of ideas to test tonight but as long as I've asked the question it would be nice to see how others have solved this type of issue. Oh yes, the T is just a transmit character to indicate the start of the command sequence, I just typed quotes around it, seemed like a good idea at the time...
That would be my starting point..
Massimo
EDIT: I tested it with PropGCC, and it works correctly on the Prop also.
Maybe someone else can see where I went wrong:The program as it stands works until I add in the commented out lines and then comment out the line teststr := string("$T,1,2,345")
SerialParsingTest - Archive [Date 2014.06.11 Time 21.34].zip
Check out this book and the associated code:
http://www.parallax.com/product/32316
ftp://ftp.propeller-chip.com/
There is a terminal project included there that contains some great token parser routine. Even without the book the code should be useful to you as it is well commented.
That worked! I went back and looked at the getstr() command in FullDuplex SerialPlus, don't know why I missed seeing that it needed a string pointer...
Thanks for the help. Now to get back to work on using the information!
The problem is when I attempt to assign the values to the Leg, command, and parameter variables. Here is the output I'm getting when entering a string of $,1,2,345 in to the program:
Hopefully someone will see what mistake I'm making here.
SerialParsingTest - Archive [Date 2014.06.14 Time 15.01].zip
John Abshier
John Abshier
See http://forums.parallax.com/showthread.php/122295-Converting-string-to-decimal?p=905112&viewfull=1#post905112
That should do it for you
You can find other relevant/useful links with the following google search:
https://www.google.ca/#q=string+to+integer+in+spin+for+propeller
Hope that helps!
Bill
Some Forum glitch. You need to replace attachment.php by the correct filename to save.
It is doing this for a while now. Filename always shows as attachment.php.
Enjoy!
Mike
That's the best thing about here, all the different ways to go about accomplishing the same goal. I learned a lot through this exercise and that was at least half the fun!