www.cnblogs.com/ruiyqinrui

开源、架构、Linux C/C++/python AI BI 运维开发自动化运维。 春风桃李花 秋雨梧桐叶。“力尽不知热 但惜夏日长”。夏不惜,秋不获。@ruiY--秦瑞

python爬虫,C编程,嵌入式开发.hadoop大数据,桉树,onenebula云计算架构.linux运维及驱动开发.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

python读取bin文件并下发串口

 
# coding:utf-8
import time, serial
from struct import *
import binascii

file = open('E:\\1.bin', 'rb')
i = 0
while 1:
c = file.read(1)
# 将字节转换成16进制;
ssss = str(binascii.b2a_hex(c))[2:-1]
print(str(binascii.b2a_hex(c))[2:-1])
if not c:
break
ser = serial.Serial('COM3', 57600, timeout=1)
ser.write(bytes().fromhex(ssss))# 将16进制转换为字节
if i % 16 == 0:
time.sleep(0.001)
#写每一行等待的时间

i += 1
ser.close()
file.close()
posted on 2018-10-17 14:17  秦瑞It行程实录  阅读(12285)  评论(0编辑  收藏  举报
www.cnblogs.com/ruiyqinrui