如何使用 python 将 .blf 数据从 CAN 转换为 .csv [英] How do I convert .blf data from CAN to .csv using python
本文介绍了如何使用 python 将 .blf 数据从 CAN 转换为 .csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有来自 Vector 软件的 blf 格式的 CAN-Data.为了进一步调查,我想使用 python 将其转换为 csv 格式.
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.
我目前的进展:
import can
filename = "test.blf"
log = can.BLFReader(filename)
我不知道那是不是正确的方法.我现在无法将日志"保存到 csv 文件.
I dont know if thats the right way. I can't save "log" to a csv file now.
这可能帮助>
推荐答案
原答案:
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)
新答案:
自从我发布这篇文章以来,我实际上创建了一个库,该库为 CAN 数据提供了类似 API 的 Pandas.在此处查看.可以在此处找到功能演示.
Since I've posted this I actually created a library which provides a pandas like API for CAN data. Check it out here. A demonstration of features can be found here.
- 处理CAN数据的常用格式
- 使用 dbc 文件中的数据自动丰富记录数据的绘图
- 适用于各种信号的多功能且可扩展的绘图功能
- 轻松将 CAN 数据导出到 Pandas 数据帧
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"]
这篇关于如何使用 python 将 .blf 数据从 CAN 转换为 .csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文