问题
I have CAN-Data in the blf-format from the Vector software. For further investigation I want to convert it into csv format using python.
My progress so far:
import can
filename = "test.blf"
log = can.BLFReader(filename)
I dont know if thats the right way. I can't save "log" to a csv file now.
This might help
回答1:
List of that object does the trick
import can
import csv
filename = "test.blf"
log = can.BLFReader("test.blf")
log = list(log)
log_output = []
for msg in log:
msg = str(msg)
log_output.append([msg[18:26],msg[38:40],msg[40:42],msg[46],msg[62],msg[67:90]])
with open("output.csv", "w", newline='') as f:
writer = csv.writer(f,delimiter=';', quotechar='\"', quoting=csv.QUOTE_ALL)
writer.writerows(log_output)
来源:https://stackoverflow.com/questions/49499903/how-do-i-convert-blf-data-from-can-to-csv-using-python