diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2015-09-10 16:25:15 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2015-09-24 15:34:43 +0000 |
commit | a1655d6ccf3f82508286b471819cc5e5cb64ff44 (patch) | |
tree | dd1ef288de9177462c55b5597d52f8de7d8fd37f /src/serialport/qserialport_win.cpp | |
parent | 918b22aef140d293721f0d81ea8988c1d35db582 (diff) |
Cleanup remainders of code relating to data error policy handling
It is impossible to implement all these features on all platforms,
and particular drivers may not support them, too.
Consequently, the user should handle such errors themselves by applying
platform-specific ioctls on the device descriptor and/or parsing the
stream's byte-stuffing.
This commit also deprecates ParityError, FramingError, and
BreakConditionError.
Tested on Windows and Linux with the virtual and the
USB serial ports.
Change-Id: I4ffc2f067787bc304a83326acb2a2421b428f986
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/serialport/qserialport_win.cpp')
-rw-r--r-- | src/serialport/qserialport_win.cpp | 68 |
1 files changed, 5 insertions, 63 deletions
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 540b169c..39d7e33a 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -78,7 +78,7 @@ QT_BEGIN_NAMESPACE bool QSerialPortPrivate::open(QIODevice::OpenMode mode) { DWORD desiredAccess = 0; - originalEventMask = EV_ERR; + originalEventMask = 0; if (mode & QIODevice::ReadOnly) { desiredAccess |= GENERIC_READ; @@ -123,8 +123,6 @@ void QSerialPortPrivate::close() writeBuffer.clear(); actualBytesToWrite = 0; - parityErrorOccurred = false; - if (settingsRestoredOnClose) { if (!::SetCommState(handle, &restoredDcb)) setError(getSystemError()); @@ -418,20 +416,12 @@ bool QSerialPortPrivate::setFlowControl(QSerialPort::FlowControl flowControl) return setDcb(&dcb); } -bool QSerialPortPrivate::setDataErrorPolicy(QSerialPort::DataErrorPolicy policy) -{ - policy = policy; - return true; -} - bool QSerialPortPrivate::completeAsyncCommunication(qint64 bytesTransferred) { communicationStarted = false; if (bytesTransferred == qint64(-1)) return false; - if (EV_ERR & triggeredEventMask) - handleLineStatusErrors(); return startAsyncRead(); } @@ -450,12 +440,12 @@ bool QSerialPortPrivate::completeAsyncRead(qint64 bytesTransferred) readStarted = false; bool result = true; - if ((bytesTransferred == ReadChunkSize) && (policy == QSerialPort::IgnorePolicy)) + if (bytesTransferred == ReadChunkSize) result = startAsyncRead(); else if (readBufferMaxSize == 0 || readBufferMaxSize > buffer.size()) result = startAsyncCommunication(); - if ((bytesTransferred > 0) && !emulateErrorPolicy()) + if (bytesTransferred > 0) emitReadyRead(); return result; @@ -503,7 +493,7 @@ bool QSerialPortPrivate::startAsyncRead() if (readStarted) return true; - DWORD bytesToRead = policy == QSerialPort::IgnorePolicy ? ReadChunkSize : 1; + DWORD bytesToRead = ReadChunkSize; if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - buffer.size())) { bytesToRead = readBufferMaxSize - buffer.size(); @@ -576,34 +566,6 @@ void QSerialPortPrivate::_q_notified(DWORD numberOfBytes, DWORD errorCode, OVERL Q_ASSERT(!"Unknown OVERLAPPED activated"); } -bool QSerialPortPrivate::emulateErrorPolicy() -{ - if (!parityErrorOccurred) - return false; - - parityErrorOccurred = false; - - switch (policy) { - case QSerialPort::SkipPolicy: - buffer.getChar(); - break; - case QSerialPort::PassZeroPolicy: - buffer.getChar(); - buffer.ungetChar('\0'); - emitReadyRead(); - break; - case QSerialPort::IgnorePolicy: - return false; - case QSerialPort::StopReceivingPolicy: - emitReadyRead(); - break; - default: - return false; - } - - return true; -} - void QSerialPortPrivate::emitReadyRead() { Q_Q(QSerialPort); @@ -629,26 +591,6 @@ qint64 QSerialPortPrivate::writeData(const char *data, qint64 maxSize) return maxSize; } -void QSerialPortPrivate::handleLineStatusErrors() -{ - DWORD errors = 0; - if (!::ClearCommError(handle, &errors, Q_NULLPTR)) { - setError(getSystemError()); - return; - } - - if (errors & CE_FRAME) { - setError(QSerialPortErrorInfo(QSerialPort::FramingError)); - } else if (errors & CE_RXPARITY) { - setError(QSerialPortErrorInfo(QSerialPort::FramingError)); - parityErrorOccurred = true; - } else if (errors & CE_BREAK) { - setError(QSerialPortErrorInfo(QSerialPort::BreakConditionError)); - } else { - setError(QSerialPortErrorInfo(QSerialPort::UnknownError, QSerialPort::tr("Unknown streaming error"))); - } -} - OVERLAPPED *QSerialPortPrivate::waitForNotified(int msecs) { OVERLAPPED *overlapped = notifier->waitForAnyNotified(msecs); @@ -706,7 +648,7 @@ inline bool QSerialPortPrivate::initialize() notifier->setHandle(handle); notifier->setEnabled(true); - if (!startAsyncCommunication()) + if ((originalEventMask & EV_RXCHAR) && !startAsyncCommunication()) return false; return true; |