I have used pyserial for a couple of days. However, a problem occurs today. I met serial write timeout. Several days before, when I used a switch, everything is OK. But today I changed for another switch. Then serial write timeout appears. I did not change any code, but the problem is actually quite severe. More seriously, the timeout not always occurs, which means that sometimes I can write in the serial successfully.
ser = serial.Serial( #Serial COM configuration
port='COM5',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
rtscts=True,
timeout=2,
writeTimeout=5
)
strInput = "show ver"
ser.flushInput()
ser.flushOutput()
ser.write(strInput.encode('utf-8')+b'\n')
I have ensured that the port is COM5 and the baudrate of the switch is 9600. Thanks a lot for answering my question.