CNSA-276-FP/test.py

27 lines
609 B
Python
Raw Normal View History

2024-05-09 21:11:20 -04:00
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()