summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2013-07-29 17:57:20 +0400
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-18 12:58:44 +0200
commitd8dc10efb1714dcfafa6a08e107fd31fc1e3ce0e (patch)
tree5bc4b5c8d1354d2fb7bbedd5419bed0d56f1be34
parent26c795f2b268aff1fc0655997215810ae8863790 (diff)
downloadqtserialport-d8dc10efb1714dcfafa6a08e107fd31fc1e3ce0e.tar.gz
Windows: acquire identifiers using the SetupDiGetDeviceInstanceId function
This decision uses one identification string of the device instead of the list of hardware identifiers. See more detail in MSDN: * http://msdn.microsoft.com/en-us/library/windows/hardware/ff551106%28v=vs.85%29.aspx * http://msdn.microsoft.com/en-us/library/windows/hardware/ff541327%28v=vs.85%29.aspx The device instance ID unambiguously identifies the device in system and contains necessary values of identifiers, that allows to resolve some issues: * we can abandon a patch: https://codereview.qt-project.org/#change,61633 and Task-number: QTBUG-32684 automatically will be resolved * we can apply a patch: https://codereview.qt-project.org/#change,61752 because instance ID also contains the serial number info Checked on Windows 7 and 8 with USB PL2303 converter, USB Modem ZTE MF180, USB Android Modems, USB Motorola CDC ACM device. Change-Id: If3b67b5b34d65de060a0e7682ba426cd94a01fa7 Reviewed-by: Laszlo Papp <lpapp@kde.org> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
-rw-r--r--src/serialport/qserialportinfo_win.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp
index b1ab76b..45236a0 100644
--- a/src/serialport/qserialportinfo_win.cpp
+++ b/src/serialport/qserialportinfo_win.cpp
@@ -114,6 +114,23 @@ static QVariant deviceRegistryProperty(HDEVINFO deviceInfoSet,
return QVariant();
}
+static QString deviceInstanceIdentifier(HDEVINFO deviceInfoSet,
+ PSP_DEVINFO_DATA deviceInfoData)
+{
+ DWORD requiredSize = 0;
+ if (::SetupDiGetDeviceInstanceId(deviceInfoSet, deviceInfoData, NULL, 0, &requiredSize))
+ return QString();
+
+ QByteArray data(requiredSize * sizeof(wchar_t), 0);
+ if (!::SetupDiGetDeviceInstanceId(deviceInfoSet, deviceInfoData,
+ reinterpret_cast<wchar_t *>(data.data()), data.size(), NULL)) {
+ // TODO: error handling with GetLastError
+ return QString();
+ }
+
+ return QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData()));
+}
+
static QString devicePortName(HDEVINFO deviceInfoSet, PSP_DEVINFO_DATA deviceInfoData)
{
static const wchar_t portKeyName[] = L"PortName";
@@ -177,7 +194,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
serialPortInfo.d_ptr->manufacturer =
deviceRegistryProperty(deviceInfoSet, &deviceInfoData, SPDRP_MFG).toString();
- s = deviceRegistryProperty(deviceInfoSet, &deviceInfoData, SPDRP_HARDWAREID).toStringList().first().toUpper();
+ s = deviceInstanceIdentifier(deviceInfoSet, &deviceInfoData).toUpper();
int index = s.indexOf(usbVendorIdentifierPrefix);
if (index != -1) {