Multi-Byte ascii to Word conversion - SERIN
Steel
Posts: 313
Hey, all.· Hit a bump and need a boost.
I am using the SERIN command to bring in Ascii.
I am putting in a Value say "32" (ascii)·into a software application.
That application sends the value over RS232 as "33 32" (Hex equivalent)
The BS2·is retrieving the value using·
Variable var Word
SERIN 16, Baud,[noparse][[/noparse]Variable.HighByte, Variable.LowByte]
Is there a way to convert "Variable" which should now contain "33 32" into the value "32"?
*note.· This needs to work if· the user puts in "102" as well...
Thanks.
·
I am using the SERIN command to bring in Ascii.
I am putting in a Value say "32" (ascii)·into a software application.
That application sends the value over RS232 as "33 32" (Hex equivalent)
The BS2·is retrieving the value using·
Variable var Word
SERIN 16, Baud,[noparse][[/noparse]Variable.HighByte, Variable.LowByte]
Is there a way to convert "Variable" which should now contain "33 32" into the value "32"?
*note.· This needs to work if· the user puts in "102" as well...
Thanks.
·
Comments
"102" would come across as "31 30 32"?
Post Edited (PJ Allen) : 2/2/2006 12:47:27 AM GMT
· SERIN Sio, Baud, [noparse][[/noparse]DEC myVal1, DEC myVal2]
One caveat: DEC gets terminated by a non-numeric character, so you might want to append a space after all numbers -- your output string would then look like this:
· "32 32 "
Or, if you are always sending two-digit values you could replace DEC with DEC2.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax