Shop OBEX P1 Docs P2 Docs Learn Events
Multi-Byte ascii to Word conversion - SERIN — Parallax Forums

Multi-Byte ascii to Word conversion - SERIN

SteelSteel Posts: 313
edited 2006-02-02 00:44 in BASIC Stamp
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.
·

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-02 00:44
    Are the numbers actually sent with a SPACE between them?
    "102" would come across as "31 30 32"?


    Post Edited (PJ Allen) : 2/2/2006 12:47:27 AM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-02 00:44
    Yep, use the DEC modifier (make sure you're not running faster than 9600 baud -- the BASIC Stamp needs the stop bit time to do the inter-byte processing).· Like this:

    · 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
Sign In or Register to comment.