我通过rc522阅读器和树莓派使用这个库https://github.com/mxgxw/MFRC522-python来读取UID。它适用于具有4字节长的uid的卡片,但我无法读取7字节长的Desfire uid。我读到当级联位为1时有必要编辑防冲突算法,如何修改这个库才能读取7字节长的uid?
发布于 2019-11-15 16:45:17
我是带着同样的问题来到这里的。虽然四年多过去了,但也许我的解决方案可以帮助一些人。
1)重命名(或删除)当前的MFRC522-python库
cd ~/.local/lib/python2.7 # or your python version
mv pirc522 pirc522_original2)创建用于安装新库的新目录(如果该目录不存在)
mkdir /usr/local/lib/python2.7/dist-packages # or your python version3)安装该库的另一个版本,其中包含一个函数anticoll2(),允许您从RFID卡中读取更多字节
git clone https://github.com/ondryaso/pi-rc522.git
cd pi-rc522
python setup.py install仅此而已。您可以像导入上一个库一样导入这个新库。
现在,要读取RFID卡,请记住7字节的RFID卡以0x88开头。因此,当anticoll()在第一个位置返回0x88时,您可以使用该库中的新函数anticoll2()读取更多数据。下面是一个例子:
from pirc522 import RFID
def detect_uid(reader):
(error, tag_type) = reader.request()
(error, uid) = reader.anticoll()
if uid[0] != 0x88:
rfid_uid = uid[0:4] # classic 4bytes-rfid card
else:
(error, uid2) = reader.anticoll2()
rfid_uid = uid[1:4] + uid2[:4] # 7bytes-rfid card
return rfid_uid
reader = pirc522.RFID()
print("UID: " + str(detect_uid(reader)))https://stackoverflow.com/questions/27681312
复制相似问题