Shop OBEX P1 Docs P2 Docs Learn Events
BS2 and RFID Reader.... How to know when the reader is inactive — Parallax Forums

BS2 and RFID Reader.... How to know when the reader is inactive

Jeff_5_Jeff_5_ Posts: 36
edited 2010-08-07 17:04 in BASIC Stamp
ok so i have a parallax rfid reader hooked into my basic stamp. I read my tags in the the VAR buf. My question is how can i determine when the reader is not reading a tag. My thought was to set the buf=0 and then do this piece of code.

LOWEnable 'activatethereader
SERINRX,T2400,150,Notag_,[WAIT($0A),SKIP6,HEX4buf] 'waitforhdr+ID
HIGHEnable

And if my reader dosnt read a tag my buf should still equal zero. So then i can say

If(buf = 0) THEN
Debug "There is no tag in range"

Anybody know how i can do this.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-08-07 15:54
    Have you tried that? If so what did you get?
  • W9GFOW9GFO Posts: 4,010
    edited 2010-08-07 16:16
    Jeff_5_ wrote: »
    My question is how can i determine when the reader is not reading a tag. My thought was to set the buf=0 and then do this piece of code.
    LOW Enable    'activate the reader
    SERIN RX, T2400, 150, Notag_, [WAIT($0A), SKIP6, HEX4 buf]     'waitforhdr+ID
    HIGH Enable
    
    And if my reader dosnt read a tag my buf should still equal zero. 
    So then i can say
    
     If (buf = 0) THEN 
    Debug "There is no tag in range"
    

    Anybody know how i can do this.

    The "Notag_" part is the name of a subroutine that the program jumps to if the tag reading times out. The "150" before it is the time in milliseconds that it waits to read a tag before making the jump. If a tag is read then the jump is not made.

    Rich H
  • Jeff_5_Jeff_5_ Posts: 36
    edited 2010-08-07 16:28
    ok that makes sense but how do sub routies work.

    can i just go

    NotTag:

    debug "There is no tag in range"
  • W9GFOW9GFO Posts: 4,010
    edited 2010-08-07 17:04
    Yes, that's pretty much it.

    See if this works;
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    RX       PIN   5  ' change to suit
    Enable   PIN   3  ' change to suit
    
    tag     VAR      Word(5)     ' an array of 5
    buf     VAR      Word
    i       VAR      Byte
    
    T2400   CON      396
    
    Main:
    
    DO
    
    FOR i = 0  TO 4
     LOW Enable    'activate the reader
     SERIN RX, T2400, 150, Notag, [WAIT($0A), SKIP 6, HEX4 buf]
     HIGH Enable
    
      SELECT buf      ' look at contents of buf
    
        CASE tag(0)   ' if buf = the first tag
          DEBUG "This is tag 1"
          EXIT        ' exit the FOR..NEXT loop
        CASE tag(1)
          DEBUG "This is tag 2"
          EXIT
        CASE tag(2)
          DEBUG "This is tag 3"
          EXIT
        CASE tag(3)
          DEBUG "This is tag 4"
          EXIT
        CASE tag(4)
          DEBUG "This is tag 5"
          EXIT
        CASE ELSE
          DEBUG "This tag stored as tag ", DEC i+1
          tag(i) = buf
      ENDSELECT
    
    NEXT
    GOTO Main
    
    Notag:
    
    DEBUG "There is no tag in range"
    
    LOOP
    

    Rich H
Sign In or Register to comment.