The unified diff between revisions [914b5530..] and [e38734b6..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'mifare.py'

#
#
# patch "mifare.py"
#  from [edcbcd9ef15300e17e3fb644de4d66261a4f4077]
#    to [3ff37acf0f531b9f5bc9000c14e82bc8ca4a097b]
#
============================================================
--- mifare.py	edcbcd9ef15300e17e3fb644de4d66261a4f4077
+++ mifare.py	3ff37acf0f531b9f5bc9000c14e82bc8ca4a097b
@@ -49,6 +49,13 @@ class MIFAREReader:
     def send_packet(self, data):
         '''Constructs a packet for the supplied data string, sends it to the
         MIFARE reader, then returns the response (if any) to the commmand.'''
+
+        # Occasionally the reader inserts extra trailing characters into its
+        # responses, so flush the buffers if possible beforehand.
+        if isinstance(self.io, serial.Serial):
+            self.io.flushInput()
+            self.io.flushOutput()
+
         # XXX - Needs more error checking.
         data = '\x00' + self.address + data
         packet = '\xAA\xBB' + chr(len(data)) + data + checksum(data)