07-11-2022, 09:29 PM
How to Convert .blf (CAN) to .csv in Python
5/5 – (1 vote)
Problem Formulation
How to convert from a CAN bus to in Python?
What is BLF? The Binary Logging Format (BLF) is a proprietary
CAN log format from the automative company Vector Informatik GmbH.
What is CAN? The Controller Area Network (CAN bus) is a message-based protocol standard for microcontrollers in vehicles to communicate without a host computer.
Method 1: Using BLF Reader and CSV Writer
To convert the BLF file to the CSV file , you can first iterate over the bus messages using and add the data to a list of lists. Then, you can use the approach to write the list of lists to a CSV file.
Here’s an example that improves upon this SO thread:
A more sophisticated version of this code is provided in this Github repository. Here’s a screenshot of the code — notice the more advanced processing of a single message compared to our solution:
source
Method 2: Using the candas Library
The library provides utility functions to work with files and the CAN bus. Among other things, it helps you with the conversion from BLF to CSV as outlined here.
This is the provided example:
Method 3: Using Custom Solution from python-can Library
You can use your tailor-made solutions by combining the Readers and Writers provided in the library.
It provides multiple utility functions such as:
Chances are you’ll find what you’re looking for when going over those functions!
Related Video
Still not satisfied? I found the following relevant video when searching for a solution to this problem. I think you’ll find some nice tricks in the video!
5/5 – (1 vote)
Problem Formulation
How to convert Code:
.blfCode:
.csv
What is BLF? The Binary Logging Format (BLF) is a proprietaryCAN log format from the automative company Vector Informatik GmbH.
What is CAN? The Controller Area Network (CAN bus) is a message-based protocol standard for microcontrollers in vehicles to communicate without a host computer.Method 1: Using BLF Reader and CSV Writer
To convert the BLF file
Code:
'my_file.blf'Code:
'my_file.csv'Code:
can.BLFReader('my_file.csv')Code:
csv.writer()Here’s an example that improves upon this SO thread:
Code:
import can
import csv log = [] for msg in list(can.BLFReader("my_file.blf")): msg = str(msg) row = [msg[18:26], msg[38:40], msg[40:42], msg[46], msg[62], msg[67:90]] log.append(row) with open("my_file.csv", "w", newline='') as f: writer = csv.writer(f, delimiter=',', quotechar='\"', quoting=csv.QUOTE_ALL) writer.writerows(log)A more sophisticated version of this code is provided in this Github repository. Here’s a screenshot of the code — notice the more advanced processing of a single message compared to our solution:
sourceMethod 2: Using the candas Library
The
Code:
candasCode:
.blfThis is the provided example:
Code:
import candas as cd db = cd.load_dbc("dbc_folder") # This is the BLF file 'my_file.blf':
log = cd.from_file("my_file") # This prints a signal from the messages in the BLF:
print(log["AVGcellTemperature"])You can use your tailor-made solutions by combining the Readers and Writers provided in the
Code:
python-canIt provides multiple utility functions such as:
- Code:
Listener
- Code:
BufferedReader
- Code:
RedirectReader
- Code:
Logger
- Code:
Printer
- Code:
CSVWriter
- Code:
SqliteWriter
- Code:
ASC
- Code:
Log
- Code:
BLF
Chances are you’ll find what you’re looking for when going over those functions!
Related Video
Still not satisfied? I found the following relevant video when searching for a solution to this problem. I think you’ll find some nice tricks in the video!

