[英]How do I fix a corrupted .blf file (from Vector software) using python-can
This is similar to this question , except I would like to end up with a new BLF file instead of a .csv file. 这类似于这个问题 ,除了我想以一个新的BLF文件而不是一个.csv文件结尾。 I am doing this to remove a corrupted object in the BLF file that keeps me from importing it into Vector's software.
我这样做是为了删除BLF文件中的损坏对象,该对象使我无法将其导入Vector的软件中。 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.
我想有一种方法可以直接将BLFReader生成的'can.io.blf.BLFReader'类对象直接传递给BLFWriter,但是我很难弄清楚该如何做。 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)
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.