CallMeAlien
CallMeAlien

Reputation: 187

Reading Mifare Classic python ACR122U

I have an ACR122U reader, which says to support Mifare Classic. I'm using nfcpy for the communication with the reader, and while I can read the tag id, I can't manage to read any data from it. When I run the following code it raises an Exception: nfc.tag.tt2.Type2TagCommandError: invalid page number. Is there a way to make this work with nfcpy? If not, what could I do?

import nfc

def on_connect(tag):
    print("Connected to tag:")
    print(tag)

    if (tag.ndef):
        print(tag.ndef)

    else:
        for sector in range(0, 16):
            for block in range(0, 4):
               data = tag.read((sector * 4) + block)
               print("Sector", sector, "Block", block, "Data:", data.hex())

def main():
    with nfc.ContactlessFrontend('usb') as clf:
        print("Waiting for a tag...")
        clf.connect(rdwr={'on-connect': on_connect})

if __name__ == "__main__":
    main()

Upvotes: 0

Views: 11

Answers (0)

Related Questions