Shop OBEX P1 Docs P2 Docs Learn Events
Help with parsing SERIN data — Parallax Forums

Help with parsing SERIN data

Kevin HarrisKevin Harris Posts: 15
edited 2005-07-03 17:27 in BASIC Stamp
I'm using a BS2 to receive coordinate data to drive servos for a color tracking program I've written.· I'm trying to figure out what the best way to send from the computer and receive to the BS2 in one shot an X and Y coordinate, both signed.· I need to formulate a good SERIN statement that can split up one piece of data into two signed coordinates.· I can make my computer send it in any format.· Anyone have any ideas?·· Thanks, Kevin Harris

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-03 17:27
    Are you planning to send in the Stamp's signed format (16-bit, two's compliment)?· If so, just accept the values as words, sent one byte at a time (usually low byte, then high byte).

    · SERIN Sio, Baud, [noparse][[/noparse]xCoord.BYTE0, xCoord.BYTE1, yCoord.BYTE0, yCoord.BYTE1]

    If you can send the data as a sting, like:

    · "-34, +27"

    ... then you can do something like this:

    · SERIN Sio, Baud, [noparse][[/noparse]SDEC xCoord, SDEC yCoord]

    The SDEC modifier converts a signed number sent as a string to a value.· You can add a WAIT modifier for synchronization if you need.· If your string was:

    · "Heading = -34, +27"

    ... then you could do this:

    · SERIN Sio, Baud, [noparse][[/noparse]WAIT ("ding ="), SDEC xCoord, SDEC yCoord]

    Note that the WAIT string is limited to six characters, hence the truncation.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.