Leif160519的blog Leif160519的blog

——————

目录
Python3 串口接收与发送16进制数据包
/  

Python3 串口接收与发送16进制数据包

本文摘自:https://blog.csdn.net/colcloud/article/details/42490867

import serial
import string
import binascii
s=serial.Serial('com4',9600)
s.open()
#接收
n=s.inwaiting()
if n: 
    data= str(binascii.b2a_hex(s.read(n)))[2:-1]
    print(data)
#发送 
d=bytes.fromhex('10 11 12 34 3f') 
s.write(d)
s.close()

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题 Python3 串口接收与发送16进制数据包
作  者Leif160519
出  处https://github.icu/articles/2019/10/08/1570525201287.html
关于博主:坐标南京,运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!