diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2015-07-08 18:26:08 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2015-07-09 14:14:48 +0000 |
commit | a2758cf594dd08a21037873f64f72166a353aa29 (patch) | |
tree | 784f662913f439570e0ea74bc4e6e88322f8e6dc | |
parent | 8919ea86c80001be7e826f5363f1b7548c7a8091 (diff) | |
download | qtserialport-a2758cf594dd08a21037873f64f72166a353aa29.tar.gz |
Give custom descriptions to errors which had none before
Change-Id: Ic083cbd58e4e775ede0cdf610f61407003834207
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r-- | src/serialport/qserialport.cpp | 22 | ||||
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 21 | ||||
-rw-r--r-- | src/serialport/qserialport_win.cpp | 14 | ||||
-rw-r--r-- | src/serialport/qserialport_wince.cpp | 22 |
4 files changed, 37 insertions, 42 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index b6c4252..b56b3da 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -521,14 +521,14 @@ bool QSerialPort::open(OpenMode mode) Q_D(QSerialPort); if (isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::OpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::OpenError, tr("Device is already open"))); return false; } // Define while not supported modes. static const OpenMode unsupportedModes = Append | Truncate | Text | Unbuffered; if ((mode & unsupportedModes) || mode == NotOpen) { - d->setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError)); + d->setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, tr("Unsupported open mode"))); return false; } @@ -561,7 +561,7 @@ void QSerialPort::close() { Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); return; } @@ -871,7 +871,7 @@ bool QSerialPort::setDataTerminalReady(bool set) Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); qWarning("%s: device not open", Q_FUNC_INFO); return false; } @@ -918,7 +918,7 @@ bool QSerialPort::setRequestToSend(bool set) Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); qWarning("%s: device not open", Q_FUNC_INFO); return false; } @@ -968,7 +968,7 @@ QSerialPort::PinoutSignals QSerialPort::pinoutSignals() Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); qWarning("%s: device not open", Q_FUNC_INFO); return QSerialPort::NoSignal; } @@ -998,7 +998,7 @@ bool QSerialPort::flush() Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); qWarning("%s: device not open", Q_FUNC_INFO); return false; } @@ -1020,7 +1020,7 @@ bool QSerialPort::clear(Directions directions) Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); qWarning("%s: device not open", Q_FUNC_INFO); return false; } @@ -1082,7 +1082,7 @@ bool QSerialPort::setDataErrorPolicy(DataErrorPolicy policy) Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); qWarning("%s: device not open", Q_FUNC_INFO); return false; } @@ -1304,7 +1304,7 @@ bool QSerialPort::sendBreak(int duration) Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); qWarning("%s: device not open", Q_FUNC_INFO); return false; } @@ -1333,7 +1333,7 @@ bool QSerialPort::setBreakEnabled(bool set) Q_D(QSerialPort); if (!isOpen()) { - d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError)); + d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open"))); qWarning("%s: device not open", Q_FUNC_INFO); return false; } diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index a80d6b3..c87db04 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -162,14 +162,14 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) bool isLockFileEmpty = lockFilePath.isEmpty(); if (isLockFileEmpty) { qWarning("Failed to create a lock file for opening the device"); - setError(QSerialPortErrorInfo(QSerialPort::PermissionError)); + setError(QSerialPortErrorInfo(QSerialPort::PermissionError, QSerialPort::tr("Permission error while creating lock file"))); return false; } QScopedPointer<QLockFile> newLockFileScopedPointer(new QLockFile(lockFilePath)); if (!newLockFileScopedPointer->tryLock()) { - setError(QSerialPortErrorInfo(QSerialPort::PermissionError)); + setError(QSerialPortErrorInfo(QSerialPort::PermissionError, QSerialPort::tr("Permission error while locking the device"))); return false; } @@ -471,7 +471,7 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d currentSerialInfo.custom_divisor = currentSerialInfo.baud_base / baudRate; if (currentSerialInfo.custom_divisor == 0) - return QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError); + return QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("No suitable custom baud rate divisor")); if (currentSerialInfo.custom_divisor * baudRate != currentSerialInfo.baud_base) { qWarning("Baud rate of serial port %s is set to %d instead of %d: divisor %f unsupported", @@ -500,7 +500,7 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d return QSerialPortErrorInfo(QSerialPort::NoError); #endif - return QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError); + return QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Custom baud rate is not supported")); } #elif defined(Q_OS_QNX) @@ -531,7 +531,7 @@ QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions d bool QSerialPortPrivate::setBaudRate(qint32 baudRate, QSerialPort::Directions directions) { if (baudRate <= 0) { - setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError)); + setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Invalid baud rate value"))); return false; } @@ -958,7 +958,7 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor return false; } if (ret == 0) { - setError(QSerialPortErrorInfo(QSerialPort::TimeoutError)); + setError(QSerialPortErrorInfo(QSerialPort::TimeoutError, QSerialPort::tr("Operation timed out"))); return false; } @@ -1091,13 +1091,12 @@ qint64 QSerialPortPrivate::readPerChar(char *data, qint64 maxSize) case QSerialPort::SkipPolicy: continue; //ignore received character case QSerialPort::StopReceivingPolicy: { - QSerialPortErrorInfo error; if (parity != QSerialPort::NoParity) - error.errorCode = QSerialPort::ParityError; + setError(QSerialPortErrorInfo(QSerialPort::ParityError, QSerialPort::tr("Parity error detected while reading"))); + else if (*data == '\0') + setError(QSerialPortErrorInfo(QSerialPort::BreakConditionError, QSerialPort::tr("Break condition detected while reading"))); else - error.errorCode = *data == '\0' ? - QSerialPort::BreakConditionError : QSerialPort::FramingError; - setError(error); + setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("Framing error detected while reading"))); return ++ret; //abort receiving } break; diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index d05c9fb..0db4b8b 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -302,7 +302,7 @@ bool QSerialPortPrivate::setBaudRate() bool QSerialPortPrivate::setBaudRate(qint32 baudRate, QSerialPort::Directions directions) { if (directions != QSerialPort::AllDirections) { - setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError)); + setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Custom baud rate direction is unsupported"))); return false; } currentDcb.BaudRate = baudRate; @@ -598,18 +598,16 @@ void QSerialPortPrivate::handleLineStatusErrors() return; } - QSerialPortErrorInfo error; - if (errors & CE_FRAME) { - error.errorCode = QSerialPort::FramingError; + setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("Framing error detected while reading"))); } else if (errors & CE_RXPARITY) { - error.errorCode = QSerialPort::ParityError; + setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("ParityError error detected while reading"))); parityErrorOccurred = true; } else if (errors & CE_BREAK) { - error.errorCode = QSerialPort::BreakConditionError; + setError(QSerialPortErrorInfo(QSerialPort::BreakConditionError, QSerialPort::tr("Break condition detected while reading"))); + } else { + setError(QSerialPortErrorInfo(QSerialPort::UnknownError, QSerialPort::tr("Unknown streaming error"))); } - - setError(error); } OVERLAPPED *QSerialPortPrivate::waitForNotified(int msecs) diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index cd28d25..88872ad 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -380,7 +380,7 @@ bool QSerialPortPrivate::setBaudRate() bool QSerialPortPrivate::setBaudRate(qint32 baudRate, QSerialPort::Directions directions) { if (directions != QSerialPort::AllDirections) { - setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError)); + setError(QSerialPortErrorInfo(QSerialPort::UnsupportedOperationError, QSerialPort::tr("Custom baud rate direction is unsupported"))); return false; } currentDcb.BaudRate = baudRate; @@ -491,7 +491,7 @@ bool QSerialPortPrivate::notifyRead() if (!sucessResult) { buffer.chop(bytesToRead); - setError(QSerialPortErrorInfo(QSerialPort::ReadError)); + setError(QSerialPortErrorInfo(QSerialPort::ReadError, QSerialPort::tr("Error reading from device"))); return false; } @@ -534,7 +534,7 @@ bool QSerialPortPrivate::notifyWrite() DWORD bytesWritten = 0; if (!::WriteFile(handle, ptr, nextSize, &bytesWritten, Q_NULLPTR)) { - setError(QSerialPortErrorInfo(QSerialPort::WriteError)); + setError(QSerialPortErrorInfo(QSerialPort::WriteError, QSerialPort::tr("Error writing to device"))); return false; } @@ -557,7 +557,7 @@ qint64 QSerialPortPrivate::writeData(const char *data, qint64 maxSize) void QSerialPortPrivate::processIoErrors(bool hasError) { if (hasError) { - setError(QSerialPortErrorInfo(QSerialPort::ResourceError)); + setError(QSerialPortErrorInfo(QSerialPort::ResourceError, QSerialPort::tr("Device disappeared from the system"))); return; } @@ -567,18 +567,16 @@ void QSerialPortPrivate::processIoErrors(bool hasError) return; } - QSerialPortErrorInfo error; - if (errors & CE_FRAME) { - error.errorCode = QSerialPort::FramingError; + setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("Framing error detected while reading"))); } else if (errors & CE_RXPARITY) { - error.errorCode = QSerialPort::ParityError; + setError(QSerialPortErrorInfo(QSerialPort::FramingError, QSerialPort::tr("ParityError error detected while reading"))); parityErrorOccurred = true; } else if (errors & CE_BREAK) { - error.errorCode = QSerialPort::BreakConditionError; + setError(QSerialPortErrorInfo(QSerialPort::BreakConditionError, QSerialPort::tr("Break condition detected while reading"))); + } else { + setError(QSerialPortErrorInfo(QSerialPort::UnknownError, QSerialPort::tr("Unknown streaming error"))); } - - setError(error); } inline bool QSerialPortPrivate::initialize(DWORD eventMask) @@ -710,7 +708,7 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor breaker.stop(); if (breaker.isWorked()) { - setError(QSerialPortErrorInfo(QSerialPort::TimeoutError)); + setError(QSerialPortErrorInfo(QSerialPort::TimeoutError, QSerialPort::tr("Operation timed out"))); } else { if (checkRead) { Q_ASSERT(selectForRead); |