4

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 Answer 1

8

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. Check it out here. A demonstration of features can be found here.

  • Common format for dealing with CAN data
  • Enrich plots of the logging data with data from the dbc files automatically
  • Versatile and extensible plotting functions for all kinds of signals
  • Easily export CAN data to a pandas dataframe
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"]
7
  • 1
    I tried this approach and get assert header[0] == b"LOBJ", "Parse error" (File "C:\Users\my_user_name\AppData\Local\Python\Python36\lib\site-packages\can\io\blf.py", line 129, in __iter__). The BLF file I try to pass is a legit Vector CANoe log file. Any ideas?
    – z33k
    May 28, 2018 at 7:11
  • Please upload the .blf somewhere and I will have a look 😊
    – JulianWgs
    May 28, 2018 at 7:13
  • I never got this error before. May be you could upload a dummy file?
    – JulianWgs
    May 28, 2018 at 8:00
  • It's beyond my current knowledge of CANoe to generate a dummy one (I'm new on the job), but I know for sure the file is legit because I can convert it to CSV using Vector CANoe itself (Tools >> Logging File Conversion dialog) with no issues.
    – z33k
    May 28, 2018 at 8:50
  • I believe you that it is legit, but the only way to know if its a problem on your side or in the code is to give me some kind of test-blf-file. May be you can send me some log which isnt confidential. Also it just needs to be very short (1s)
    – JulianWgs
    May 28, 2018 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.