Shop OBEX P1 Docs P2 Docs Learn Events
Interpreting received data (RS232, ASCII, BS2) — Parallax Forums

Interpreting received data (RS232, ASCII, BS2)

Grant_OGrant_O Posts: 36
edited 2006-02-19 08:22 in BASIC Stamp
hi, i was just wondering if anyone knows how to interpret incomming·ASCII strings·and use them in commands with a BS2. Im running a SimpleStep stepper motor·controller that i can call on through RS232 for information on settings and current position. but all of its information is not just numbers, in the begening of·its response string Theres (d9<) then the number or characters i need. basicly if i wanted to do a command similar to this:

IF "SERIN" = d9<1000·THEN (something)

(d) = external·devices·prefix response
(9) =·external·devices network number
(<1000) = external·devices data string

what would i need to do to seperate the string?

thanks:

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-19 01:34
    You would use the "STR" modifier if it's coming in ASCII, and the "DEC" modifier if it's coming in as an ascii (displayable) number.

    So:
    D_BYTE VAR BYTE
    Nine_Byte VAR BYTE
    NumVal VAR WORD

    DoAgain:
    SERIN StepPin, 16384, [noparse][[/noparse]D_Byte, Nine_Byte, wait("<"), DEC NumVal]

    IF D_Byte <> 'd' THEN DoAgain
    IF Nine_Byte <> '9' THEN DoAgain

    SEROUT 16, 16384, [noparse][[/noparse]"Got ", DEC Nine_Byte, 13]
    GOTO DoAgain


    I believe the DEC modifier wants a comma, space, or line-feed to end the token.

    Oh, and note that "16384" will have to be modified to be the baudmode select value for your BS2 'flavor'.
    You want "Inverted, 9600" for the PC (SEROUT 16).· I don't know what the baud rate is for your device,
    nor the pin.· Look it up in the manual under "SEROUT".
  • Grant_OGrant_O Posts: 36
    edited 2006-02-19 08:22
    Thanks, those are the commands i really needed. now i have to play around with them and see what i can do.

    dont worry bout the baud rates, i figured them out the hard way but now iv learned how to calculate them.

    again thanks allenlane!
Sign In or Register to comment.