December 03, 2024, 10:19:27 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


prop2 with multiple rfid readers to activate one relay

Started by cdwaynew, May 16, 2016, 07:11:17 AM

Previous topic - Next topic

cdwaynew

I hope I am doing this ok. First time posting anywhere really. I have found lots of useful info on your site so I hope you can help me out with this.  I need to hook up 5 or 6 separate rfid readers to one controller and when all five are activated then the controller will activate a relay. I am thinking the prop2 is the way to go but am open to suggestions. I have not used any of these boards before but would like to get familiar with them because I think they would be very useful to me.  I have one parallax serial rfid reader and wondered if there were others I should look into or get more of these. I don't have a prop2 yet but multiple prop1s if that would work also.  Thanks for any advice at all!
DW

JonnyMac

Have you talked with John Barrowman in our sales office about this? He asked me to work on such a program for a customer and that is on today's "To Do" list. You'll need two pins per reader (one for activation, the other for serial), a pin for putting the device into training mode, and another for your output. With six readers that would be 14 total pins so you're okay.

Escape room prop?
Jon McPhalen
EFX-TEK Hollywood Office

cdwaynew

Thanks, I will check with him about this. Yes, we are building some escape rooms and I have seen one similar to this so thought it would fit one of our games well.

JonnyMac

No need t check with John -- was just wondering if you're the person he spoke with.

Here's something to start with. It's an "explorer" type program that lets you scan tags so that you can put them into the program's database. It will show you the tags and if a tag is in the correct spot you'll see *** after the tag string.

I haven't written a BS2 program in a long time, so I was happy that it can do a serial time-out and look for a specific leading character.

' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock            PIN     15                      ' OUT15 controls lock

RFID4E          PIN     9                       ' Reader #4 enable pin
RFID4S          PIN     8                       ' Reader #4 serial pin

RFID3E          PIN     7                       ' Reader #3 enable pin
RFID3S          PIN     6                       ' Reader #3 serial pin

RFID2E          PIN     5                       ' Reader #2 enable pin
RFID2S          PIN     4                       ' Reader #2 serial pin

RFID1E          PIN     3                       ' Reader #1 enable pin
RFID1S          PIN     2                       ' Reader #1 serial pin

RFID0E          PIN     1                       ' Reader #0 enable pin
RFID0S          PIN     0                       ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     4                       ' 5 readers (0..4)
NoTag           CON     $FF

UnlockBits      CON     %11111                  ' correct tags all readers


IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

T2400           CON     396                     ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx          VAR     Byte
tagNum          VAR     Byte
buf             VAR     Byte(10)
success         VAR     Byte
idx             VAR     Byte
char            VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs

  FOR tagIdx = 0 TO LastTag                     ' disable all readers
    HIGH (tagIdx * 2) + 1                       ' make enable pin high
  NEXT


' -----[ Program Code ]----------------------------------------------------

Main:
  success = %00000                              ' clear found tags

  FOR tagIdx = 0 TO LastTag                     ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "
    GOSUB Scan_Reader
    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ***"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN5 success

  IF (success = UnlockBits) THEN
    HIGH Lock
    PAUSE 5000
  ELSE
    LOW Lock
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:
  LOW (tagIdx * 2) + 1                          ' enable reader

  SERIN (tagIdx * 2), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (tagNum * 10 + idx), char            ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char       ' compare tag to table
    NEXT
    GOTO SR_Exit                                ' all bytes match!

Bad_Char:                                       ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                ' no tag, or bad #

SR_Exit:
  HIGH (tagIdx * 2) + 1                         ' disable reader
  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "0415148F26"            ' valid tags
Tag1            DATA    "0415148E0C"
Tag2            DATA    "041514AEA3"
Jon McPhalen
EFX-TEK Hollywood Office

cdwaynew

This looks cool. Thanks for your help, I really appreciate it!

Lanuti

