我正在尝试使用ACR122u NFC阅读器与NFC标签进行通信。程序启动良好,当一个标签连接时,它能够读取并执行标签上的所有所需操作。然而,一旦NFC标签被移除,读卡器就会关闭,直到程序重新启动才会打开。以下是我轮询读卡器的代码:
def CheckNFCCard():
getUIDCommand = [0xFF, 0xCA, 0x00, 0x00, 0x00]
turnOffBeepCommand = [0xFF, 0x00, 0x52, 0x00, 0x00]
getDataCommand = [0xFF, 0xB0, 0x00, 0x07, 0x10]
updateBlockCommandFirst=[0xFF, 0xD6, 0x00, 0x07, 0x04, 0x65, 0x6E, 0x75, 0x73]
updateBlockCommandSecond=[0xFF, 0xD6, 0x00, 0x08, 0x04, 0x65, 0x64, 0xFE, 0x00]
#get NFC reader
r = readers()
reader = r[0]
#select reader, connect
conn = reader.createConnection()
while(True):
print('NFC routine restart')
try:
conn.connect()
except:
time.sleep(1)
continue
#send hex command to turn off beeps on scan.
conn.transmit(turnOffBeepCommand)
#get data encoded on tag.
data, sw1, sw2 = conn.transmit(getDataCommand)
if (sw1, sw2) == (0x90, 0x0):
print("Status: The operation completed.")
#Turn decimal numbers into characters
stringList = [chr(x) for x in data]
#
identifierString = ''.join(stringList)[2:6]
if (identifierString == "used"):
pub.sendMessage('NFCDetected', arg1='used')
elif (identifierString == "new_"):
data, sw1, sw2 = conn.transmit(updateBlockCommandFirst)
if (sw1, sw2) == (0x90, 0x0):
conn.transmit(updateBlockCommandSecond)
Thread(target=pub.sendMessage, args=('NFCDetected',), kwargs={'new' : arg1}).Start()
time.sleep(1)
continue
循环继续按预期运行,但读卡器已关闭,不会再次连接
任何帮助都将不胜感激
目前没有回答
相关问题 更多 >
编程相关推荐