简体   繁体   English

如何使用 python 将 .blf 数据从 CAN 转换为 .csv

[英]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 文件。

This might help这可能有帮助

Original answer:原答案:

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)

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 .可以在此处找到功能演示。

  • Common format for dealing with CAN data处理CAN数据的通用格式
  • Enrich plots of the logging data with data from the dbc files automatically使用 dbc 文件中的数据自动丰富记录数据的绘图
  • Versatile and extensible plotting functions for all kinds of signals适用于各种信号的多功能和可扩展的绘图功能
  • Easily export CAN data to a pandas dataframe轻松将 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"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM