diff options
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | qtserialport.pro | 1 | ||||
-rw-r--r-- | src/serialport/qserialport.cpp | 3 | ||||
-rw-r--r-- | src/serialport/qserialport.h | 12 | ||||
-rw-r--r-- | src/serialport/qserialport_p.h | 1 | ||||
-rw-r--r-- | src/serialport/qserialport_win.cpp | 9 | ||||
-rw-r--r-- | src/serialport/qserialport_wince.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qserialport/tst_qserialport.cpp | 11 |
8 files changed, 37 insertions, 5 deletions
diff --git a/.qmake.conf b/.qmake.conf index e543981..66a0241 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,3 +1,3 @@ load(qt_build_config) -MODULE_VERSION = 5.5.1 +MODULE_VERSION = 5.6.0 diff --git a/qtserialport.pro b/qtserialport.pro index b3ebb8b..b8e7231 100644 --- a/qtserialport.pro +++ b/qtserialport.pro @@ -4,5 +4,6 @@ lessThan(QT_MAJOR_VERSION, 5) { } requires(!winrt) +requires(!ios) load(qt_parts) diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 956c899..74604b0 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -67,6 +67,7 @@ QSerialPortPrivate::QSerialPortPrivate() , handle(INVALID_HANDLE_VALUE) , parityErrorOccurred(false) , readChunkBuffer(ReadChunkSize, 0) + , communicationStarted(false) , writeStarted(false) , readStarted(false) , notifier(0) @@ -176,7 +177,7 @@ void QSerialPortPrivate::setError(const QSerialPortErrorInfo &errorInfo) used in non-GUI threads, to avoid freezing the user interface. For more details about these approaches, refer to the - \l {Examples}{example} applications. + \l {Qt Serial Port Examples}{example} applications. The QSerialPort class can also be used with QTextStream and QDataStream's stream operators (operator<<() and operator>>()). There is one issue to be diff --git a/src/serialport/qserialport.h b/src/serialport/qserialport.h index 36ae788..2815ebe 100644 --- a/src/serialport/qserialport.h +++ b/src/serialport/qserialport.h @@ -65,9 +65,6 @@ class Q_SERIALPORT_EXPORT QSerialPort : public QIODevice #endif Q_PROPERTY(bool breakEnabled READ isBreakEnabled WRITE setBreakEnabled NOTIFY breakEnabledChanged) - Q_ENUMS(BaudRate DataBits Parity StopBits FlowControl DataErrorPolicy SerialPortError) - Q_FLAGS(Directions PinoutSignals) - #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) typedef void* Handle; #else @@ -81,6 +78,7 @@ public: Output = 2, AllDirections = Input | Output }; + Q_FLAG(Direction) Q_DECLARE_FLAGS(Directions, Direction) enum BaudRate { @@ -94,6 +92,7 @@ public: Baud115200 = 115200, UnknownBaud = -1 }; + Q_ENUM(BaudRate) enum DataBits { Data5 = 5, @@ -102,6 +101,7 @@ public: Data8 = 8, UnknownDataBits = -1 }; + Q_ENUM(DataBits) enum Parity { NoParity = 0, @@ -111,6 +111,7 @@ public: MarkParity = 5, UnknownParity = -1 }; + Q_ENUM(Parity) enum StopBits { OneStop = 1, @@ -118,6 +119,7 @@ public: TwoStop = 2, UnknownStopBits = -1 }; + Q_ENUM(StopBits) enum FlowControl { NoFlowControl, @@ -125,6 +127,7 @@ public: SoftwareControl, UnknownFlowControl = -1 }; + Q_ENUM(FlowControl) enum PinoutSignal { NoSignal = 0x00, @@ -139,6 +142,7 @@ public: SecondaryTransmittedDataSignal = 0x100, SecondaryReceivedDataSignal = 0x200 }; + Q_FLAG(PinoutSignal) Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal) #if QT_DEPRECATED_SINCE(5, 2) @@ -161,6 +165,7 @@ public: StopReceivingPolicy, UnknownPolicy = -1 }; + Q_ENUM(DataErrorPolicy) #endif enum SerialPortError { @@ -179,6 +184,7 @@ public: TimeoutError, NotOpenError }; + Q_ENUM(SerialPortError) explicit QSerialPort(QObject *parent = Q_NULLPTR); explicit QSerialPort(const QString &name, QObject *parent = Q_NULLPTR); diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h index 571b0de..f3b1eb8 100644 --- a/src/serialport/qserialport_p.h +++ b/src/serialport/qserialport_p.h @@ -236,6 +236,7 @@ public: HANDLE handle; bool parityErrorOccurred; QByteArray readChunkBuffer; + bool communicationStarted; bool writeStarted; bool readStarted; QWinOverlappedIoNotifier *notifier; diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index a9687a2..0c61d36 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -400,6 +400,8 @@ bool QSerialPortPrivate::setDataErrorPolicy(QSerialPort::DataErrorPolicy policy) bool QSerialPortPrivate::completeAsyncCommunication(qint64 bytesTransferred) { + communicationStarted = false; + if (bytesTransferred == qint64(-1)) return false; if (EV_ERR & triggeredEventMask) @@ -453,6 +455,9 @@ bool QSerialPortPrivate::completeAsyncWrite(qint64 bytesTransferred) bool QSerialPortPrivate::startAsyncCommunication() { + if (communicationStarted) + return true; + ::ZeroMemory(&communicationOverlapped, sizeof(communicationOverlapped)); if (!::WaitCommEvent(handle, &triggeredEventMask, &communicationOverlapped)) { QSerialPortErrorInfo error = getSystemError(); @@ -463,6 +468,7 @@ bool QSerialPortPrivate::startAsyncCommunication() return false; } } + communicationStarted = true; return true; } @@ -722,6 +728,9 @@ QSerialPortErrorInfo QSerialPortPrivate::getSystemError(int systemErrorCode) con case ERROR_FILE_NOT_FOUND: error.errorCode = QSerialPort::DeviceNotFoundError; break; + case ERROR_PATH_NOT_FOUND: + error.errorCode = QSerialPort::DeviceNotFoundError; + break; case ERROR_INVALID_NAME: error.errorCode = QSerialPort::DeviceNotFoundError; break; diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index 88872ad..b49dd75 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -670,6 +670,9 @@ QSerialPortErrorInfo QSerialPortPrivate::getSystemError(int systemErrorCode) con case ERROR_FILE_NOT_FOUND: error.errorCode = QSerialPort::DeviceNotFoundError; break; + case ERROR_PATH_NOT_FOUND: + error.errorCode = QSerialPort::DeviceNotFoundError; + break; case ERROR_INVALID_NAME: error.errorCode = QSerialPort::DeviceNotFoundError; break; diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp index c5c9113..e49b1ff 100644 --- a/tests/auto/qserialport/tst_qserialport.cpp +++ b/tests/auto/qserialport/tst_qserialport.cpp @@ -112,6 +112,8 @@ private slots: void controlBreak(); + void clearAfterOpen(); + protected slots: void handleBytesWrittenAndExitLoopSlot(qint64 bytesWritten); void handleBytesWrittenAndExitLoopSlot2(qint64 bytesWritten); @@ -910,5 +912,14 @@ void tst_QSerialPort::controlBreak() QCOMPARE(qvariant_cast<bool>(breakSpy.at(1).at(0)), false); } +void tst_QSerialPort::clearAfterOpen() +{ + QSerialPort senderPort(m_senderPortName); + QVERIFY(senderPort.open(QSerialPort::ReadWrite)); + QCOMPARE(senderPort.error(), QSerialPort::NoError); + QVERIFY(senderPort.clear()); + QCOMPARE(senderPort.error(), QSerialPort::NoError); +} + QTEST_MAIN(tst_QSerialPort) #include "tst_qserialport.moc" |