1

I have a .asc file, I want to convert it to .blf as per vector format.

I have tried,

from can.io import BLFWriter
import can
import pandas as pd
 
#input paths
path = '/home/ranjeet/Downloads/CAN/BLF_READER/input/'
asc_file = '20171209_1610_15017.asc'
blf_file = '20171209_1610_15017.blf'

df = pd.read_table(path + asc_file)
print(df)

I am able to read .asc, how do I write it to a .blf file as per vector format.

Ranjeet R Patil
  • 453
  • 6
  • 10

1 Answers1

2

Why are you reading your asc file with pandas if you're already working with the python-can module?
You will find how to interact with asc and blf files in the doc here and there respectively.

One thing you should pay attention to is to read/write blf files in binary mode. So in your example this should work (don't forget to stop the log otherwise the header will be missing):

import can

with open(asc_file, 'r') as f_in:
    log_in = can.io.ASCReader(f_in)

    with open(blf_file, 'wb') as f_out:
        log_out = can.io.BLFWriter(f_out)
        for msg in log_in:
            log_out.on_message_received(msg)
        log_out.stop()
Tranbi
  • 11,407
  • 6
  • 16
  • 33