-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcard.py
56 lines (51 loc) · 1.45 KB
/
card.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import nfc
import config
import cv2
import time
#from verification import check_card
#from db_handler import Userdb
from new_verification import check_card
from new_db_handler import Userdb
#The method is called whenever you place a NFC tag on the reader.
def handleTag(tag):
if tag.identifier.hex()!='':
config.uid = str(tag.identifier.hex())
print("Tag address: " + config.uid, flush=True)
return True
return False
def gotTag():
if check_card(config.uid):
if config.cardOnly:
config.relay.signal("card") # relay_on()
else:
config.padON = True
return True
#True for loop until tag is removed
#False for immediate return
return False
# The Card Thread
def card():
oCLF = nfc.ContactlessFrontend()
#Insert the device address here (e.g. "tty:S0"). Note the ":" after "tty"
# oCLF.open("tty:S0")
oCLF.open("usb:072f:2200")
config.dba = Userdb()
while not config.done:
try:
print("Waiting for NFC tag ...", flush=True)
oCLF.connect(rdwr={'on-connect': handleTag})
#time.sleep(1)
except KeyboardInterrupt:
config.done = True
print("card interrupted")
oCLF.close()
break
except:
print("Connection Error")
oCLF.close()
#time.sleep(1)
# oCLF.open("tty:S0")
oCLF.open("usb:072f:2200")
if config.uid != '':
gotTag()
config.uid = ''