portx="COM4"
# Baud rate , One of the standard values :50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400,57600,115200
bps=115200
# timeout ,None: Always wait for the operation ,0 To return the requested result immediately , Other values are wait timeout ( The unit is in seconds )
timex=5
# Open the serial port , And get the serial object
ser=serial.Serial(portx,bps,timeout=timex)
ser.write(“hello") Is to write data to the serial port
ser.close() It's closing ser The serial port
ser.open() Will open the serial port
ser = serial.Serial('COM1', 115200) To set the baud rate , Of course, there are special functions
data = ser.read() Can read one character
data = ser.read(20) Yes. 20 Characters