Reputation: 31
I use this library https://github.com/mxgxw/MFRC522-python to read UID using rc522 reader and Raspberry Pi. It works great for cards with 4 bytes long uid but I am unable to read 7 bytes long Desfire uid. I read that it is necessary to edit anti collision algorithm when cascade bit is 1. How to modify this library to be able to read 7 bytes long uid ?
Upvotes: 3
Views: 2341
Reputation: 310
I have just come here with the same problem. Although more than 4 years have passed, maybe my solution can help someone.
1) Rename (or delete) the current MFRC522-python library
cd ~/.local/lib/python2.7 # or your python version
mv pirc522 pirc522_original
2) Create a new directory (if it does not exists) for the installation of a new library
mkdir /usr/local/lib/python2.7/dist-packages # or your python version
3) Install this other version of the library, which contains a function anticoll2()
that allows you to read more bytes from the RFID Card
git clone https://github.com/ondryaso/pi-rc522.git
cd pi-rc522
python setup.py install
And that's all. You can import this new library the same way you imported the previous one.
Now, to read a RFID card, remember that a 7-bytes RFID card starts with 0x88
. So you can use the new function anticoll2()
in this library to read more data when anticoll()
returns 0x88
on the first position. Here's is an example:
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)))
Upvotes: 1