Python3 串口接收與發送16進制數據包的實例


Python3 串口接收與發送16進制數據包的實例

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM