Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support for Python3 #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
print ("Ctrl+C captured, ending read.")
continue_reading = False
GPIO.cleanup()

Expand All @@ -28,7 +28,7 @@ def end_read(signal,frame):

# If a card is found
if status == MIFAREReader.MI_OK:
print "Card detected"
print ("Card detected")

# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
Expand All @@ -37,7 +37,7 @@ def end_read(signal,frame):
if status == MIFAREReader.MI_OK:

# Print UID
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
print ("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))

# This is the default key for authentication
key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
Expand Down
18 changes: 9 additions & 9 deletions MFRC522.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def MFRC522_SelectTag(self, serNum):
(status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, buf)

if (status == self.MI_OK) and (backLen == 0x18):
print "Size: " + str(backData[0])
print ("Size: " + str(backData[0]))
return backData[0]
else:
return 0
Expand Down Expand Up @@ -318,9 +318,9 @@ def MFRC522_Auth(self, authMode, BlockAddr, Sectorkey, serNum):

# Check if an error occurred
if not(status == self.MI_OK):
print "AUTH ERROR!!"
print ("AUTH ERROR!!")
if not (self.Read_MFRC522(self.Status2Reg) & 0x08) != 0:
print "AUTH ERROR(status2reg & 0x08) != 0"
print ("AUTH ERROR(status2reg & 0x08) != 0")

# Return the status
return status
Expand All @@ -337,10 +337,10 @@ def MFRC522_Read(self, blockAddr):
recvData.append(pOut[1])
(status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, recvData)
if not(status == self.MI_OK):
print "Error while reading!"
print ("Error while reading!")
i = 0
if len(backData) == 16:
print "Sector "+str(blockAddr)+" "+str(backData)
print ("Sector "+str(blockAddr)+" "+str(backData))

def MFRC522_Write(self, blockAddr, writeData):
buff = []
Expand All @@ -353,7 +353,7 @@ def MFRC522_Write(self, blockAddr, writeData):
if not(status == self.MI_OK) or not(backLen == 4) or not((backData[0] & 0x0F) == 0x0A):
status = self.MI_ERR

print str(backLen)+" backdata &0x0F == 0x0A "+str(backData[0]&0x0F)
print (str(backLen)+" backdata &0x0F == 0x0A "+str(backData[0]&0x0F))
if status == self.MI_OK:
i = 0
buf = []
Expand All @@ -365,9 +365,9 @@ def MFRC522_Write(self, blockAddr, writeData):
buf.append(crc[1])
(status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE,buf)
if not(status == self.MI_OK) or not(backLen == 4) or not((backData[0] & 0x0F) == 0x0A):
print "Error while writing"
print ("Error while writing")
if status == self.MI_OK:
print "Data written"
print ("Data written")

def MFRC522_DumpClassic1K(self, key, uid):
i = 0
Expand All @@ -377,7 +377,7 @@ def MFRC522_DumpClassic1K(self, key, uid):
if status == self.MI_OK:
self.MFRC522_Read(i)
else:
print "Authentication error"
print ("Authentication error")
i = i+1

def MFRC522_Init(self):
Expand Down
12 changes: 6 additions & 6 deletions Read.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
print ("Ctrl+C captured, ending read.")
continue_reading = False
GPIO.cleanup()

Expand All @@ -21,8 +21,8 @@ def end_read(signal,frame):
MIFAREReader = MFRC522.MFRC522()

# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."
print ("Welcome to the MFRC522 data read example")
print ("Press Ctrl-C to stop.")

# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:
Expand All @@ -32,7 +32,7 @@ def end_read(signal,frame):

# If a card is found
if status == MIFAREReader.MI_OK:
print "Card detected"
print ("Card detected")

# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
Expand All @@ -41,7 +41,7 @@ def end_read(signal,frame):
if status == MIFAREReader.MI_OK:

# Print UID
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
print ("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))

# This is the default key for authentication
key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
Expand All @@ -57,5 +57,5 @@ def end_read(signal,frame):
MIFAREReader.MFRC522_Read(8)
MIFAREReader.MFRC522_StopCrypto1()
else:
print "Authentication error"
print ("Authentication error")

30 changes: 15 additions & 15 deletions Write.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
print ("Ctrl+C captured, ending read.")
continue_reading = False
GPIO.cleanup()

Expand All @@ -28,7 +28,7 @@ def end_read(signal,frame):

# If a card is found
if status == MIFAREReader.MI_OK:
print "Card detected"
print ("Card detected")

# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
Expand All @@ -37,7 +37,7 @@ def end_read(signal,frame):
if status == MIFAREReader.MI_OK:

# Print UID
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
print ("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))

# This is the default key for authentication
key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
Expand All @@ -47,7 +47,7 @@ def end_read(signal,frame):

# Authenticate
status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid)
print "\n"
print ("\n")

# Check if authenticated
if status == MIFAREReader.MI_OK:
Expand All @@ -59,39 +59,39 @@ def end_read(signal,frame):
for x in range(0,16):
data.append(0xFF)

print "Sector 8 looked like this:"
print ("Sector 8 looked like this:")
# Read block 8
MIFAREReader.MFRC522_Read(8)
print "\n"
print ("\n")

print "Sector 8 will now be filled with 0xFF:"
print ("Sector 8 will now be filled with 0xFF:")
# Write the data
MIFAREReader.MFRC522_Write(8, data)
print "\n"
print ("\n")

print "It now looks like this:"
print ("It now looks like this:")
# Check to see if it was written
MIFAREReader.MFRC522_Read(8)
print "\n"
print ("\n")

data = []
# Fill the data with 0x00
for x in range(0,16):
data.append(0x00)

print "Now we fill it with 0x00:"
print ("Now we fill it with 0x00:")
MIFAREReader.MFRC522_Write(8, data)
print "\n"
print ("\n")

print "It is now empty:"
print ("It is now empty:")
# Check to see if it was written
MIFAREReader.MFRC522_Read(8)
print "\n"
print ("\n")

# Stop
MIFAREReader.MFRC522_StopCrypto1()

# Make sure to stop reading for cards
continue_reading = False
else:
print "Authentication error"
print ("Authentication error")