34 lines
890 B
Python
34 lines
890 B
Python
|
|
import time
|
||
|
|
import ndef
|
||
|
|
import nfc
|
||
|
|
from nfc.clf import RemoteTarget
|
||
|
|
|
||
|
|
clf = nfc.ContactlessFrontend()
|
||
|
|
assert clf.open('tty:USB0:pn532') is True # open /dev/ttyUSB0 with pn532 driver
|
||
|
|
|
||
|
|
while True:
|
||
|
|
target = clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F'))
|
||
|
|
if target is not None:
|
||
|
|
tag = nfc.tag.activate(clf, target)
|
||
|
|
print(tag)
|
||
|
|
if tag.ndef is not None:
|
||
|
|
for record in tag.ndef.records:
|
||
|
|
print(record)
|
||
|
|
else:
|
||
|
|
print("EMPTY TAG - WRITING...")
|
||
|
|
if not tag.ndef.is_writeable:
|
||
|
|
print("This Tag is not writeable.")
|
||
|
|
break
|
||
|
|
tag.format()
|
||
|
|
ret = tag.wr
|
||
|
|
|
||
|
|
if ret:
|
||
|
|
print("ERROR")
|
||
|
|
else:
|
||
|
|
print("OK")
|
||
|
|
else:
|
||
|
|
print("NO TARGET")
|
||
|
|
time.sleep(0.1)
|
||
|
|
|
||
|
|
print("EXITING")
|
||
|
|
clf.close()
|