简体   繁体   English

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

[英]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.

相关问题 如何按照矢量格式使用 python 将 CAN 的 .asc 数据转换为 .blf - How do I convert .asc data of CAN to .blf using python as per vector format 如何使用 python 将 CAN 的.blf 数据转换为.asc - How do I convert .blf data of CAN to .asc using python 如何使用 python 将 .blf 数据从 CAN 转换为 .csv - How do I convert .blf data from CAN to .csv using python 如何从python-can接口中捕获CAN总线异常,例如'Network down'? - How can I trap CAN bus exceptions such as 'Network down' from within python-can interfaces? 如何使用SocketCAN或Python-can发送和接收文件? - How to send and receive a file in SocketCAN or Python-can? "在矢量硬件上使用 python-can 库在 CAN FD 上发送长消息" - Sending long messages on CAN FD using python-can library on vector hardware Python-can 记录文件时间 - Python-can Logging File Time 我的 python 安装损坏/损坏。 我如何解决它? - My python installation is broken/corrupted. How do I fix it? 如何在使用CANard库的Python中使用ISOTP协议发送和接收CAN消息? - How to send and receive CAN message using ISOTP protocol in Python-can which uses CANard library? 如何使用Python-CAN查看CAN网络的错误帧 - How to see the error frames of a CAN network with Python-CAN
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM