Merge remote-tracking branch 'origin/master'
# Conflicts: # src/test/rfid.py
This commit is contained in:
commit
d0de088e22
|
|
@ -41,53 +41,54 @@ else:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if not connected:
|
if not connected:
|
||||||
logging.info("Attempting to connect to NFC reader...")
|
|
||||||
clf = nfc.ContactlessFrontend()
|
clf = nfc.ContactlessFrontend()
|
||||||
for dev in dev_list:
|
for dev in dev_list:
|
||||||
connected = clf.open(dev)
|
connected = clf.open(dev)
|
||||||
if connected:
|
if connected:
|
||||||
logging.info(f"CONNECTED TO {dev}")
|
print(f"CONNECTED TO {dev}")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
logging.error(f"UNABLE TO CONNECT TO {dev}")
|
print(f"UNABLE TO CONNECT TO {dev}")
|
||||||
|
|
||||||
if connected:
|
if connected:
|
||||||
target = clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F'))
|
target = clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F'))
|
||||||
if target is not None:
|
if target is not None:
|
||||||
tag = nfc.tag.activate(clf, target)
|
tag = nfc.tag.activate(clf, target)
|
||||||
if tag is not None:
|
if tag is not None:
|
||||||
logging.info(f"Tag detected: {tag}")
|
print(tag)
|
||||||
if tag.ndef is not None:
|
if tag.ndef is not None:
|
||||||
if not len(tag.ndef.records):
|
if not len(tag.ndef.records):
|
||||||
logging.info("EMPTY TAG - WRITING...")
|
print("EMPTY TAG - WRITING...")
|
||||||
if not tag.ndef.is_writeable:
|
if not tag.ndef.is_writeable:
|
||||||
logging.warning("This Tag is not writeable.")
|
print("This Tag is not writeable.")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
tag.format()
|
tag.format()
|
||||||
record = ndef.TextRecord("Errecinque,fixture,5812345678")
|
#tag.ndef.records = [ndef.TextRecord("Errecinque"),ndef.TextRecord("5812345678")]
|
||||||
|
record=ndef.TextRecord("Errecinque,fixture,5812345678")
|
||||||
tag.ndef.records = [record]
|
tag.ndef.records = [record]
|
||||||
if tag.ndef.has_changed:
|
if tag.ndef.has_changed:
|
||||||
logging.error("WRITE ERROR")
|
print("WRITE ERROR")
|
||||||
else:
|
else:
|
||||||
logging.info("WRITE OK")
|
print("WRITE OK")
|
||||||
|
|
||||||
for record in tag.ndef.records:
|
for record in tag.ndef.records:
|
||||||
logging.info(f"Record: {record}")
|
print(record)
|
||||||
else:
|
else:
|
||||||
logging.error("ERROR NOT NDEF")
|
print("ERROR NOT NDEF")
|
||||||
else:
|
else:
|
||||||
logging.info("NO TARGET")
|
print("NO TARGET")
|
||||||
else:
|
else:
|
||||||
logging.info("NOT CONNECTED")
|
print("NOT CONNECTED")
|
||||||
except IOError as io_err:
|
except IOError as io_err:
|
||||||
logging.error(f"IOError: {io_err}")
|
print(f"IOError: {io_err}")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
connected = False
|
connected = False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"General Exception: {e}")
|
print(f"General Exception: {e}")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
connected = False
|
connected = False
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
logging.info("EXITING")
|
print("EXITING")
|
||||||
clf.close()
|
clf.close()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user