From 6ba91567b46905122922cf0ca67f3acda48596cc Mon Sep 17 00:00:00 2001 From: Brett Weir Date: Thu, 16 Apr 2015 01:40:13 -0700 Subject: [PATCH] Add resource counter to only disconnect device on continued error --- Loader.cpp | 15 +++++++++++---- Loader.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Loader.cpp b/Loader.cpp index d16b5bb..71922da 100644 --- a/Loader.cpp +++ b/Loader.cpp @@ -14,6 +14,7 @@ Loader::Loader(QString port, int reset_gpio, bool useRtsReset, QObject * parent) { this->useRtsReset = useRtsReset; version = 0; + resourceErrorCount = 0; serial.setSettingsRestoredOnClose(false); serial.setPortName(port); @@ -52,6 +53,8 @@ int Loader::get_version() int Loader::open() { + resourceErrorCount = 0; + if (!serial.open(QIODevice::ReadWrite)) { qDebug() << serial.errorString(); @@ -238,10 +241,14 @@ void Loader::device_error(QSerialPort::SerialPortError e) case QSerialPort::TimeoutError: case QSerialPort::UnknownError: case QSerialPort::ResourceError: // SUPER IMPORTANT - qDebug() << "ERROR: " << e; - close(); - emit finished(); - emit sendError(e,"Device unexpectedly disconnected!"); + resourceErrorCount++; + if (resourceErrorCount > 1) + { + qDebug() << "ERROR: " << e; + close(); + emit finished(); + emit sendError(e,"Device unexpectedly disconnected!"); + } break; default: break; diff --git a/Loader.h b/Loader.h index 823adb6..9601eb2 100644 --- a/Loader.h +++ b/Loader.h @@ -75,6 +75,7 @@ class Loader : public QObject int ack; int error; bool useRtsReset; + int resourceErrorCount; int checksum(QByteArray binary, bool isEEPROM); QByteArray convert_binary_to_eeprom(QByteArray binary);