I am working on a script for RFID. I will have a folder that has only one file, but that filename changes, and I have therefore called the file as a variable. Running the script shows that the variable filename is found correctly.
After a UID is found from the RFID reader, I need the script to open the variable filename, and append the file with the newly-found UID.
The card reads successfully, but nothing is copied into the variable file.
I'd appreciate a second set of eyes on this. I'm rather new to python, so please forgive my ignorance.
Code: Select all
import RPi.GPIO as GPIO
import MFRC522
import signal
import glob
MYFILE = glob.glob('/home/pi/RXRFID/newscans/*.txt')
continue_reading = True
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
continue_reading = False
GPIO.cleanup()
# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)
# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()
# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:
# Scan for cards
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
# If a card is found
if status == MIFAREReader.MI_OK:
print "Card detected"
print MYFILE
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
# If we have the UID, continue
if status == MIFAREReader.MI_OK:
# Print UID
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])