| 1 |
// Copyright (C) 2023 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
#include <QtCore/qcoreapplication.h> |
| 5 |
#include <QtCore/qdebug.h> |
| 6 |
|
| 7 |
#include <QtSerialPort/qserialportinfo.h> |
| 8 |
|
| 9 |
void enumeratePorts() |
| 10 |
{ |
| 11 |
//! [enumerate_ports] |
| 12 |
const auto serialPortInfos = QSerialPortInfo::availablePorts(); |
| 13 |
for (const QSerialPortInfo &portInfo : serialPortInfos) { |
| 14 |
qDebug() << "\n" |
| 15 |
<< "Port:" << portInfo.portName() << "\n" |
| 16 |
<< "Location:" << portInfo.systemLocation() << "\n" |
| 17 |
<< "Description:" << portInfo.description() << "\n" |
| 18 |
<< "Manufacturer:" << portInfo.manufacturer() << "\n" |
| 19 |
<< "Serial number:" << portInfo.serialNumber() << "\n" |
| 20 |
<< "Vendor Identifier:" |
| 21 |
<< (portInfo.hasVendorIdentifier() |
| 22 |
? QByteArray::number(portInfo.vendorIdentifier(), 16) |
| 23 |
: QByteArray()) << "\n" |
| 24 |
<< "Product Identifier:" |
| 25 |
<< (portInfo.hasProductIdentifier() |
| 26 |
? QByteArray::number(portInfo.productIdentifier(), 16) |
| 27 |
: QByteArray()); |
| 28 |
} |
| 29 |
//! [enumerate_ports] |
| 30 |
} |
| 31 |
|
| 32 |
int main(int argc, char **argv) |
| 33 |
{ |
| 34 |
QCoreApplication app(argc, argv); |
| 35 |
|
| 36 |
enumeratePorts(); |
| 37 |
|
| 38 |
return app.exec(); |
| 39 |
} |
| 40 |
|
| 41 |
#include "doc_src_serialport.moc" |