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