How do I convert .blf data from CAN to .csv using python

故事扮演 提交于 2019-12-10 10:02:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!