diff options
-rw-r--r-- | examples/cenumerator/main.cpp | 4 | ||||
-rw-r--r-- | examples/enumerator/main.cpp | 19 | ||||
-rw-r--r-- | examples/terminal/settingsdialog.cpp | 9 | ||||
-rw-r--r-- | src/serialport/qserialportinfo.cpp | 18 | ||||
-rw-r--r-- | src/serialport/qserialportinfo.h | 4 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_mac.cpp | 6 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_p.h | 6 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_unix.cpp | 9 | ||||
-rw-r--r-- | src/serialport/qserialportinfo_win.cpp | 4 |
9 files changed, 38 insertions, 41 deletions
diff --git a/examples/cenumerator/main.cpp b/examples/cenumerator/main.cpp index 11af6183..3ae7d65e 100644 --- a/examples/cenumerator/main.cpp +++ b/examples/cenumerator/main.cpp @@ -59,8 +59,8 @@ int main(int argc, char *argv[]) << QObject::tr("Location: ") << serialPortInfo.systemLocation() << endl << QObject::tr("Description: ") << serialPortInfo.description() << endl << QObject::tr("Manufacturer: ") << serialPortInfo.manufacturer() << endl - << QObject::tr("Vendor Identifier: ") << serialPortInfo.vendorIdentifier() << endl - << QObject::tr("Product Identifier: ") << serialPortInfo.productIdentifier() << endl + << QObject::tr("Vendor Identifier: ") << QByteArray::number(serialPortInfo.vendorIdentifier(), 16) << endl + << QObject::tr("Product Identifier: ") << QByteArray::number(serialPortInfo.productIdentifier(), 16) << endl << QObject::tr("Busy: ") << (serialPortInfo.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) << endl; } diff --git a/examples/enumerator/main.cpp b/examples/enumerator/main.cpp index 0bd3fc04..a95ee76e 100644 --- a/examples/enumerator/main.cpp +++ b/examples/enumerator/main.cpp @@ -57,18 +57,13 @@ int main(int argc, char *argv[]) QVBoxLayout *layout = new QVBoxLayout; foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { - QString s(QObject::tr("Port: %1\n" - "Location: %2\n" - "Description: %3\n" - "Manufacturer: %4\n" - "Vendor Identifier: %5\n" - "Product Identifier: %6\n" - "Busy: %7\n")); - - s = s.arg(info.portName()).arg(info.systemLocation()) - .arg(info.description()).arg(info.manufacturer()) - .arg(info.vendorIdentifier()).arg(info.productIdentifier()) - .arg(info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")); + QString s = QObject::tr("Port: ") + info.portName() + "\n" + + QObject::tr("Location: ") + info.systemLocation() + "\n" + + QObject::tr("Description: ") + info.description() + "\n" + + QObject::tr("Manufacturer: ") + info.manufacturer() + "\n" + + QObject::tr("Vendor Identifier: ") + QString::number(info.vendorIdentifier(), 16) + "\n" + + QObject::tr("Product Identifier: ") + QString::number(info.productIdentifier(), 16) + "\n" + + QObject::tr("Busy: ") + (info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) + "\n"; QLabel *label = new QLabel(s); layout->addWidget(label); diff --git a/examples/terminal/settingsdialog.cpp b/examples/terminal/settingsdialog.cpp index f0779331..c516a75c 100644 --- a/examples/terminal/settingsdialog.cpp +++ b/examples/terminal/settingsdialog.cpp @@ -153,9 +153,12 @@ void SettingsDialog::fillPortsInfo() ui->serialPortInfoListBox->clear(); foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { QStringList list; - list << info.portName() << info.description() - << info.manufacturer() << info.systemLocation() - << info.vendorIdentifier() << info.productIdentifier(); + list << info.portName() + << info.description() + << info.manufacturer() + << info.systemLocation() + << QString::number(info.vendorIdentifier(), 16) + << QString::number(info.productIdentifier(), 16); ui->serialPortInfoListBox->addItem(list.first(), list); } diff --git a/src/serialport/qserialportinfo.cpp b/src/serialport/qserialportinfo.cpp index 6d3ea334..e16e13e4 100644 --- a/src/serialport/qserialportinfo.cpp +++ b/src/serialport/qserialportinfo.cpp @@ -184,25 +184,23 @@ QString QSerialPortInfo::manufacturer() const } /*! - Returns the vendor identifier string of the serial - port in hexadecimal format, if available; otherwise - returns an empty string. + Returns the 16-bit vendor number for the serial port, if available; + otherwise returns zero. */ -QString QSerialPortInfo::vendorIdentifier() const +quint16 QSerialPortInfo::vendorIdentifier() const { Q_D(const QSerialPortInfo); - return !d ? QString() : d->vendorIdentifier; + return !d ? 0 : d->vendorIdentifier; } /*! - Returns the product identifier string of the serial - port in hexadecimal format, if available; otherwise - returns an empty string. + Returns the 16-bit product number for the serial port, if available; + otherwise returns zero. */ -QString QSerialPortInfo::productIdentifier() const +quint16 QSerialPortInfo::productIdentifier() const { Q_D(const QSerialPortInfo); - return !d ? QString() : d->productIdentifier; + return !d ? 0 : d->productIdentifier; } /*! diff --git a/src/serialport/qserialportinfo.h b/src/serialport/qserialportinfo.h index 96d48d78..19fd5b7e 100644 --- a/src/serialport/qserialportinfo.h +++ b/src/serialport/qserialportinfo.h @@ -71,8 +71,8 @@ public: QString systemLocation() const; QString description() const; QString manufacturer() const; - QString vendorIdentifier() const; - QString productIdentifier() const; + quint16 vendorIdentifier() const; + quint16 productIdentifier() const; bool isNull() const; bool isBusy() const; diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp index 0378f193..59cfad94 100644 --- a/src/serialport/qserialportinfo_mac.cpp +++ b/src/serialport/qserialportinfo_mac.cpp @@ -232,13 +232,13 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() ::CFRelease(manufacturer); } - int value = 0; + quint16 value = 0; if (vendorIdentifier) { if (::CFNumberGetValue(CFNumberRef(vendorIdentifier), kCFNumberIntType, &value)) { - serialPortInfo.d_ptr->vendorIdentifier = QString::number(value, 16); + serialPortInfo.d_ptr->vendorIdentifier = value; } ::CFRelease(vendorIdentifier); } @@ -247,7 +247,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() if (::CFNumberGetValue(CFNumberRef(productIdentifier), kCFNumberIntType, &value)) { - serialPortInfo.d_ptr->productIdentifier = QString::number(value, 16); + serialPortInfo.d_ptr->productIdentifier = value; } ::CFRelease(productIdentifier); } diff --git a/src/serialport/qserialportinfo_p.h b/src/serialport/qserialportinfo_p.h index 259752e3..ee7b8841 100644 --- a/src/serialport/qserialportinfo_p.h +++ b/src/serialport/qserialportinfo_p.h @@ -51,15 +51,15 @@ QT_BEGIN_NAMESPACE class QSerialPortInfoPrivate { public: - QSerialPortInfoPrivate() {} + QSerialPortInfoPrivate() : vendorIdentifier(0), productIdentifier(0) {} ~QSerialPortInfoPrivate() {} QString portName; QString device; QString description; QString manufacturer; - QString vendorIdentifier; - QString productIdentifier; + quint16 vendorIdentifier; + quint16 productIdentifier; }; class QSerialPortInfoPrivateDeleter diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp index c474e750..bfdc3d0c 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -145,12 +145,13 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() serialPortInfo.d_ptr->manufacturer = QString( QLatin1String(::udev_device_get_property_value(dev, "ID_VENDOR"))).replace('_', ' '); + serialPortInfo.d_ptr->vendorIdentifier = - QLatin1String(::udev_device_get_property_value(dev, - "ID_VENDOR_ID")); + QString::fromLatin1(::udev_device_get_property_value(dev, "ID_VENDOR_ID")).toInt(0, 16); + serialPortInfo.d_ptr->productIdentifier = - QLatin1String(::udev_device_get_property_value(dev, - "ID_MODEL_ID")); + QString::fromLatin1(::udev_device_get_property_value(dev, "ID_MODEL_ID")).toInt(0, 16); + } else if (subsys == QLatin1String("pnp")) { // PNP bus type // Append this device. // FIXME: How to get additional information about serial devices diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp index 37880a70..0a6618e6 100644 --- a/src/serialport/qserialportinfo_win.cpp +++ b/src/serialport/qserialportinfo_win.cpp @@ -178,11 +178,11 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts() int index = s.indexOf(vendorIdentifierPrefix); if (index != -1) - serialPortInfo.d_ptr->vendorIdentifier = s.mid(index + vendorIdentifierPrefix.size(), vendorIdentifierSize); + serialPortInfo.d_ptr->vendorIdentifier = s.mid(index + vendorIdentifierPrefix.size(), vendorIdentifierSize).toInt(0, 16); index = s.indexOf(productIdentifierPrefix); if (index != -1) - serialPortInfo.d_ptr->productIdentifier = s.mid(index + productIdentifierPrefix.size(), productIdentifierSize); + serialPortInfo.d_ptr->productIdentifier = s.mid(index + productIdentifierPrefix.size(), productIdentifierSize).toInt(0, 16); serialPortInfoList.append(serialPortInfo); } |