Notification when serial port is plugged or unplugged
-
I want to get signalled when a USB serial port is plugged or un plugged.
how can I get it? -
if you are working in Linux, you can check existing USB port periodically.
@
foreach(QSerialPortInfo m, QSerialPortInfo::availablePorts())
{
if(m.portName().contains("ttyUSB"))
//USB serial is plugged
else
//USB serial is unplugged}
@
or check existing file "/dev/ttyUSB0"
@
if(QFile::exists("/dev/ttyUSB0"))
//USB Serial is Plugged
else
//Unplugged
@ -
Yes.
Also you can take a source code (just an do copy/paste) from an "QSerialDevice":https://gitorious.org/qserialdevice/qserialdevice/source/55692a7caf58fba51f859b8e015b2bbd7d92e1b6:src/qserialdeviceenumerator or "QextSerialPort":http://code.google.com/p/qextserialport/source/browse/#git/src project. Look in enumerator files.
UPD: Besides, if you want to got a notify about unplugged previously opened serial port, you can use QtSerialPort module and connect to the error signal with the ResourceError value.
Note: The official QtSerialPort module do not support the notifications that you want. You should implement it yourself (appropriate URL's I provided).
-
ok. thanks for both of you.