PDA

View Full Version : QSerialPort very slow to close



BrianNorman
29th April 2016, 18:10
I have a QSerialPort m_serialPort communicating correctly with a Bluetooth connection. I can close the port from the code using m_serialPort->close() and it works normally.

If I power off the device I can detect that it has gone because I 'ping' my device every second. When I get no answer to my 'ping' I try to close the port but m_serialPort->close() takes 20s to return.

Why does it take 20s?

If this is unavoidable is there another way I can 'kill' the QSerialPort?

Thanks

d_stranz
30th April 2016, 17:16
Operating systems generally have a defined time-out period for ports, network sockets, and the like where they wait until this time has elapsed before releasing the system resources. This is probably to improve reliability - these are drivers for physical devices after all, and if there is a momentary break in communications, the software shouldn't instantly shut down the channel but wait a reasonable amount of time before concluding that the connection is truly broken. These protocols were developed back in the days when 110 and 300 baud modems were the norm, so what was a "reasonable time" then isn't so reasonable now.

Most operating systems give you a way to set these timeouts, see the Windows documentation (https://msdn.microsoft.com/en-us/library/aa363421%28v=vs.85%29.aspx), for example. You may have to dip into OS-specific coding in order to get access to that, though.