【问题标题】:How do I convert .asc data of CAN to .blf using python as per vector format如何根据矢量格式使用 python 将 CAN 的 .asc 数据转换为 .blf
【发布时间】:2022-01-18 14:35:33
【问题描述】:

我有一个 .asc 文件,我想将其转换为矢量格式的 .blf。

我试过了,

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)

我能够读取 .asc,如何按照矢量格式将其写入 .blf 文件。

【问题讨论】:

    标签: python python-3.x vector ascii can-bus


    【解决方案1】:

    如果您已经在使用 python-can 模块,为什么还要使用 pandas 读取 asc 文件?
    您将分别在文档 herethere 中找到如何与 asc 和 blf 文件进行交互。

    您应该注意的一件事是以二进制模式读取/写入 blf 文件。因此,在您的示例中,这应该可以工作(不要忘记停止日志,否则标题将丢失):

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      • 1970-01-01
      • 2020-12-08
      • 2011-07-13
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多