Shop OBEX P1 Docs P2 Docs Learn Events
SERIN WAIT question — Parallax Forums

SERIN WAIT question

CheetahCheetah Posts: 26
edited 2007-10-12 15:36 in BASIC Stamp
I need monitor a serial line for strings, for example "@1|dda" and "@2|da".
If I don't get either of these sequences with 30 seconds I need to timeout
from the SERIN command and go on to other things and then come back and
check again later. Is it possible to WAIT for 2 strings using the SERIN command?

Comments

  • BeanBean Posts: 8,129
    edited 2007-10-11 16:40
    The TIMEOUT option only waits if the line is idle.
    If there is data coming in, it will wait forever for the WAIT string.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My goal is to live forever...Or die trying.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • CheetahCheetah Posts: 26
    edited 2007-10-11 16:44
    Yea, I just noticed that. Hmm....
    I'm using the stamp as a watchdog to monitor activity on a serial line.
    Actually I don't need the timeout option. I just need to make sure that
    I receive either of these 2 strings at least every 30 seconds. Any ideas
    how to approach that?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-11 16:46
    A lot depends on exactly what kinds of strings you are expecting. If, for example, the strings always start with "@" and end with a single "a", this is doable. You would use a WAIT("@") formatter, then STR bytearray\5\a to read up to 5 characters into a byte array of length 5 terminated by the first "a". You'd then have to check the byte array to make sure the format was correct. You'd still use a timeout, but keep in mind that, if the timeout occurs in the middle of receiving the data, what has come in so far is possibly lost and anything that comes in while you're doing other things will be ignored.

    You can't WAIT for either of two different strings.
  • DgswanerDgswaner Posts: 795
    edited 2007-10-11 16:48
    you could have the wait command look for "@" but you might get false positives, do you have the luxury of changing the the string that are coming in? if you could have 2 or more common characters at the beginning of the strings say "@@" that should be reliable enough to work well. so your wait command would wait until it received @@, not have to monitor for 2 different strings. my 2¢

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A complex design is the sign of an inferior designer. - Jamie Hyneman, Myth Buster
  • CheetahCheetah Posts: 26
    edited 2007-10-11 17:02
    I see. Thanks for the suggestions.
    All of the data coming across begin with a '@' and end with a '#'.
    So I guess I could wait for a '@' and receive up to the '#' and then
    check the string for what I'm looking for. There is a lot of traffic
    on the line so I just need to make sure i get these 2 strings at
    least every 30 secs. Any ideas on how to handle this 30 second thing?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-11 17:16
    Again, it's important to remember that the Stamp will not see any of the traffic on the serial line that occurs while the Stamp is executing anything other than the SERIN. It's possible that one or both of these strings will be missed by the Stamp. There are some 3rd party serial buffers that will buffer any serial input up to 32 bytes and download it to the Stamp on request.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-11 17:21
    Because of the lack of buffered I/O, the Stamps are not well suited to monitoring a serial line. One serial buffer is www.protean-logic.com/tickit/rsb509B_HTML_Cutsheet.htm. Have a look at the description.
  • CheetahCheetah Posts: 26
    edited 2007-10-11 17:32
    OK. I understand now.
    Thanks for the help and I'll take a look at a serial buffer.

    Take care.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-10-12 15:36
    Mike Green

    One serial buffer is www.protean-logic.com/tickit/rsb509B_HTML_Cutsheet.htm. Have a look at the description.

    Thanks For sharinng this·with use that just might work for a project that i put on hold because of having·the same type of prolbem that Cheetah·is having in what (he/she) is trying to do..........smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.