diff options
author | Laszlo Papp <lpapp@kde.org> | 2013-07-27 16:57:08 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-02 21:05:07 +0100 |
commit | 959775c41683033adbd99faab7e3d70e0009c143 (patch) | |
tree | 4d6586946d44617271dbbc56840d45196e855dec /src/serialport/qserialportinfo_win.cpp | |
parent | 5a2314414fc89c6ef44521f6d13899045b6da7af (diff) | |
download | qtserialport-959775c41683033adbd99faab7e3d70e0009c143.tar.gz |
Add API for querying the serial number
Thanks go to Massimo Callegari for the initial patch and the request to remind
us again. Thanks also go to Denis and Sergey for working on the windows serial
number parser.
Task-number: QTBUG-31981
Change-Id: I60d882280f481eb99d275e0a9c81da50292b1c61
Reviewed-by: Massimo Callegari <massimocallegari@yahoo.it>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Diffstat (limited to 'src/serialport/qserialportinfo_win.cpp')
-rw-r--r-- | src/serialport/qserialportinfo_win.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp index 85d40cc..448f3ed 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -195,6 +195,28 @@ private: const QString &m_serialPortName; }; +static QString deviceSerialNumber(const QString &instanceIdentifier) +{ + int firstbound = instanceIdentifier.lastIndexOf(QLatin1Char('\\')); + int lastbound = instanceIdentifier.indexOf(QLatin1Char('_'), firstbound); + if (instanceIdentifier.startsWith(QStringLiteral("USB\\"))) { + if (lastbound != instanceIdentifier.size() - 3) + lastbound = instanceIdentifier.size(); + int ampersand = instanceIdentifier.indexOf(QLatin1Char('&'), firstbound); + if (ampersand != -1 && ampersand < lastbound) + return QString(); + } else if (instanceIdentifier.startsWith(QStringLiteral("FTDIBUS\\"))) { + firstbound = instanceIdentifier.lastIndexOf(QLatin1Char('+')); + lastbound = instanceIdentifier.indexOf(QLatin1Char('\\'), firstbound); + if (lastbound == -1) + return QString(); + } else { + return QString(); + } + + return instanceIdentifier.mid(firstbound + 1, lastbound - firstbound - 1); +} + QList<QSerialPortInfo> QSerialPortInfo::availablePorts() { static const QString usbVendorIdentifierPrefix(QStringLiteral("VID_")); @@ -238,6 +260,8 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() s = deviceInstanceIdentifier(deviceInfoSet, &deviceInfoData).toUpper(); + serialPortInfo.d_ptr->serialNumber = deviceSerialNumber(s); + int index = s.indexOf(usbVendorIdentifierPrefix); if (index != -1) { serialPortInfo.d_ptr->vendorIdentifier = s.mid(index + usbVendorIdentifierPrefix.size(), vendorIdentifierSize) |