如何使用pythoncan修复损坏的.blf文件(来自Vector软件)

2024-10-03 00:21:35 发布

您现在位置:Python中文网/ 问答频道 /正文

这与this question类似,只是我希望以一个新的BLF文件而不是.csv文件结束。我这样做是为了删除BLF文件中的一个损坏的对象,它阻止我将其导入Vector的软件中。我想有办法直接通过can.io.blf公司.BLFReader'由BLFReader直接生成到BLFWriter的类对象,但我很难弄清楚如何生成。下面的示例代码应该有助于解释我想要实现的功能:

import can


filename_in = "corrupted.blf"
log = can.io.BLFReader(filename_in)
filename_out = "cleaned.blf"
can.io.BLFWriter(filename_out,log)

Tags: 文件csv对象iniologfilenameout
1条回答
网友
1楼 · 发布于 2024-10-03 00:21:35

我的解决方案是:

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()

相关问题 更多 >