Skip to content

Commit

Permalink
Add resource counter to only disconnect device on continued error
Browse files Browse the repository at this point in the history
  • Loading branch information
bweir committed Apr 16, 2015
1 parent bfe7883 commit 6ba9156
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -52,6 +53,8 @@ int Loader::get_version()

int Loader::open()
{
resourceErrorCount = 0;

if (!serial.open(QIODevice::ReadWrite))
{
qDebug() << serial.errorString();
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6ba9156

Please sign in to comment.