5

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.

3
  • How can you have a timeout on writing? Commented Aug 19, 2016 at 6:41
  • 1
    Increase writeTimeout value or remove the parameter. Commented Aug 19, 2016 at 7:03
  • Thanks for answering. I have already tried those methods, but the problem still exists. Commented Aug 19, 2016 at 7:29

3 Answers 3

1

I ran into this problem recently. I found that setting write_timeout=0 solved the issue (also, not really sure why a write timeout even exists...)

Another answer here suggests the same thing :)

Sign up to request clarification or add additional context in comments.

Comments

1

The problem may be that the interface tries to comply with RTS, CTS, DSR, or DTS signals. It is possible that if they are not properly connected, they can mysteriously affect communication through a timeout.

One solution may be to ignore their influence using rtscts=False and/or dsrdtr=False when opening the serial port in Python.

Comments

0

If you have flow control with request to send / clear to send structure and the device you are writing to isn't responding you need the timeout for the write in order to not hang

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.