Adding a .csv CAN logger example

Logs on all 3 CAN busses to output.csv
This commit is contained in:
Adam Urban 2017-11-03 22:01:18 -04:00 committed by George Hotz
parent 849f68879d
commit ad21cd719e
1 changed files with 28 additions and 0 deletions

28
examples/can_logger.py Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python
import binascii
import csv
from panda import Panda
def can_logger():
try:
p = Panda()
outputfile = open('output.csv', 'wb')
csvwriter = csv.writer(outputfile)
#Write Header
csvwriter.writerow(['Bus', 'MessageID', 'Message'])
print("Writing csv file. Press Ctrl-C to exit...")
while True:
can_recv = p.can_recv()
for address, _, dat, src in can_recv:
csvwriter.writerow([str(src), str(address), binascii.hexlify(dat)])
except KeyboardInterrupt:
print("Exiting...")
outputfile.close()
if __name__ == "__main__":
can_logger()