Shop OBEX P1 Docs P2 Docs Learn Events
rxtime or rxcheck question — Parallax Forums

rxtime or rxcheck question

steprogsteprog Posts: 227
edited 2010-12-02 03:59 in Propeller 1
Hi Guys,
Does rxtime or rxcheck corrupt the incoming string if you use it?
Thanks,
Greg

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-12-01 23:57
    steprog wrote: »
    Does rxtime or rxcheck corrupt the incoming string if you use it?
    rxtime uses rxcheck, the latter returns either the oldest received character or -1 indicating that there isn't one. So if there is one then it consumes a character (by returning it to you). I assume you use said function in a simple yes/no manner which - if not handled properly - loses characters.

    What does your code look like?
  • steprogsteprog Posts: 227
    edited 2010-12-02 00:19
    MsgTest:==debug.rxtime(100)
    getstr(@command)
    if strcomp(@Reset, @command)
    do stuff

    From what your telling me my string compare won't work too well.
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-02 00:28
    steprog wrote: »
    MsgTest:==debug.rxtime(100)
      getstr(@command)
      if strcomp(@Reset, @command)
       do stuff
    

    From what your telling me my string compare won't work too well.

    Let's say you receive the string "fred\n" ('\n' being the end of the line/string). Depending on timing MsgTest will either be -1 (timeout) or 'f'. Then getstr will assemble the string "fred" or "red". So in case you didn't get the timeout you want to recover the missing/consumed character.
  • steprogsteprog Posts: 227
    edited 2010-12-02 00:31
    Now how to do that
    Thanks for the help.
    Greg
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-02 00:34
    steprog wrote: »
    Now how to do that
    Thanks for the help.
    Greg

    getstr looks like one of your methods, so why don't you pass in an extra parameter (i.e. MsgTest) which when -1 is ignored otherwise inserted into the buffer before the serial device is read again?
  • steprogsteprog Posts: 227
    edited 2010-12-02 00:38
    Sounds interesting, but for the life of me I can't picture how to implement it.
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-02 00:46
    steprog wrote: »
    Sounds interesting, but for the life of me I can't picture how to implement it.

    I'd help you but I'd need to see more code in order to do so. An example would be ...
    VAR
      byte  command[16]
      
    PUB null
    
      if (MsgTest := debug.rxtime(100)) <> -1               ' got character
        command[0] := MsgTest                               ' recover character
        getstr(@command[1])                                 ' append remainder of string
        if strcomp(@Reset, @command)
          do stuff
    
  • steprogsteprog Posts: 227
    edited 2010-12-02 00:47
    You have been more help than I deserve. Thanks a bunch.
    Greg
  • AribaAriba Posts: 2,690
    edited 2010-12-02 03:59
    You can also add a new methode to the FullDuplexSerial object, which returns the number of waiting bytes in the buffer. This does not change the buffer.
    PUB rxcount : count
    
    '' Check for bytes in receivebuffer (never waits)
    '' returns the number of bytes 
    
      count := (rx_head - rx_tail) & 15
    

    Andy
Sign In or Register to comment.