Shop OBEX P1 Docs P2 Docs Learn Events
Using RxCheck — Parallax Forums

Using RxCheck

steprogsteprog Posts: 227
edited 2014-03-23 18:14 in Propeller 1
Hello
I put this code in my software hoping that the software will check for data and then move on. Unfortunately it still seems to get hung up. Is there something I am doing wroing with
rxCheck ?
Thanks,
Greg

if USB.rxcheck
comd:= USB.rx
if comd == "O" 'Status Command
OverPressure:= true

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2014-03-23 16:27
    rxcheck returns -1 or the first available character.
    if (comd := USB.rxcheck) <> -1
        ' do something
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-23 16:29
    Which object are you using?

    In many objects rxCheck returns -1 is no character is received but if there is a character it will be returned. So do something like:
    result := USB.rxCheck
      if result <> -1
        ' do something with character stored in result.
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-23 16:30
    kuroneko wrote: »
    rxcheck returns -1 or the first available character.
    if (comd := USB.rxcheck) <> -1
        ' do something
    

    "comd" needs to be a long, right?
  • kuronekokuroneko Posts: 3,623
    edited 2014-03-23 16:39
    Duane Degn wrote: »
    "comd" needs to be a long, right?
    Only when you assign first and then do the comparison. Doing it in one go can take any type (width cut-off doesn't affect comparison).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-23 16:43
    kuroneko wrote: »
    Only when you assign first and then do the comparison. Doing it in one go can take any type (width cut-off doesn't affect comparison).

    Thank you kuroneko.

    That's just want I wanted to know. I didn't know one could do it that way.
  • steprogsteprog Posts: 227
    edited 2014-03-23 17:17
    That seemed to work thanks, but I still don't understand why I couldn't use it as a boolean expression and test it for true or false
  • kuronekokuroneko Posts: 3,623
    edited 2014-03-23 17:53
    steprog wrote: »
    ... but I still don't understand why I couldn't use it as a boolean expression and test it for true or false
    The returned values include $00..$FF (the actual character) and $FFFFFFFF (no character). This is not a TRUE/FALSE API. If you want that you'd need to introduce your own method which simply returns the rx fill level, then you can simply fetch a character (after doing a boolean check).
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-03-23 18:14
    Since the IF statement really only looks for a false or non-false I simplify it like this:
    ch := coms.rxcheck
    if ch+1 ' a -1 becomes 0 or false
    ' do something

    but in this case ch was declared as a local variable so I guess it works because it is a long
Sign In or Register to comment.