summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2016-02-18 17:54:21 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2016-02-19 09:00:23 +0000
commit4e1873cea12c747aaa021e529051bcb2d3e85bb8 (patch)
treeede49a6d938883b84b67fdb0be30ddbcb3c7c20a
parentf4303a4d71b770ce4d990ff52efc6bedfb1020e5 (diff)
downloadqtserialport-4e1873cea12c747aaa021e529051bcb2d3e85bb8.tar.gz
Get serial number of bluetooth USB dongle on Windows
Now, the serial ports which are created by the bluetooth connection takes the serial numbers of the own USB bluetooth dongles. We enumerate all parent devices of a driver stack until their end has been reached, or the serial number has been found. Change-Id: I63820f34fd4c47992c3c5ef3c7ce63eca4ea0cf8 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialportinfo_win.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp
index 140f191..451efef 100644
--- a/src/serialport/qserialportinfo_win.cpp
+++ b/src/serialport/qserialportinfo_win.cpp
@@ -264,16 +264,22 @@ static QString parseDeviceSerialNumber(const QString &instanceIdentifier)
return instanceIdentifier.mid(firstbound + 1, lastbound - firstbound - 1);
}
-static QString deviceSerialNumber(const QString &instanceIdentifier,
+static QString deviceSerialNumber(QString instanceIdentifier,
DEVINST deviceInstanceNumber)
{
- QString result = parseDeviceSerialNumber(instanceIdentifier);
- if (result.isEmpty()) {
- const DEVINST parentNumber = parentDeviceInstanceNumber(deviceInstanceNumber);
- const QString parentInstanceIdentifier = deviceInstanceIdentifier(parentNumber);
- result = parseDeviceSerialNumber(parentInstanceIdentifier);
+ forever {
+ const QString result = parseDeviceSerialNumber(instanceIdentifier);
+ if (!result.isEmpty())
+ return result;
+ deviceInstanceNumber = parentDeviceInstanceNumber(deviceInstanceNumber);
+ if (deviceInstanceNumber == 0)
+ break;
+ instanceIdentifier = deviceInstanceIdentifier(deviceInstanceNumber);
+ if (instanceIdentifier.isEmpty())
+ break;
}
- return result;
+
+ return QString();
}
QList<QSerialPortInfo> QSerialPortInfo::availablePorts()