SATS/feature/rfid-read/source/read.py

41 lines
762 B
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf8 -*-
import RPi.GPIO as GPIO
import MFRC522
# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()
2017-02-24 09:14:51 +00:00
# Scan for cards
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
# If we have the UID, continue
2017-02-24 09:14:51 +00:00
while status != MIFAREReader.MI_OK:
2017-02-24 09:14:51 +00:00
# Scan for cards
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
2017-02-24 09:14:51 +00:00
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
2017-02-24 09:14:51 +00:00
# Print UID
suid = str(hex(uid[0]))[2:];
suid += '-' + str(hex(uid[1]))[2:];
suid += '-' + str(hex(uid[2]))[2:];
suid += '-' + str(hex(uid[3]))[2:];
2017-02-24 09:14:51 +00:00
print suid;
2017-02-24 09:14:51 +00:00
exit(0);