blob: fc8fd9b3b8a56849af714f837384d783ab205e38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QCoreApplication>
#include <QSerialPortInfo>
#include <QTextStream>
int main(int argc, char *argv[])
{
QCoreApplication coreApplication(argc, argv);
QTextStream out(stdout);
const auto serialPortInfos = QSerialPortInfo::availablePorts();
out << "Total number of ports available: " << serialPortInfos.count() << Qt::endl;
const QStringView blankString = u"N/A";
for (const QSerialPortInfo &serialPortInfo : serialPortInfos) {
const QStringView description = serialPortInfo.description();
const QStringView manufacturer = serialPortInfo.manufacturer();
const QStringView serialNumber = serialPortInfo.serialNumber();
out << Qt::endl
<< "Port: " << serialPortInfo.portName() << Qt::endl
<< "Location: " << serialPortInfo.systemLocation() << Qt::endl
<< "Description: " << (!description.isEmpty() ? description : blankString) << Qt::endl
<< "Manufacturer: " << (!manufacturer.isEmpty() ? manufacturer : blankString) << Qt::endl
<< "Serial number: " << (!serialNumber.isEmpty() ? serialNumber : blankString) << Qt::endl
<< "Vendor Identifier: " << (serialPortInfo.hasVendorIdentifier()
? QByteArray::number(serialPortInfo.vendorIdentifier(), 16)
: blankString.toLatin1()) << Qt::endl
<< "Product Identifier: " << (serialPortInfo.hasProductIdentifier()
? QByteArray::number(serialPortInfo.productIdentifier(), 16)
: blankString.toLatin1()) << Qt::endl;
}
return 0;
}
|