diff --git a/python/RFIDler/__init__.py b/python/RFIDler/__init__.py index 3b9ac02..077eda5 100755 --- a/python/RFIDler/__init__.py +++ b/python/RFIDler/__init__.py @@ -156,11 +156,10 @@ def send_command(self, tosend): """ try: if self.Debug: - print '\r\n>>>', tosend, - self.Connection.write(tosend + "\r\n") + print ('\r\n>>>', tosend, self.Connection.write(tosend + "\r\n")) except: if self.Debug: - print '(fail!)' + print ('(fail!)') return False, "Serial communications failure (send)!" if self.Debug: @@ -168,17 +167,17 @@ def send_command(self, tosend): try: result = self.Connection.read(1) if self.Debug: - print '\r\n<<<', + print ('\r\n<<<'), if not result in '.+!?': if self.Debug: - print result, '(fail!)' + print (result, '(fail!)') return False, result if self.Debug: - print result + print (result) return True, result except: if self.Debug: - print '(fail!)' + print ('(fail!)') return False, "Serial communications failure (receive)!" def command(self, tosend): @@ -208,7 +207,7 @@ def command(self, tosend): while 42: item = self.Connection.readline().replace('\r', '').replace('\n', '') if self.Debug: - print '<<<', item + print ('<<<', item) if item == '*': return True, data data.append(item) diff --git a/python/rfidler.py b/python/rfidler.py index 98cfefb..cfc4728 100755 --- a/python/rfidler.py +++ b/python/rfidler.py @@ -157,7 +157,7 @@ def output(message): if not Quiet: - print message + print (message) def store_data(data, filename_prefix = "dump"): @@ -173,7 +173,7 @@ def load_data(fname): try: with open(fname, "r") as f: lines = f.readlines() - except Exception, e: + except Exception as e: return [False, str(e)] return [True, lines] @@ -338,7 +338,7 @@ def plot_data(data): pyplot.show() if len(sys.argv) < 3: - print """ + print (""" usage: {0} [ARGS] [COMMAND [ARGS] ...] Commands: @@ -356,14 +356,14 @@ def plot_data(data): Commands will be executed sequentially. Unrecognised commands will be passed directly to RFIDler. Commands with arguments to be passed directly should be quoted. e.g. "SET TAG FDXB" -""".format(*sys.argv) +""".format(*sys.argv)) exit(True) port = sys.argv[1] rfidler = RFIDler.RFIDler() result, reason = rfidler.connect(port) if not result: - print 'Warning - could not open serial port:', reason + print ('Warning - could not open serial port:', reason) current = 2 # process each command @@ -377,7 +377,7 @@ def plot_data(data): if sys.argv[current].upper() == 'OFF': rfidler.Debug = False else: - print 'Unknown option:', sys.argv[current] + print ('Unknown option:', sys.argv[current]) exit(True) current += 1 continue @@ -386,17 +386,17 @@ def plot_data(data): if not os.path.exists('/dev/RFIDlerBL'): result, reason = rfidler.command('BL') if not result: - print 'could not set bootloader mode!' + print ( 'could not set bootloader mode!') exit(True) rfidler.disconnect() time.sleep(1) if os.path.exists('/dev/RFIDlerBL'): - print 'bootloader mode - flashing...' + print ('bootloader mode - flashing...') os.system('mphidflash -r -w %s' % sys.argv[current]) else: - print 'bootloader not detected!' + print ('bootloader not detected!') exit(True) - print 'Waiting for reboot...' + print ('Waiting for reboot...') while 42: result, reason = rfidler.connect(port) if result: @@ -405,7 +405,7 @@ def plot_data(data): break if command == 'FLASHP': time.sleep(1) - print 'Load next board' + print ('Load next board') # wait for disconnect while 42: try: @@ -415,7 +415,7 @@ def plot_data(data): break except: break - print 'Waiting for board...' + print ('Waiting for board...') # wait for new board in normal or bootloader mode while 42: result, reason = rfidler.connect(port) @@ -464,22 +464,22 @@ def plot_data(data): # requires hardware to be placed on test jig if command == 'TEST': test = 1 - print 'Testing H/W. Hit to end.' + print ('Testing H/W. Hit to end.') while 42: - print 'waiting for board...' + print ('waiting for board...') while 42: rfidler.disconnect() result, reason = rfidler.connect(port) if result: break if os.path.exists('/dev/RFIDlerBL'): - print 'bootloader mode - flashing...' + print ('bootloader mode - flashing...') os.system( 'mphidflash -r -w /home/software/unpacked/RFIDler/firmware/Pic32/RFIDler.X/dist/debug/production/RFIDler.X.production.hex') os.system('clear') test_result = 'Pass' - print 'Starting test', test + print ('Starting test', test) for x in 'PING', \ 'DEBUGOFF 0', \ 'DEBUGON 4', \ @@ -487,19 +487,18 @@ def plot_data(data): 'DEBUGON 3', 'SET TAG INDALA64', 'UID', 'DEBUGOFF 3', \ 'TEST-WIEGAND', 'TEST-SC', 'TEST-SD', \ 'SET TAG HID26', 'ENCODE 12345678 HID26', 'EMULATOR BG', 'WIEGAND-OUT OFF', 'TEST-WIEGAND-READ 1': - print ' Test %s - ' % x, - sys.stdout.flush() + print (' Test %s - ' % x, sys.stdout.flush()) for z in range(10): result, data = rfidler.command(x) if result: break - print result, data + print (result, data) if not result: test_result = 'Fail!' # now wait for board to change os.system('figlet ' + test_result) test += 1 - print 'load next board' + print ('load next board') while 42: try: result, data = rfidler.command('PING') @@ -540,7 +539,7 @@ def plot_data(data): result, data = rfidler.command(command) if result: for line in data: - print line + print (line) else: output('Failed: ' + data) continue