diff options
-rw-r--r-- | src/serialport/qserialport.cpp | 1 | ||||
-rw-r--r-- | src/serialport/qserialport_p.h | 1 | ||||
-rw-r--r-- | src/serialport/qserialport_win.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qserialport/tst_qserialport.cpp | 11 |
4 files changed, 19 insertions, 0 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index 1126fb9..8bf71c6 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) 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 6a1a941..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; } 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" |