diff options
Diffstat (limited to 'examples/serialport/creaderasync')
-rw-r--r-- | examples/serialport/creaderasync/CMakeLists.txt | 36 | ||||
-rw-r--r-- | examples/serialport/creaderasync/creaderasync.pro | 18 | ||||
-rw-r--r-- | examples/serialport/creaderasync/main.cpp | 45 | ||||
-rw-r--r-- | examples/serialport/creaderasync/serialportreader.cpp | 55 | ||||
-rw-r--r-- | examples/serialport/creaderasync/serialportreader.h | 35 |
5 files changed, 0 insertions, 189 deletions
diff --git a/examples/serialport/creaderasync/CMakeLists.txt b/examples/serialport/creaderasync/CMakeLists.txt deleted file mode 100644 index b60dbab..0000000 --- a/examples/serialport/creaderasync/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(creaderasync LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/creaderasync") - -find_package(Qt6 REQUIRED COMPONENTS Core SerialPort) - -qt_add_executable(creaderasync - main.cpp - serialportreader.cpp serialportreader.h -) - -set_target_properties(creaderasync PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(creaderasync PRIVATE - Qt::Core - Qt::SerialPort -) - -install(TARGETS creaderasync - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/serialport/creaderasync/creaderasync.pro b/examples/serialport/creaderasync/creaderasync.pro deleted file mode 100644 index 38d8b52..0000000 --- a/examples/serialport/creaderasync/creaderasync.pro +++ /dev/null @@ -1,18 +0,0 @@ -QT = core -QT += serialport - -CONFIG += console -CONFIG -= app_bundle - -TARGET = creaderasync -TEMPLATE = app - -HEADERS += \ - serialportreader.h - -SOURCES += \ - main.cpp \ - serialportreader.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/serialport/creaderasync -INSTALLS += target diff --git a/examples/serialport/creaderasync/main.cpp b/examples/serialport/creaderasync/main.cpp deleted file mode 100644 index f371266..0000000 --- a/examples/serialport/creaderasync/main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "serialportreader.h" - -#include <QCoreApplication> -#include <QSerialPort> -#include <QStringList> -#include <QTextStream> - -int main(int argc, char *argv[]) -{ - QCoreApplication coreApplication(argc, argv); - const int argumentCount = QCoreApplication::arguments().size(); - const QStringList argumentList = QCoreApplication::arguments(); - - QTextStream standardOutput(stdout); - - if (argumentCount == 1) { - standardOutput << QObject::tr("Usage: %1 <serialportname> [baudrate]") - .arg(argumentList.first()) - << Qt::endl; - return 1; - } - - QSerialPort serialPort; - const QString serialPortName = argumentList.at(1); - serialPort.setPortName(serialPortName); - - const int serialPortBaudRate = (argumentCount > 2) - ? argumentList.at(2).toInt() : QSerialPort::Baud9600; - serialPort.setBaudRate(serialPortBaudRate); - - if (!serialPort.open(QIODevice::ReadOnly)) { - standardOutput << QObject::tr("Failed to open port %1, error: %2") - .arg(serialPortName) - .arg(serialPort.errorString()) - << Qt::endl; - return 1; - } - - SerialPortReader serialPortReader(&serialPort); - - return coreApplication.exec(); -} diff --git a/examples/serialport/creaderasync/serialportreader.cpp b/examples/serialport/creaderasync/serialportreader.cpp deleted file mode 100644 index d7f399b..0000000 --- a/examples/serialport/creaderasync/serialportreader.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "serialportreader.h" - -#include <QCoreApplication> - -SerialPortReader::SerialPortReader(QSerialPort *serialPort, QObject *parent) : - QObject(parent), - m_serialPort(serialPort), - m_standardOutput(stdout) -{ - connect(m_serialPort, &QSerialPort::readyRead, this, &SerialPortReader::handleReadyRead); - connect(m_serialPort, &QSerialPort::errorOccurred, this, &SerialPortReader::handleError); - connect(&m_timer, &QTimer::timeout, this, &SerialPortReader::handleTimeout); - - m_timer.start(5000); -} - -void SerialPortReader::handleReadyRead() -{ - m_readData.append(m_serialPort->readAll()); - - if (!m_timer.isActive()) - m_timer.start(5000); -} - -void SerialPortReader::handleTimeout() -{ - if (m_readData.isEmpty()) { - m_standardOutput << QObject::tr("No data was currently available " - "for reading from port %1") - .arg(m_serialPort->portName()) - << Qt::endl; - } else { - m_standardOutput << QObject::tr("Data successfully received from port %1") - .arg(m_serialPort->portName()) - << Qt::endl; - m_standardOutput << m_readData << Qt::endl; - } - - QCoreApplication::quit(); -} - -void SerialPortReader::handleError(QSerialPort::SerialPortError serialPortError) -{ - if (serialPortError == QSerialPort::ReadError) { - m_standardOutput << QObject::tr("An I/O error occurred while reading " - "the data from port %1, error: %2") - .arg(m_serialPort->portName()) - .arg(m_serialPort->errorString()) - << Qt::endl; - QCoreApplication::exit(1); - } -} diff --git a/examples/serialport/creaderasync/serialportreader.h b/examples/serialport/creaderasync/serialportreader.h deleted file mode 100644 index 361db1d..0000000 --- a/examples/serialport/creaderasync/serialportreader.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef SERIALPORTREADER_H -#define SERIALPORTREADER_H - -#include <QByteArray> -#include <QSerialPort> -#include <QTextStream> -#include <QTimer> - -QT_BEGIN_NAMESPACE - -QT_END_NAMESPACE - -class SerialPortReader : public QObject -{ - Q_OBJECT - -public: - explicit SerialPortReader(QSerialPort *serialPort, QObject *parent = nullptr); - -private slots: - void handleReadyRead(); - void handleTimeout(); - void handleError(QSerialPort::SerialPortError error); - -private: - QSerialPort *m_serialPort = nullptr; - QByteArray m_readData; - QTextStream m_standardOutput; - QTimer m_timer; -}; - -#endif // SERIALPORTREADER_H |