PDA

View Full Version : QSerialPort::ResourceError called endlessly when USB detached



RamiRosenbaum
31st March 2016, 09:55
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

kuzulis
31st March 2016, 14:23
it is already be fixed in 5.6.0

RamiRosenbaum
31st March 2016, 15:03
I prefer not to upgrade my Qt version.
There's also the licencing issue that has changed in that version...

anda_skoa
31st March 2016, 15:34
Delete the object and recreate it for further use?

Cheers,
_

HeyYO
9th August 2016, 16:22
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/+archive/ubuntu/serialplot/ . I basically back-ported fixes from Qt 5.6. Here is the diff:


--- 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);