gpt4 book ai didi

python - 如何使用 rc522 和 Raspberry Pi 读取 7 个字节长的 Desfire uid?

转载 作者:行者123 更新时间:2023-12-02 05:48:11 27 4
gpt4 key购买 nike

我使用这个库https://github.com/mxgxw/MFRC522-python使用 rc522 读卡器和 Raspberry Pi 读取 UID。它非常适合具有 4 字节长 uid 的卡,但我无法读取 7 字节长 Desfire uid。我读到当级联位为1时需要编辑防碰撞算法。如何修改这个库才能读取7字节长的uid?

最佳答案

我刚来这里,遇到了同样的问题。虽然已经过去了 4 年多,但也许我的解决方案可以帮助某人。

1) 重命名(或删除)当前的 MFRC522-python 库

cd ~/.local/lib/python2.7  # or your python version
mv pirc522 pirc522_original

2)创建一个新目录(如果不存在)用于安装新库

mkdir /usr/local/lib/python2.7/dist-packages  # or your python version

3) 安装该库的另一个版本,其中包含一个函数 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)))

关于python - 如何使用 rc522 和 Raspberry Pi 读取 7 个字节长的 Desfire uid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27681312/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com