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

fix python3 print statements and exception style #42

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
15 changes: 7 additions & 8 deletions python/RFIDler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,29 +156,28 @@ 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:
print
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):
Expand Down Expand Up @@ -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)
Expand Down
41 changes: 20 additions & 21 deletions python/rfidler.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@

def output(message):
if not Quiet:
print message
print (message)


def store_data(data, filename_prefix = "dump"):
Expand All @@ -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]
Expand Down Expand Up @@ -338,7 +338,7 @@ def plot_data(data):
pyplot.show()

if len(sys.argv) < 3:
print """
print ("""
usage: {0} <PORT> <COMMAND> [ARGS] [COMMAND [ARGS] ...]

Commands:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -464,42 +464,41 @@ def plot_data(data):
# requires hardware to be placed on test jig
if command == 'TEST':
test = 1
print 'Testing H/W. Hit <ESC> to end.'
print ('Testing H/W. Hit <ESC> 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', \
'DEBUGON 2', 'SET TAG HITAG2', 'UID', 'DEBUGOFF 2', \
'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')
Expand Down Expand Up @@ -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