You queried the port, not the device. Send some kind of query message to the device that will produce a response message.
QextSerialPort - detect disconnection
-
31-05-2022 - |
Question
I have a device connected to the computer as "COM8". I'd like to know when it is unplugged from the computer, so I used the following code to detect:
m_receiverCom->isWritable();
m_receiverCom->isOpen();
However, they still returned true after I unplugged the device. How can I detect whether the device is plugged or not ?
La solution
Autres conseils
Although an old thread, prevent people from getting stuck. I just ran into this problem, and I successfully used qextserialport to detect serial port disconnect/connect using:
QextSerialPort *serial_monitor;
serial_monitor = new QextSerialEnumerator();
serial_monitor->setUpNotifications();
connect(serial_monitor, SIGNAL(deviceRemoved(QextPortInfo)), this, SLOT(_handleUSBError(QextPortInfo)));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow