Shop OBEX P1 Docs P2 Docs Learn Events
How to read 16 comma-delimited hex2 values with SERIN? — Parallax Forums

How to read 16 comma-delimited hex2 values with SERIN?

Al3Al3 Posts: 6
edited 2013-08-14 13:59 in BASIC Stamp
I have this array
MemData VAR Byte(16)


1) I would like to send the following string and read it with SERIN or whatever appropriate command into above array.
"01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,FF"


2) How would it be done if 16 values were not separated with commas?
"0102030405060708090A0B0C0D0E0FFF"

Thank you.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-08-14 13:59
    The HEX2 formatter reads two hexadecimal digits and converts that to a single byte value. Your 2nd case is easiest and would be done using a loop as follows:

    FOR i = 0 to 15
    SERIN <pin>,<BaudValue>,[HEX2 MemData[ i ]]
    NEXT

    Your 1st case depends on how the last value is delimited. You have a comma as the delimiter for all but the last value. It's easier if you use a space or carriage return as the delimiter for the last value:

    FOR i = 0 to 15
    SERIN <pin>,<BaudValue>,[HEX MemData[ i ]]
    NEXT

    Read the description of the various input formatters in Appendix C of the Basic Stamp Syntax and Reference Manual to get the details of how these work.
Sign In or Register to comment.