简体   繁体   English

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

[英]How do I convert .asc data of CAN to .blf using python as per vector format

I have a.asc file, I want to convert it to.blf as per vector format.我有一个 .asc 文件,我想按照矢量格式将其转换为 .blf 。

I have tried,我努力了,

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)

I am able to read.asc, how do I write it to a.blf file as per vector format.我能够读取.asc,如何按照矢量格式将其写入 a.blf 文件。

Why are you reading your asc file with pandas if you're already working with the python-can module?如果您已经在使用python-can模块,为什么还要使用 pandas 读取您的 asc 文件?
You will find how to interact with asc and blf files in the doc here and there respectively.您将分别在此处此处的文档中找到如何与 asc 和 blf 文件进行交互。

One thing you should pay attention to is to read/write blf files in binary mode.您应该注意的一件事是以二进制模式读取/写入 blf 文件。 So in your example this should work (don't forget to stop the log otherwise the header will be missing):因此,在您的示例中,这应该可以工作(不要忘记停止日志,否则 header 将丢失):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 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修复损坏的.blf文件(来自Vector软件) - How do I fix a corrupted .blf file (from Vector software) using python-can Python 解析包含 CAN-TP Trame (ISO-TP) 的 CAN 日志文件(.asc 或 blf) - Python Parse a CAN log file (.asc or blf) that contains CAN-TP Trame (ISO-TP) Python CAN 日志转换器用于以下日志类型(ASC、BLF、CSV、LOG) - Python CAN Log Converter for the following log types (ASC, BLF, CSV, LOG) 如何将 python 中的时间戳转换为日期时间格式以获得 cosmos 数据? - How do I convert timestamp to datetime format in python for cosmos data? 如何使用Python以.asc文件格式读取/提取气候模型数据? - How to read/extract climate model data in .asc file format by using Python? 如何使用 python 将原始 CAN 数据转换为人类可读格式? - How to convert raw CAN data to human readable format using python? 如何使用 Python 将 CSV 文件转换为 XML 格式 - How can I convert CSV file into XML format using Python 如何在python中转换为整齐的格式? - How can I convert to a tidy format in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM