0

I need to analyse a lot of CAN data and want to use python for that. I recently came across the python-can library and saw that it's possible to convert .blf to .asc files.

How do I convert .blf data of CAN to .asc using python This post helped a lot.

https://stackoverflow.com/users/13525512/tranbi Can @Tranbi or anyone else help me with some example code?

This is the part I have done till now:

import can
import os

fileList = os.listdir(".\inputFiles")

for i in range(len(fileList)):
    with open(os.path.join(".\inputFiles", fileList[i]), 'rb') as f_in:
        log_in = can.io.BLFReader(f_in)

        with open(os.path.join(".\outputFiles", os.path.splitext(fileList[i])[0] + '.asc'), 'w') as f_out:
            log_out = can.io.ASCWriter(f_out)
            for msg in log_in:
                log_out.on_message_received(msg)
            log_out.stop()

I need to either directly read data from .blf files sequentially, or convert them to .asc, correct the timestamp using the file name, combine the files, convert them to .csv and then analyse in python. Would really help if I can get a shorter route?

  • Question needs some code: Please provide enough code so others can better understand or reproduce the problem: https://stackoverflow.com/help/minimal-reproducible-example – D.L Apr 07 '22 at 16:08
  • What exactly do you plan to plot and what kind of analysis do you want to conduct? The .asc file will only contain Bytes for specific Timestamps/Message IDs. If you want to analyse/plot physical values, you'll need a description file like .dbc. – Tranbi Apr 07 '22 at 19:07
  • Yes, you are correct. I do have the .dbc file and I want to plot and analyse the physical values. I saw there is another library called cantools to load .dbc files, but since I am not very good in python programming, I am not able to use the libraries with just the documentation. Can you help me make a example code? – SAPTARSHI PAN Apr 11 '22 at 09:46
  • Why do you wanna do it with python then? There are some free tools out there to plot can signals with dbc support. – Tranbi Apr 13 '22 at 12:25
  • I have too many files to analyse and I want to do some automated calculations. Also, we have some restrictions on installing new tools. – SAPTARSHI PAN Apr 13 '22 at 14:12
  • Your question needs more details and focus. The code you provided only converts blf files to asc iiuc. Try to split the tasks in subtasks: read messages, interpret signals from DBC, store relevant signals to a format suited for analysis (e.g. pandas dataframe), formulate the analysis you want to perform. If you need assistance along the way, people here (including myself) will gladly help, given your provide necessary info/data to reproduce the problem. – Tranbi Apr 14 '22 at 15:18

0 Answers0