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