How to plot and analyse CAN data directly on python?

800 views Asked by At

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?

0

There are 0 answers