Hello Jon,
I enjoy this forum, but only in a read only mode.
I had Contacted John re: using Prop 2 to use 8 separate Parallax RFID readers with a specific RFID tag assigned to each reader.
This is for an escape room.
After Talking to John I have wired the RFID reader so they are on continuously.
I down loaded code from Parallax and it works to identify the tags.

' =========================================================================
'
'   File....... RFID.BS2
'   Purpose.... RFID Tag Reader / Simple Security System
'   Author..... (c) Parallax, Inc. -- All Rights Reserved
'   E-mail..... support@parallax.com
'   Started....
'   Updated.... 07 FEB 2005
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Reads tags from a Parallax RFID reader and compares to known tags (stored
' in EEPROM table).  If tag is found, the program will disable a lock.


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Enable          PIN     0                       ' low = reader on
RX              PIN     1                       ' serial from reader
Spkr            PIN     2                       ' speaker output
Latch           PIN     3                       ' lock/latch control


' -----[ Constants ]-------------------------------------------------------

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T1200       CON     813
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    TMidi       CON     12
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T1200       CON     2063
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    TMidi       CON     60
    T38K4       CON     45
  #CASE BS2PX
    T1200       CON     3313
    T2400       CON     1646
    T4800       CON     813
    T9600       CON     396
    T19K2       CON     188
    TMidi       CON     108
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     T2400


#SELECT $STAMP
  #CASE BS2, BS2E
    TmAdj       CON     $100                    ' x 1.0 (time adjust)
    FrAdj       CON     $100                    ' x 1.0 (freq adjust)
  #CASE BS2SX
    TmAdj       CON     $280                    ' x 2.5
    FrAdj       CON     $066                    ' x 0.4
  #CASE BS2P
    TmAdj       CON     $3C5                    ' x 3.77
    FrAdj       CON     $044                    ' x 0.265
  #CASE BS2PE
    TmAdj       CON     $100                    ' x 1.0
    FrAdj       CON     $0AA                    ' x 0.665
#ENDSELECT


LastTag         CON     3


#DEFINE __No_SPRAM = ($STAMP < BS2P)            ' does module have SPRAM?


' -----[ Variables ]-------------------------------------------------------

#IF __No_SPRAM #THEN
  buf           VAR     Byte(10)                ' RFID bytes buffer
#ELSE
  chkChar       VAR     Byte                    ' character to test
#ENDIF

tagNum          VAR     Nib                     ' from EEPROM table
idx             VAR     Byte                    ' tag byte index
char            VAR     Byte                    ' character from table


' -----[ EEPROM Data ]-----------------------------------------------------

Tag1            DATA    "1600110A5E"            ' valid tags
Tag2            DATA
Tag3            Data

Name0           DATA    "Unauthorized", CR, 0
Name1           DATA    "Tag 1 (Fear the Farm)", CR, 0
Name2           DATA    "Tag 2 (Oval)", CR, 0
Name3           DATA    "Tag 3 (Small Round)", CR, 0


' -----[ Initialization ]--------------------------------------------------

Reset:
  HIGH Enable                                   ' turn of RFID reader
  LOW Latch                                     ' lock the door!


' -----[ Program Code ]----------------------------------------------------

Main:
  LOW Enable                                    ' activate the reader
  #IF __No_SPRAM #THEN
    SERIN RX, T2400, [WAIT($0A), STR buf\10]    ' wait for hdr + ID
  #ELSE
    SERIN RX, T2400, [WAIT($0A), SPSTR 10]
  #ENDIF
  HIGH Enable                                   ' deactivate reader

Check_List:
  FOR tagNum = 1 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (tagNum - 1 * 10 + idx), char        ' get tag data from table
      #IF __No_SPRAM #THEN
        IF (char <> buf(idx)) THEN Bad_Char     ' compare tag to table
      #ELSE
        GET idx, chkChar                        ' read char from SPRAM
        IF (char <> chkChar) THEN Bad_Char      ' compare to table
      #ENDIF
    NEXT
    GOTO Tag_Found                              ' all bytes match!

Bad_Char:                                       ' try next tag
  NEXT

Bad_Tag:
  tagNum = 0
  GOSUB Show_Name                               ' print message
  FREQOUT Spkr, 1000 */ TmAdj, 115 */ FrAdj     ' groan
  PAUSE 1000
  GOTO Main

Tag_Found:
  GOSUB Show_Name                               ' print name
  HIGH Latch                                    ' remove latch
  FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj     ' beep
  LOW Latch                                     ' restore latch
  GOTO Main

  END


' -----[ Subroutines ]-----------------------------------------------------

' Prints name associated with RFID tag

Show_Name:
  DEBUG DEC tagNum, ": "
  LOOKUP tagNum,
         [Name0, Name1, Name2, Name3], idx      ' point to first character
  DO
    READ idx, char                              ' read character from name
    IF (char = 0) THEN EXIT                     ' if 0, we're done
    DEBUG char                                  ' otherwise print it
    idx = idx + 1                               ' point to next character
  LOOP
  RETURN




I then used your code and tried to adapt it for my purpose and set it up for 10 readers.
Alas, I have stumbled.

Would you please review what I have done and enlighten me?
Thanking you in Advance
Steve


   

Lanuti

Here is how I modified your code without success
Thanking you in advance
Steve

' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock            PIN     15                      ' OUT15 controls lock

RFID9S          PIN     9                       ' Reader #9 serial pin
RFID8S          PIN     8                       ' Reader #8 serial pin

RFID7S          PIN     7                       ' Reader #7 serial pin
RFID6S          PIN     6                       ' Reader #6 serial pin

RFID5S          PIN     5                       ' Reader #5 serial pin
RFID4S          PIN     4                       ' Reader #4 serial pin

RFID3S          PIN     3                       ' Reader #3 serial pin
RFID2S          PIN     2                       ' Reader #2 serial pin

RFID1S          PIN     1                       ' Reader #1 serial pin
RFID0S          PIN     0                       ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     9                       ' 10 readers (0..10)
NoTag           CON     $FF

UnlockBits      CON     %11111                  ' correct tags all readers


IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

T2400           CON     396                     ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx          VAR     Byte
tagNum          VAR     Byte
buf             VAR     Byte(10)
success         VAR     Byte
idx             VAR     Byte
char            VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs





' -----[ Program Code ]----------------------------------------------------

Main:
  success = %00000                              ' clear found tags

  FOR tagIdx = 0 TO LastTag                     ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "
    GOSUB Scan_Reader
    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ***"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN5 success

  IF (success = UnlockBits) THEN
    HIGH Lock
    PAUSE 5000
  ELSE
    LOW Lock
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:


  SERIN (tagIdx * 2), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (tagNum * 10 + idx), char            ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char       ' compare tag to table
    NEXT
    GOTO SR_Exit                                ' all bytes match!

Bad_Char:                                       ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                ' no tag, or bad #

SR_Exit:

  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "1600110A5E"            ' valid tags
Tag1            DATA    "1600110A5E"
Tag2            DATA    "1600110A5E"

JonnyMac

Reverse-engineering one's intent takes a lot of time -- tell me what you want the program to do (that it doesn't), and I'll show you the way. Much easier for you to spell it out than for me to try to suss it out! :)
Jon McPhalen
EFX-TEK Hollywood Office

