summaryrefslogtreecommitdiff
path: root/examples/serialport
diff options
context:
space:
mode:
Diffstat (limited to 'examples/serialport')
-rw-r--r--examples/serialport/cenumerator/main.cpp14
-rw-r--r--examples/serialport/creaderasync/serialportreader.cpp6
-rw-r--r--examples/serialport/creadersync/main.cpp7
-rw-r--r--examples/serialport/terminal/settingsdialog.cpp13
4 files changed, 27 insertions, 13 deletions
diff --git a/examples/serialport/cenumerator/main.cpp b/examples/serialport/cenumerator/main.cpp
index f55b92d..2d770e8 100644
--- a/examples/serialport/cenumerator/main.cpp
+++ b/examples/serialport/cenumerator/main.cpp
@@ -53,14 +53,20 @@ int main(int argc, char *argv[])
out << QObject::tr("Total number of ports available: ") << serialPortInfoList.count() << endl;
+ const QString blankString = QObject::tr("N/A");
+ QString description;
+ QString manufacturer;
+
foreach (const QSerialPortInfo &serialPortInfo, serialPortInfoList) {
+ description = serialPortInfo.description();
+ manufacturer = serialPortInfo.manufacturer();
out << endl
<< QObject::tr("Port: ") << serialPortInfo.portName() << endl
<< QObject::tr("Location: ") << serialPortInfo.systemLocation() << endl
- << QObject::tr("Description: ") << serialPortInfo.description() << endl
- << QObject::tr("Manufacturer: ") << serialPortInfo.manufacturer() << endl
- << QObject::tr("Vendor Identifier: ") << (serialPortInfo.hasVendorIdentifier() ? QByteArray::number(serialPortInfo.vendorIdentifier(), 16) : QByteArray()) << endl
- << QObject::tr("Product Identifier: ") << (serialPortInfo.hasProductIdentifier() ? QByteArray::number(serialPortInfo.productIdentifier(), 16) : QByteArray()) << endl
+ << QObject::tr("Description: ") << (!description.isEmpty() ? description : blankString) << endl
+ << QObject::tr("Manufacturer: ") << (!manufacturer.isEmpty() ? manufacturer : blankString) << endl
+ << QObject::tr("Vendor Identifier: ") << (serialPortInfo.hasVendorIdentifier() ? QByteArray::number(serialPortInfo.vendorIdentifier(), 16) : blankString) << endl
+ << QObject::tr("Product Identifier: ") << (serialPortInfo.hasProductIdentifier() ? QByteArray::number(serialPortInfo.productIdentifier(), 16) : blankString) << endl
<< QObject::tr("Busy: ") << (serialPortInfo.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) << endl;
}
diff --git a/examples/serialport/creaderasync/serialportreader.cpp b/examples/serialport/creaderasync/serialportreader.cpp
index 5dd7412..e238304 100644
--- a/examples/serialport/creaderasync/serialportreader.cpp
+++ b/examples/serialport/creaderasync/serialportreader.cpp
@@ -72,13 +72,13 @@ void SerialPortReader::handleReadyRead()
void SerialPortReader::handleTimeout()
{
if (m_readData.isEmpty()) {
- m_standardOutput << QObject::tr("Either no data was currently available for reading, or an error occurred for port %1, error: %2").arg(m_serialPort->portName()).arg(m_serialPort->errorString()) << endl;
- QCoreApplication::exit(1);
+ m_standardOutput << QObject::tr("No data was currently available for reading from port %1").arg(m_serialPort->portName()) << endl;
} else {
m_standardOutput << QObject::tr("Data successfully received from port %1").arg(m_serialPort->portName()) << endl;
m_standardOutput << m_readData << endl;
- QCoreApplication::quit();
}
+
+ QCoreApplication::quit();
}
void SerialPortReader::handleError(QSerialPort::SerialPortError serialPortError)
diff --git a/examples/serialport/creadersync/main.cpp b/examples/serialport/creadersync/main.cpp
index cd10b8e..188d7b8 100644
--- a/examples/serialport/creadersync/main.cpp
+++ b/examples/serialport/creadersync/main.cpp
@@ -99,9 +99,12 @@ int main(int argc, char *argv[])
while (serialPort.waitForReadyRead(5000))
readData.append(serialPort.readAll());
- if (readData.isEmpty()) {
- standardOutput << QObject::tr("Either no data was currently available for reading, or an error occurred for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl;
+ if (serialPort.error() == QSerialPort::ReadError) {
+ standardOutput << QObject::tr("Failed to read from port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl;
return 1;
+ } else if (serialPort.error() == QSerialPort::TimeoutError) {
+ standardOutput << QObject::tr("No data was currently available for reading from port %1").arg(serialPortName) << endl;
+ return 0;
}
standardOutput << QObject::tr("Data successfully received from port %1").arg(serialPortName) << endl;
diff --git a/examples/serialport/terminal/settingsdialog.cpp b/examples/serialport/terminal/settingsdialog.cpp
index ad32824..923f000 100644
--- a/examples/serialport/terminal/settingsdialog.cpp
+++ b/examples/serialport/terminal/settingsdialog.cpp
@@ -151,14 +151,19 @@ void SettingsDialog::fillPortsParameters()
void SettingsDialog::fillPortsInfo()
{
ui->serialPortInfoListBox->clear();
+ static const QString blankString = QObject::tr("N/A");
+ QString description;
+ QString manufacturer;
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
QStringList list;
+ description = info.description();
+ manufacturer = info.manufacturer();
list << info.portName()
- << info.description()
- << info.manufacturer()
+ << (!description.isEmpty() ? description : blankString)
+ << (!manufacturer.isEmpty() ? manufacturer : blankString)
<< info.systemLocation()
- << (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString())
- << (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : QString());
+ << (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : blankString)
+ << (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : blankString);
ui->serialPortInfoListBox->addItem(list.first(), list);
}