使用python脚本分析kingst逻辑分析仪导出的txt格式数据--基于uart协议

1、kingst逻辑分析仪导出的txt数据格式如下:

Time [s],Value,Parity Error,Framing Error
0.0000863000,0x12,,
0.0000913000,0x34,,
0.0000963000,0x56,,
0.0001013000,0x01,,
0.0001063000,0x01,,
0.0001113000,0x01,,
0.0001163000,0x01,,
...

第一列是接收字符的时间,第二列是接收的字符;

2、结合自己的使用场景(作者的uart发送的是can报文,16个字符为一个包),需要将字符提取出来并且16个为一行生成新的txt文档,便于分析can报文,python代码如下:

file_name = "2021-12-29_15-21-19.txt"

chars_each_line = 16
recv_times = []
recv_chars = []

(file_date,file_suffix) = file_name.split('.')
after_file_name = file_date + "_temp" + "." + file_suffix

def save_file(recv_chars):
    after_file = open(after_file_name, 'w')
    for i in range(len(recv_chars)):
        if i%chars_each_line  == 0:
            after_file.writelines("\n")
            after_file.writelines(recv_chars[i])
        else:
            after_file.writelines(recv_chars[i])
    after_file.close()

file = open(file_name, "r")
for each_line in file:
    if  "Time" not in each_line:
        (recv_time, recv_char, temp) = each_line.split(',',2)
        recv_times.append(recv_time)
        recv_chars.append(recv_char)

save_file(recv_chars)
file.close()

 3、输入文件名为2021-12-29_15-21-19.txt,最后生成文件2021-12-29_15-21-19_temp.txt,内容如下:

空行

0x120x340x560x010x010x010x010x010x010x010x010x010x010x010x01
0x120x340x560x020x020x020x020x020x020x020x020x020x020x020x02
0x120x340x560x030x030x030x030x030x030x030x030x030x030x030x03

...

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值