[英]How do I convert .blf data from CAN to .csv using python
I have CAN-Data in the blf-format from the Vector software.我有来自 Vector 软件的 blf 格式的 CAN 数据。 For further investigation I want to convert it into csv format using python.
为了进一步调查,我想使用 python 将其转换为 csv 格式。
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.
我现在无法将“日志”保存到 csv 文件。
Original answer:原答案:
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)
New answer:新答案:
Since I've posted this I actually created a library which provides a pandas like API for CAN data.因为我已经发布了这个,我实际上创建了一个库,它为 CAN 数据提供了像 API 这样的熊猫。 Check it out here .
在这里查看。 A demonstration of features can be found here .
可以在此处找到功能演示。
import candas as cd
db = cd.load_dbc("dbc_folder")
# Provide file without extension
log_data = cd.from_file("blf_file")
# Signals can be accessed like this
log_data["AVGcellTemperature"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.