串口读写(python)

调试中用到的小工具,留存

import time
import serial
import binascii
ser1 = serial.Serial(port='COM7',baudrate=38400,timeout=0)
ser2 = serial.Serial(port='COM5',baudrate=38400,timeout=0)
while (1):
data = ser1.readall()
if(len(data)>0):
print(str(binascii.b2a_hex(data)))
ser2.write(data)
data = ser2.readall()
if(len(data)>0):
# time.sleep(0.01)
#print(binascii.b2a_hex(data))
ser1.write(data)

你可能感兴趣的:(Python)