Lanuti

I would like to have 8 separate boxes with a RFID reader in the bottom of each box ( 8 readers).
Then a unique RFID tag for each box.  With the goal to match the Red Tag to Red box, Blue tag to Blue box, yellow tag to yellow box,
ETC x 8 unique pairs.
Only When all 8 correct pairs have been made I would like to have a LED light that is red initially (when not paired or wrong pairs made)
that then turns green and some notification sound that lets the player know they have been successful with the puzzle.
I hope this explains the idea.

John Suggested that  I Ground the Enable to leave the readers on continuously.
Doing this and alternating every other pin set I can get 5 of the 8 to read but not necessarily all at the same time and the prop2 get very warm/hot
If I switch the Prop2 On with all the rfid tags in the right spot - when it first registers it will see all 5 in order and register 11111

Should I be using a different board?


Thanks for your help,
Steve

Lanuti

jonnymac

using your code with minor changes
I have 8 RFID parallax readers connected to pins 0-7 with enable shorted to ground
The Debug terminal will register all 8 correct RFID tags (******) if they are in place when powering up the prop2
and Correct Tags: 11111111
If the prop2 is left on for more than a minute It is HOT

below is how I modified your code

Thanks

Steve



' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock              PIN     15                          ' OUT15 controls lock

RFID7S          PIN     7                           ' Reader #7 serial pin
RFID6S          PIN     6                           ' Reader #6 serial pin

