summaryrefslogtreecommitdiffstats
path: root/examples/serialport/cwriterasync
diff options
context:
space:
mode:
Diffstat (limited to 'examples/serialport/cwriterasync')
-rw-r--r--examples/serialport/cwriterasync/CMakeLists.txt36
-rw-r--r--examples/serialport/cwriterasync/cwriterasync.pro18
-rw-r--r--examples/serialport/cwriterasync/main.cpp57
-rw-r--r--examples/serialport/cwriterasync/serialportwriter.cpp74
-rw-r--r--examples/serialport/cwriterasync/serialportwriter.h38
5 files changed, 0 insertions, 223 deletions
diff --git a/examples/serialport/cwriterasync/CMakeLists.txt b/examples/serialport/cwriterasync/CMakeLists.txt
deleted file mode 100644
index 7f64ccb8..00000000
--- a/examples/serialport/cwriterasync/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(cwriterasync LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/serialport/cwriterasync")
-
-find_package(Qt6 REQUIRED COMPONENTS Core SerialPort)
-
-qt_add_executable(cwriterasync
- main.cpp
- serialportwriter.cpp serialportwriter.h
-)
-
-set_target_properties(cwriterasync PROPERTIES
- WIN32_EXECUTABLE FALSE
- MACOSX_BUNDLE FALSE
-)
-
-target_link_libraries(cwriterasync PRIVATE
- Qt::Core
- Qt::SerialPort
-)
-
-install(TARGETS cwriterasync
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/serialport/cwriterasync/cwriterasync.pro b/examples/serialport/cwriterasync/cwriterasync.pro
deleted file mode 100644
index f6105bc9..00000000
--- a/examples/serialport/cwriterasync/cwriterasync.pro
+++ /dev/null
@@ -1,18 +0,0 @@
-QT = core
-QT += serialport
-
-CONFIG += console
-CONFIG -= app_bundle
-
-TARGET = cwriterasync
-TEMPLATE = app
-
-HEADERS += \
- serialportwriter.h
-
-SOURCES += \
- main.cpp \
- serialportwriter.cpp
-
-target.path = $$[QT_INSTALL_EXAMPLES]/serialport/cwriterasync
-INSTALLS += target
diff --git a/examples/serialport/cwriterasync/main.cpp b/examples/serialport/cwriterasync/main.cpp
deleted file mode 100644
index 9424a264..00000000
--- a/examples/serialport/cwriterasync/main.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "serialportwriter.h"
-
-#include <QCoreApplication>
-#include <QFile>
-#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);
-
- serialPort.open(QIODevice::WriteOnly);
-
- QFile dataFile;
- if (!dataFile.open(stdin, QIODevice::ReadOnly)) {
- standardOutput << QObject::tr("Failed to open stdin for reading") << Qt::endl;
- return 1;
- }
-
- const QByteArray writeData(dataFile.readAll());
- dataFile.close();
-
- if (writeData.isEmpty()) {
- standardOutput << QObject::tr("Either no data was currently available on "
- "the standard input for reading, "
- "or an error occurred for port %1, error: %2")
- .arg(serialPortName).arg(serialPort.errorString()) << Qt::endl;
- return 1;
- }
-
- SerialPortWriter serialPortWriter(&serialPort);
- serialPortWriter.write(writeData);
-
- return coreApplication.exec();
-}
diff --git a/examples/serialport/cwriterasync/serialportwriter.cpp b/examples/serialport/cwriterasync/serialportwriter.cpp
deleted file mode 100644
index 0331b268..00000000
--- a/examples/serialport/cwriterasync/serialportwriter.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "serialportwriter.h"
-
-#include <QCoreApplication>
-
-SerialPortWriter::SerialPortWriter(QSerialPort *serialPort, QObject *parent) :
- QObject(parent),
- m_serialPort(serialPort),
- m_standardOutput(stdout)
-{
- m_timer.setSingleShot(true);
- connect(m_serialPort, &QSerialPort::bytesWritten,
- this, &SerialPortWriter::handleBytesWritten);
- connect(m_serialPort, &QSerialPort::errorOccurred,
- this, &SerialPortWriter::handleError);
- connect(&m_timer, &QTimer::timeout, this, &SerialPortWriter::handleTimeout);
-}
-
-void SerialPortWriter::handleBytesWritten(qint64 bytes)
-{
- m_bytesWritten += bytes;
- if (m_bytesWritten == m_writeData.size()) {
- m_bytesWritten = 0;
- m_standardOutput << QObject::tr("Data successfully sent to port %1")
- .arg(m_serialPort->portName()) << Qt::endl;
- QCoreApplication::quit();
- }
-}
-
-void SerialPortWriter::handleTimeout()
-{
- m_standardOutput << QObject::tr("Operation timed out for port %1, error: %2")
- .arg(m_serialPort->portName())
- .arg(m_serialPort->errorString())
- << Qt::endl;
- QCoreApplication::exit(1);
-}
-
-void SerialPortWriter::handleError(QSerialPort::SerialPortError serialPortError)
-{
- if (serialPortError == QSerialPort::WriteError) {
- m_standardOutput << QObject::tr("An I/O error occurred while writing"
- " the data to port %1, error: %2")
- .arg(m_serialPort->portName())
- .arg(m_serialPort->errorString())
- << Qt::endl;
- QCoreApplication::exit(1);
- }
-}
-
-void SerialPortWriter::write(const QByteArray &writeData)
-{
- m_writeData = writeData;
-
- const qint64 bytesWritten = m_serialPort->write(writeData);
-
- if (bytesWritten == -1) {
- m_standardOutput << QObject::tr("Failed to write the data to port %1, error: %2")
- .arg(m_serialPort->portName())
- .arg(m_serialPort->errorString())
- << Qt::endl;
- QCoreApplication::exit(1);
- } else if (bytesWritten != m_writeData.size()) {
- m_standardOutput << QObject::tr("Failed to write all the data to port %1, error: %2")
- .arg(m_serialPort->portName())
- .arg(m_serialPort->errorString())
- << Qt::endl;
- QCoreApplication::exit(1);
- }
-
- m_timer.start(5000);
-}
diff --git a/examples/serialport/cwriterasync/serialportwriter.h b/examples/serialport/cwriterasync/serialportwriter.h
deleted file mode 100644
index 371fe2af..00000000
--- a/examples/serialport/cwriterasync/serialportwriter.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef SERIALPORTWRITER_H
-#define SERIALPORTWRITER_H
-
-#include <QByteArray>
-#include <QObject>
-#include <QSerialPort>
-#include <QTextStream>
-#include <QTimer>
-
-QT_BEGIN_NAMESPACE
-
-QT_END_NAMESPACE
-
-class SerialPortWriter : public QObject
-{
- Q_OBJECT
-
-public:
- explicit SerialPortWriter(QSerialPort *serialPort, QObject *parent = nullptr);
- void write(const QByteArray &writeData);
-
-private slots:
- void handleBytesWritten(qint64 bytes);
- void handleTimeout();
- void handleError(QSerialPort::SerialPortError error);
-
-private:
- QSerialPort *m_serialPort = nullptr;
- QByteArray m_writeData;
- QTextStream m_standardOutput;
- qint64 m_bytesWritten = 0;
- QTimer m_timer;
-};
-
-#endif // SERIALPORTWRITER_H