如何使用Python按照矢量格式将CAN的.asc数据转换为.blf

问题描述 投票:0回答:1

我有一个 .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个回答
2
投票

如果您已经在使用

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()
© www.soinside.com 2019 - 2024. All rights reserved.