RFID5S          PIN     5                           ' Reader #5 serial pin
RFID4S          PIN     4                           ' Reader #4 serial pin

RFID3S          PIN     3                           ' Reader #3 serial pin
RFID2S          PIN     2                           ' Reader #2 serial pin

RFID1S          PIN     1                           ' Reader #1 serial pin
RFID0S          PIN     0                           ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag          CON     7                                 ' 5 readers (0..4)
NoTag            CON     $FF

UnlockBits      CON     %11111111                  ' correct tags all readers


IsOn              CON     1                                  ' for active-high in/out
IsOff              CON     0

Yes                CON     1
No                 CON     0

T2400            CON     396                                ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx              VAR     Byte
tagNum            VAR     Byte
buf                   VAR     Byte(10)
success             VAR     Byte
idx                    VAR     Byte
char                  VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000            ' clear all
  DIRH = %00000000 : DIRL = %00000000             ' set outputs

  FOR tagIdx = 0 TO LastTag                                   ' disable all readers

  NEXT


' -----[ Program Code ]----------------------------------------------------

Main:
  success = %000000                                                 ' clear found tags

  FOR tagIdx = 0 TO LastTag                                       ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "
    GOSUB Scan_Reader
    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ******"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF
  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN8 success

  IF (success = UnlockBits) THEN
    HIGH Lock
    PAUSE 5000
  ELSE
    LOW Lock
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:


  SERIN (tagIdx * 1), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                                    ' scan through known tags
    FOR idx = 0 TO 9                                                  ' scan bytes in tag
      READ (tagNum * 10 + idx), char                          ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char                   ' compare tag to table
    NEXT
    GOTO SR_Exit                                                       ' all bytes match!

Bad_Char:                                                                ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                                    ' no tag, or bad #

SR_Exit:
  HIGH (tagIdx * 2) + 1                                            ' disable reader
  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "1600110A5E"                           ' valid tags
Tag1            DATA    "1600121696"
Tag2            DATA    "1600120E29"
Tag3            DATA    "1600120E2D"
Tag4            DATA    "1600120E2F"
Tag5            DATA    "1600120E2E"
Tag6            DATA    "1600120E46"
Tag7            DATA    "1600121241"

Lanuti


JackMan

If you're powering all 8 active readers from the Prop-2, you are drawing possibly close to 2 amps of current through that regulator. That would cause it to get hot. Try powering the readers with a separate 5v supply with a common GND.

JonnyMac

Glad you got it working! Well done.

And Jack is correct: when operating the RFID readers draw a fair bit of current (to generate a magnetic field large enough to affect a passive tag). Using a separate 5V supply is a good idea if you're going to leave the readers on all the time.

Are you good at whipping up circuits? Here's an idea: you could use a 74HC595 to selectively enable one reader at a time; this would cut down on the current through the regulator and allow it to run cooler.
Jon McPhalen
EFX-TEK Hollywood Office

Lanuti

I may never play with multiple RFID readers again as I am pulling out all my hair

I can wire a house and a car but whipping up circuits is very new to me.

