当前位置:主页 > 软件编程 > Python代码 >

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

时间:2021-05-01 09:35:31 | 栏目:Python代码 | 点击:

如下所示:

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()

您可能感兴趣的文章:

相关文章