QSerialPort::ResourceError called endlessly when USB detached
Hi,
My app' is talking with a GSM modem, over USB.
- /dev/ttyACM0 is used for pppd (external process, not within my Qt app').
- /dev/ttyACM5 is used for 'control' AT commands (RSSI, provider local time, voice calls, etc.)
Everything is working fine till the modem's USB cable is plugged out (actually, every few hours the modem crashes, or something else, which ends up in the USB interface is destroyed, what seems to my Linux as a detach-event).
On detach:
- pppd dies and frees /dev/ttyACM0.
- My QSerialPort receives a ResourceError signal, I call MyQSerialPort.close() and receive another ResourceError signal, in an endless loop. The app' finally crashes (but the Linux doesn't), but the modem has already reconnected and uDev creates ttyACM0, 1, 2, 3, 4, 6, 7 - missing ttyACM5 (because it was held by the app').
What am I doing wrong?
Should I disconnect all signals from MyQSerialPort before calling close(), and reconnect after?
I'm afraid of a memory/resource leak.
Qt 5.5.1, Linux.
Thanks
Re: QSerialPort::ResourceError called endlessly when USB detached
it is already be fixed in 5.6.0
Re: QSerialPort::ResourceError called endlessly when USB detached
I prefer not to upgrade my Qt version.
There's also the licencing issue that has changed in that version...
Re: QSerialPort::ResourceError called endlessly when USB detached
Delete the object and recreate it for further use?
Cheers,
_
Re: QSerialPort::ResourceError called endlessly when USB detached
For those coming here from Ubuntu or derivatives, I've uploaded a patched version of qt5 serialport package to my ppa: https://launchpad.net/~hyozd/+archiv...tu/serialplot/ . I basically back-ported fixes from Qt 5.6. Here is the diff:
Code:
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -208,14 +208,11 @@
void QSerialPortPrivate::close()
{
- if (settingsRestoredOnClose) {
- if (::tcsetattr(descriptor, TCSANOW, &restoredTermios) == -1)
- setError(getSystemError());
- }
+ if (settingsRestoredOnClose)
+ ::tcsetattr(descriptor, TCSANOW, &restoredTermios);
#ifdef TIOCNXCL
- if (::ioctl(descriptor, TIOCNXCL) == -1)
- setError(getSystemError());
+ ::ioctl(descriptor, TIOCNXCL);
#endif
if (readNotifier) {
@@ -228,8 +225,7 @@
writeNotifier = Q_NULLPTR;
}
- if (qt_safe_close(descriptor) == -1)
- setError(getSystemError());
+ qt_safe_close(descriptor);
lockFileScopedPointer.reset(Q_NULLPTR);