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

JulianWgs
  • 961
  • 1
  • 14
  • 25

1 Answers1

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"]
JulianWgs
  • 961
  • 1
  • 14
  • 25
  • 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 '18 at 07:11
  • Please upload the .blf somewhere and I will have a look – JulianWgs May 28 '18 at 07:13
  • I never got this error before. May be you could upload a dummy file? – JulianWgs May 28 '18 at 08: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 '18 at 08: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 '18 at 08:54
  • @JulianWgs I have a little bit of a doubt in using your CANdas library. I'm trying to work with the library but I am running into some issues. Your help would be greatly appreciated. – Prashanth L Sep 20 '22 at 17:40
  • @PrashanthL Please create an issue at the repo either at GitHub or GitLab and include a minimal example of what problem you are trying to solve. I will gladly help you :) (I know usually the repo isnt the place for questions, but for now it is Okay) – JulianWgs Sep 22 '22 at 07:20