Skip to content

Commit

Permalink
Fix can_logger.py to run correctly on python3 (commaai#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
claydugo authored and robbederks committed Nov 27, 2019
1 parent 7f9b4a5 commit 000282e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions examples/can_logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

import binascii
import csv
import sys
from panda import Panda
Expand All @@ -21,7 +20,7 @@ def can_logger():
sys.exit(0)

try:
outputfile = open('output.csv', 'wb')
outputfile = open('output.csv', 'w')
csvwriter = csv.writer(outputfile)
#Write Header
csvwriter.writerow(['Bus', 'MessageID', 'Message', 'MessageLength'])
Expand All @@ -35,7 +34,7 @@ def can_logger():
can_recv = p.can_recv()

for address, _, dat, src in can_recv:
csvwriter.writerow([str(src), str(hex(address)), "0x" + binascii.hexlify(dat), len(dat)])
csvwriter.writerow([str(src), str(hex(address)), f"0x{dat.hex()}", len(dat)])

if src == 0:
bus0_msg_cnt += 1
Expand All @@ -44,10 +43,10 @@ def can_logger():
elif src == 2:
bus2_msg_cnt += 1

print("Message Counts... Bus 0: " + str(bus0_msg_cnt) + " Bus 1: " + str(bus1_msg_cnt) + " Bus 2: " + str(bus2_msg_cnt), end='\r')
print(f"Message Counts... Bus 0: {bus0_msg_cnt} Bus 1: {bus1_msg_cnt} Bus 2: {bus2_msg_cnt}", end='\r')

except KeyboardInterrupt:
print("\nNow exiting. Final message Counts... Bus 0: " + str(bus0_msg_cnt) + " Bus 1: " + str(bus1_msg_cnt) + " Bus 2: " + str(bus2_msg_cnt))
print(f"\nNow exiting. Final message Counts... Bus 0: {bus0_msg_cnt} Bus 1: {bus1_msg_cnt} Bus 2: {bus2_msg_cnt}")
outputfile.close()

if __name__ == "__main__":
Expand Down

0 comments on commit 000282e

Please sign in to comment.