python如何讀取bin文件并下發(fā)串口
更新時間:2019年07月05日 10:39:29 作者:返回主頁 小甲魚
這篇文章主要介紹了python如何讀取bin文件并下發(fā)串口,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
下面是實現(xiàn)代碼
# 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)
# 將字節(jié)轉(zhuǎn)換成16進(jìn)制;
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進(jìn)制轉(zhuǎn)換為字節(jié)
if i % 16 == 0:
time.sleep(0.001)
#寫每一行等待的時間
i += 1
ser.close()
file.close()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python 序列化和反序列化庫 MarshMallow 的用法實例代碼
marshmallow(Object serialization and deserialization, lightweight and fluffy.)用于對對象進(jìn)行序列化和反序列化,并同步進(jìn)行數(shù)據(jù)驗證。這篇文章主要介紹了Python 序列化和反序列化庫 MarshMallow 的用法實例代碼,需要的朋友可以參考下2020-02-02
Python爬蟲庫BeautifulSoup的介紹與簡單使用實例
BeautifulSoup是一個可以從HTML或XML文件中提取數(shù)據(jù)的Python庫,本文為大家介紹下Python爬蟲庫BeautifulSoup的介紹與簡單使用實例其中包括了,BeautifulSoup解析HTML,BeautifulSoup獲取內(nèi)容,BeautifulSoup節(jié)點操作,BeautifulSoup獲取CSS屬性等實例2020-01-01
Tensorflow安裝問題: Could not find a version that satisfies the
這篇文章主要介紹了Tensorflow安裝問題: Could not find a version that satisfies the requirement tensorflow,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04

