我正在设置考勤系统的RFID阅读器。但是当我把我的标签放到阅读器上时,它被标签id中断了-我把它外部存储到数据库中。
#//////place your tag//////
print("Now place your tag to write")
rdr.wait_for_tag()
(error, data) = rdr.request()
if not error:
print("\nDetected: " + format(data, "02x"))
(error, uid) = rdr.anticoll()
if not error:
print("Card read UID: " +str(uid[0])+str(uid[1])+str(uid[2])+str(uid[3]))
tagid = str(uid[0])+str(uid[1])+str(uid[2])+str(uid[3])
print("Written..!")
print(tagid)
cursor.execute("insert into rfid_check (uid,firstname,age,tag_id) values ('%s','%s','%s','%s')" %(user_id,fname, ag_e, tagid))
connection.commit()
print("Data was successfully Added...!")
tagid = str(uid[0])+str(uid[1])+str(uid[2])+str(uid[3])
IndexError: list index out of range发布于 2019-05-28 17:20:44
代码结构不正确。尝试用这个来缩进rdr.anticoll(),只要标记请求不正确,就不会发生任何处理。
尝试下面这行代码,以获得更好的可视化效果:
print("Now place your tag to write")
rdr.wait_for_tag()
(error, data) = rdr.request()
if not error:
print("\nDetected: " + format(data, "02x"))
(error, uid) = rdr.anticoll()
if not error:
print("Card read UID: " +str(uid[0])+str(uid[1])+str(uid[2])+str(uid[3]))
tagid = str(uid[0])+str(uid[1])+str(uid[2])+str(uid[3])
print("Written..!")
print(tagid)
cursor.execute("insert into rfid_check (uid,firstname,age,tag_id) values ('%s','%s','%s','%s')" %(user_id,fname, ag_e, tagid))
connection.commit()
print("Data was successfully Added...!")
else:
print("Unsuccessful")https://stackoverflow.com/questions/56338412
复制相似问题