1

This is similar to this question, except I would like to end up with a new BLF file instead of a .csv file. I am doing this to remove a corrupted object in the BLF file that keeps me from importing it into Vector's software. I imagine there is a way to directly pass the 'can.io.blf.BLFReader' class object generated by BLFReader directly to BLFWriter, but I am having trouble figuring out how. The example code below should help explain the functionality I would like to achieve:

import can


filename_in = "corrupted.blf"
log = can.io.BLFReader(filename_in)
filename_out = "cleaned.blf"
can.io.BLFWriter(filename_out,log)
LoveToCode
  • 788
  • 6
  • 14

1 Answers1

0

Here is my solution:

def BLFRepair(filename_in, filename_out):
""" Repairs a corrupted Vector .blf fileself.
Args:
    filename_in (str): Filename of input corrupted file.
    filename_out (str): Filename to save repaired file with.
"""
cleaned_log=BLFReader(filename_in)   # ignores errors
logger=BLFWriter(filename_out)
for msg in cleaned_log:
    logger.on_message_received(msg)

logger.stop()
LoveToCode
  • 788
  • 6
  • 14