27 lines
609 B
Python
27 lines
609 B
Python
|
import nfc
|
||
|
import time
|
||
|
|
||
|
def connected(tag):
|
||
|
print("Tag detected:", tag)
|
||
|
return True
|
||
|
|
||
|
def read_nfc():
|
||
|
try:
|
||
|
clf = nfc.ContactlessFrontend('usb') # Ensure this matches your connection
|
||
|
print("NFC reader initialized.")
|
||
|
except Exception as e:
|
||
|
print("Failed to initialize NFC reader:", e)
|
||
|
return
|
||
|
|
||
|
try:
|
||
|
while True:
|
||
|
print("Waiting for NFC tag...")
|
||
|
clf.connect(rdwr={'on-connect': connected})
|
||
|
time.sleep(1)
|
||
|
except Exception as e:
|
||
|
print("Error reading NFC tag:", e)
|
||
|
finally:
|
||
|
clf.close()
|
||
|
|
||
|
read_nfc()
|