Shop OBEX P1 Docs P2 Docs Learn Events
RFID Tag ID To My Memory Stick — Parallax Forums

RFID Tag ID To My Memory Stick

jhwattsjhwatts Posts: 35
edited 2011-01-30 03:21 in BASIC Stamp
I am trying to write a RFID tags unique ID to a my memory stick. My code is below. I'm using the RFID read/write module (28440), Super Carrier Board, Memory Stick Datalogger (#27937), BS2px24. The code is working but at the location of the astrics in the code the variable result needs to be assigned the tag ID (As some type of string I think.) to be written to the file. Any suggestions on how I can this to work?

' {$STAMP BS2px}
' {$PBASIC 2.5}
' ========================================================================
'
[ I/O Definitions ]

RFID_TX PIN 0 ' Connects to RFID R/W Module SIN
RFID_RX PIN 1 ' Connects to RFID R/W Module SOUT
Display PIN 12 ' Serial LCD
'
[ USB STICK I/O Definitions ]
TX PIN 8 ' Transmit Data --> 27937.4 (RXD)
RTS PIN 9 ' Request To Send --> 27937.6 (CTS)
RX PIN 10 ' Receive Data <-- 27937.5 (TXD)
CTS PIN 11 ' Clear TO Send <-- 27937.2 (RTS)
'
[ Constants ]
Baud CON 396
RFID_ReadLegacy CON $0F ' Read unique ID from EM4102 read-only tag (for backwards compatibility with Parallax RFID Card Reader, #28140 and #28340) (12)
'
[ Variables ]
buffer VAR Byte(12) ' data buffer
idx VAR Byte ' index
idy VAR Byte
'
[ Variables ]
timeout VAR Bit ' Timeout Inidicator
index VAR Byte ' Index Variable
ioByte VAR Byte ' Input/Output Storage
temp VAR Byte ' Temp Variable
counter VAR Word ' Counter Variable
result VAR Word ' Random Number Storage
'
[ Initialization ]
Initialize:
PAUSE 250 ' let DEBUG open
DEBUG CLS ' clear the screen
'
[ Program Code ]

Main:
DEBUG CR
DEBUG CLS, "Memory Stick Datalogger V1.1", CR, CR
PAUSE 2000 ' Allow Time To Settle

HIGH TX ' Initialize Transmit Line
LOW RTS ' Take Vinculum Out Of Reset

PAUSE 2000 ' Allow Time To Settle

GOSUB Purge ' Purge Buffer
DEBUG "Synchronizing...", CR
index = 0

' For Synchronization send E until echoed back
DO WHILE (index < 1)
PAUSE 500
SEROUT TX\CTS, Baud, ["E", CR] ' Transmit "E CR"
GOSUB Get_Serial_Bytes ' Get Returned Data
LOOP
GOSUB Purge ' Purge Buffer

' Send e to complete synchronization
PAUSE 500
SEROUT TX\CTS, Baud, ["e", CR] ' Transmit "e CR"
GOSUB Get_Serial_Bytes

' Send CR to see if drive is present
PAUSE 500
GOSUB Purge ' Purge Buffer
DEBUG "Checking for USB Flash drive...", CR
SEROUT TX\CTS, Baud, [CR] ' Send Carriage Return
GOSUB Get_Serial_Bytes ' Wait for D:\>

IF (buffer(0) = "N") THEN
DEBUG "No drive present!"
STOP
ELSE
DEBUG "Drive D: Ready...", CR

' Open rfidfile.txt for output (write)
PAUSE 500
SEROUT TX\CTS, Baud, ["OPW rfidfile.txt", CR]
GOSUB Get_Serial_Bytes

DEBUG "Reading Legacy tag's unique serial number..." ' Read unique ID from EM4102 read-only tag
Read_Legacy:
SEROUT RFID_TX, Baud, ["!RW", RFID_ReadLegacy]
SERIN RFID_RX, Baud, [STR buffer\12] ' Get header and data
IF buffer(0) <> $0A THEN Read_Legacy ' If we don't receive the correct header, keep trying until we do

FOR idx = 1 TO 10 ' Display the data (ignore final \r byte sent by the reader)
DEBUG buffer(idx)
'***********************************************
result = buffer(idx) 'I need write these values to the file.
'************************************************
NEXT

' Write value to rfidfile.txt
PAUSE 250
SEROUT TX\CTS, Baud, ["WRF ", $00, $00, $00, $05, CR, DEC5 result, CR]
GOSUB Get_Serial_Bytes

' Close rfidfile.txt
PAUSE 250
SEROUT TX\CTS, Baud, ["CLF rfidfile.txt", CR]
GOSUB Get_Serial_Bytes
GOSUB Purge

ENDIF
GOSUB Purge ' Purge Buffer
counter = 0 ' Loop Counter

' USB Suspend Mode (Power Saving Mode)
PAUSE 120
DEBUG "Putting drive to sleep...", CR
SEROUT TX\CTS, Baud, ["SUD", CR]
GOSUB Get_Serial_Bytes
PAUSE 10000

' Wake Drive (Full Power)
PAUSE 120
DEBUG "Waking drive now", CR
SEROUT TX\CTS, Baud, ["WKD", CR]
GOSUB Get_Serial_Bytes
GOTO Main ' Do it all over again!
END
'
[ Subroutines ]

Get_Serial_Bytes:
timeout = 1 ' Set Timeout Indicator Flag
index = 0 ' Initialize Index
DO WHILE (timeout > 0) ' While Timeout Has Not Occurred
ioByte = 0 ' Clear Temporary Storage
SERIN RX\RTS, Baud, 100, No_Data, [ioByte]
buffer(index) = ioByte ' Save Byte Received To Array
index = index + 1 ' Increment Index
IF (index > 14) THEN ' Check For Overflow
index = 14 ' Prevent Overflow
ENDIF
LOOP
RETURN

Purge:
timeout = 1 ' Set Timeout Indicator Flag
DO WHILE (timeout > 0) ' While Timeout Has Not Occurred
PAUSE 50
SERIN RX\RTS, Baud, 500, No_Data, [ioByte]
LOOP
RETURN

No_Data:
timeout = 0 ' Timeout, Clear Flag
RETURN

No_Data2:
DEBUG CR, "Error reading the seed file -- Halting execution!", CR
PAUSE 1000
GOSUB Purge ' Purge Buffer
STOP
RETURN
'
[ End of File ]

Comments

Sign In or Register to comment.