def checkCard(self): if rfid.tagIsPresent(): if rfid.readMifare(): uid = rfid.getUniqueId() cid = self.myDatabase.cardExists(uid) if cid >= 0: #print ("CHECK: Card found") return cid else: #print ("CHECK: Card NOT found") return -1 else: return -1 else: return -1
def waitTillCardRemoved(self): while rfid.tagIsPresent(): time.sleep(0.2)
# Import this module to gain access to the RFID driver import rfid import urllib2 import time # Keep track of what the last tag we saw was old_tag = 0 api = "http://localhost:8000/api/" # This, like, forever! while True: # try to check to see if a card is present try: tagIsPresent = rfid.tagIsPresent() except: time.sleep(0.2) continue # If one is, see if it's different to the one we had before if tagIsPresent: # try and grab the data try: rfid.readMifare() uid = rfid.getUniqueId() except: time.sleep(0.2) continue # If it's a new tag, then do the thing!