Shop OBEX P1 Docs P2 Docs Learn Events
How to read between the stars — Parallax Forums

How to read between the stars

PVJohnPVJohn Posts: 60
edited 2006-02-27 15:31 in BASIC Stamp
Hi, I need to read a string from serial input pin of unknown lenght, but it is terminated with CR. String is very simillar to GPS output, but values are separated by "*" (ASCII 42). Something like this: 43.023*23*239.65***43*2****6 CR.
How can I read·values between those stars and skip those without any value between them.
Thanks,
PVJohn

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-26 11:54
    PVJohn -

    I'm not sure you know enough about your data, to parse it very efficiently, or possibly at all. Part of the answer here may depend on which Stamp plaform you are using. Are you using a Stamp BS-2 or some more advanced Stamp than that (BS-2SX, BS-2p, etc)?

    The real underlying question here is whether you have SPSTR available to you. More information can be found about SPSTR in the PBASIC Stamp manual or the PBASIC Help File in the SERIN formatters area.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-26 21:56
    Well, depending on the baud rate, etc. you could use the DEC formatter on SERIN.· It terminates numeric input at non-numeric characters.· You would most likely need to know how many valid numbers you have coming in though and the baud rate would probably need to be 2400 bps unless you had a faster Stamp Module.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • PVJohnPVJohn Posts: 60
    edited 2006-02-27 06:52
    I'm using BS2px with Max 233 at 2400 (to be on safe side), and I was thinking to check if incoming data is different from ASCII 42. If it is, then I would start a counter (for data and memory location) and store data in EEPROM. It would count until next (ASCII 42) comes. After that, by using values from the counter I could retrieve what I need and restarted counter. I tried to do this, but I got confused with those two loops. If you have a sample code to do this, it would be a great help.
    Sincerely,
    PVJohn
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-27 08:35
    Even with the BS2px speed I think you'd be taking a chance at missing bytes; Chris's solution is really best suited for what you want to do. The BS2px will handle the conversions for you, all you have to do is decide which of the fields you want to capture.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • neotericneoteric Posts: 144
    edited 2006-02-27 15:31
    IN REFERENCE TO MISSING BYTES:·· I had a similar situation, and here is what I did to solve it.· Perhaps it could help you.

    I have a device that delivers serial data very fast.· I·did not need to collect all the data, just need to know where it is at when I poll it.· (it sends a serial formatter, and x position, and a y position).This particular device had no handshaking, and delivered data at 9600.·· It just sent the data out, over and over....

    I recieved the string, then I ignored any strings that did not begin with the correct beginning data.· I think you would need to do something like that, with data somewhere in that string you can compare on.· This worked beautifully for me.

    recieve string (fixed length)

    does string have correct data in it?

    if yes, proceed

    if not, goto recieve string

    usually just getting the string twice was enough.....

    DO
    SERIN RX, baud,[noparse][[/noparse]STR whatsit\5]·········· ''· use 16 for main serial input (programming port)
    IF whatsit(0) = 137· THEN··············· ''· correct string always begins with 137
    DEBUG DEC x," - ", DEC y,"·· ",DEC finx,"··· ", DEC finy,CR· 'View results on PC Screen· Works'
    ENDIF
    LOOP

    Post Edited (neoteric) : 2/27/2006 4:20:18 PM GMT
Sign In or Register to comment.