创建NFC读卡python脚本
2021-03-18 03:25
标签:href conf efi https spl try unzip exec ready 读卡器:ACR122U,主机环境:ubuntu 20.00 1.apt install libnfc-bin def execCmd(cmd): def saveCardUIDtoFile(str:str): cmd = "nfc-list" 创建NFC读卡python脚本 标签:href conf efi https spl try unzip exec ready 原文地址:https://www.cnblogs.com/InspirationPlace/p/13958498.html
2.apt install libpcsclite1
3.apt install vim
4.vi /etc/modprobe.d/blacklist-libnfc.conf
在文件尾增加:
blacklist pn533
blacklist pn533_usb
blacklist nfc
5.获取nfc-tools 1.8.0(因为ACR122U在1.7.1上有bug)
github:https://github.com/nfc-tools/libnfc/releases/tag/libnfc-1.8.0
download:https://github.com/nfc-tools/libnfc/releases/download/libnfc-1.8.0/libnfc-1.8.0.tar.bz2
unzip and compile:
tar xjf libnfc-1.8.0.tar.bz2
cd libnfc-1.8.0
./configure --with-drivers=acr122s,acr122_pcsc,acr122_usb --sysconfdir=/etc --prefix=/usr
make
makeinstall
6.try it:nfc-list
7.编写一段python代码,获取UID:
`import time
import os
ret = os.popen(cmd)
msg = ret.read()
ret.close()
return msg
file = open(file = "/UID/cardUID",mode = "w")
file.write(str)
file.close()
alreadyDetected = False
findCount = 0
while(True):
ret = execCmd(cmd)
ret = ret.split("\n")
findCount = 0
for element in ret:
if element.find("UID") != -1:
findCount += 1
if alreadyDetected == False:
alreadyDetected = True
print("NFC tag is detected.")
UIDList = element.split(" ")
UID = UIDList[9] + UIDList[11] + UIDList[13] + UIDList[15]
saveCardUIDtoFile(UID)
print("UID is: %r" % UID)
if findCount == 0:
if alreadyDetected == True:
alreadyDetected = False
print("NFC tag is removed.")
saveCardUIDtoFile("")
`
8.enjoy
上一篇:50 排序的工程应用示例
下一篇:Java的数据类型