I have the prop2 with a 12 volt power supply

I have a second 5 volt power supply that I Daisy chained to each RFID reader so as to not take power from the Prop2

Enable is shorted to Ground - keep RFID readers on constant.

Scout Wire comes back to Prop2 at the white pin (I/0) using pins 0-7

Regulator is now cool.

If I Ground the RFID readers to the Prop2 thru the Ground screw - The Prop2 LED lights up
With the power off but dimmer than when power is on

Volt Meter says Scout wire (white) to Ground is 5 volts

RFID reader will NOT read any of the RFID tags

When using Parallax code and using 1 reader at a time I can individual read each tag

If there is an easier way to make this puzzle -  please share before I'm hairless

Thanks

Steve




Here is code I last Used

' =========================================================================
'
'   File...... rfid_multi-tag.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 16 MAY 2016
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Lock            PIN     15                      ' OUT15 controls lock


RFID7           PIN     7                       ' Reader #7 serial pin
RFID6           PIN     6                       ' Reader #6 serial pin

RFID5           PIN     5                       ' Reader #5 serial pin
RFID4           PIN     4                       ' Reader #4 serial pin

RFID3           PIN     3                       ' Reader #3 serial pin
RFID2           PIN     2                       ' Reader #2 serial pin

RFID1           PIN     1                       ' Reader #1 serial pin
RFID0           PIN     0                       ' Reader #0 serial pin


' -----[ Constants ]-------------------------------------------------------

LastTag         CON     7                       ' 8 readers (0..7)
NoTag           CON     $FF

UnlockBits      CON     %11111111                 ' correct tags all readers


IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

T2400           CON     396                     ' baud for RFID readers


' -----[ Variables ]-------------------------------------------------------

tagIdx          VAR     Byte
tagNum          VAR     Byte
buf             VAR     Byte(10)
success         VAR     Byte
idx             VAR     Byte
char            VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs





' -----[ Program Code ]----------------------------------------------------

Main:
  success = %00000                              ' clear found tags

  FOR tagIdx = 0 TO LastTag                     ' scan all readers
    DEBUG CRSRXY, 0, tagIdx, "Reader ", DEC1 tagIdx, ": "

    GOSUB Scan_Reader


    IF (tagNum < $FF) THEN
      DEBUG STR buf\10
      IF (tagNum = tagIdx) THEN
        success = success | (1 << tagIdx)
        DEBUG " ******"
      ELSE
        DEBUG CLREOL
      ENDIF
    ELSE
      DEBUG "No Tag", CLREOL
    ENDIF


  NEXT

  DEBUG CRSRXY, 0, LastTag+2
  DEBUG "Correct tags: ", BIN8 success



  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Pass the reader # to scan in tagIdx
' If tagNum is 0..LastTag on return, known tag was found
' If tagNum is $FF then reader had no tag, or tag not in database

Scan_Reader:


  SERIN (tagIdx *1), T2400, 250, Not_Found, [WAIT($0A), STR buf\10]

Check_List:
  FOR tagNum = 0 TO LastTag                     ' scan through known tags
    FOR idx = 0 TO 9                            ' scan bytes in tag
      READ (tagNum * 10 + idx), char            ' get tag data from table
      IF (char <> buf(idx)) THEN Bad_Char       ' compare tag to table  (LEFT OUT)
    NEXT
    GOTO SR_Exit                                ' all bytes match!

Bad_Char:                                       ' try next tag
  NEXT

Not_Found:
  tagNum = NoTag                                ' no tag, or bad #

SR_Exit:

  RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Tag0            DATA    "480069D1E4"            ' valid tags
Tag1            DATA    "480069DACD"
Tag2            DATA    "480068C391"
Tag3            DATA    "480069CF1C"
Tag4            DATA    "480069C3F4"
Tag5            DATA    "480069BBAA"
Tag6            DATA    "480069D109"
Tag7            DATA    "480069C475"