Search code examples
c++cqextserialport

QextSerialPort - detect disconnection


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 ?


Solution

  • You queried the port, not the device. Send some kind of query message to the device that will produce a response message.