'PySerial: Open port takes too long
I'm communicating from my PC to a Nucleo-Board via UART. For that I'm using PySerial, a FTDI-USB-Cable for data connection and a USB-Cable for power. open() works fine, except when I remove the power from my Nucleo-Board. Then open() needs way too long (2-4 seconds). "Okay, then just don't remove the power from the Nucleo-Board". Yeah true, but I want to handle this case -> it will open an error window. The only problem is, that it takes 2-4 seconds to open that window because open() takes too long.
A problem could be that the UART cable is still connected which makes the COM-Port available which won't raise an error when using open(). But I don't know why it takes so long. It doesn't communicate with the Board yet, it just opens the COM Port, right? If it already communicates, then it could be a problem, because the Board does not respond because it's not connected to the power.
My code to check how long open() takes:
start_serialwrite1 = time.perf_counter()
try:
self.ser.open()
end_serialwrite1 = time.perf_counter()
print(f"time serialwrite1: {end_serialwrite1-start_serialwrite1}")
except serial.SerialException as e:
print("ERROR")
self.ser.close()
Output, when I unplug the power cable:
time serialwrite1: 3.3720932
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
