From 5de449b12b941574b8e04bc34f7a94d98846eb45 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 7 Feb 2016 16:05:41 -0500 Subject: [PATCH] Slight changes to serialworker to make things run a bit more stable. --- serialworker.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/serialworker.cpp b/serialworker.cpp index 8b0786e..d70fc6c 100644 --- a/serialworker.cpp +++ b/serialworker.cpp @@ -132,7 +132,7 @@ void SerialWorker::connectionTimeout() { //then emit the the failure signal and see if anyone cares qDebug() << "Failed to connect to GVRET at that com port"; - ticker->stop(); + //ticker->stop(); closeSerialPort(); //make sure it's properly closed anyway emit connectionFailure(); } @@ -433,13 +433,14 @@ void SerialWorker::handleTick() if (connected) { - if (!gotValidated) + if (!gotValidated && doValidation) { if (serial == NULL) return; if (serial->isOpen()) //if it's still false we have a problem... { qDebug() << "Comm validation failed. "; closeSerialPort(); //start by stopping everything. + //Then wait 500ms and restart the connection automatically QTimer::singleShot(500, this, SLOT(handleReconnect())); return; } @@ -451,7 +452,7 @@ void SerialWorker::handleTick() emit frameUpdateTick(framesPerSec / 4, gotFrames); //sends stats to interested parties canModel->sendBulkRefresh(gotFrames); gotFrames = 0; - if (doValidation && serial) sendCommValidation(); + if (doValidation && serial && serial->isOpen()) sendCommValidation(); } void SerialWorker::handleReconnect() @@ -467,6 +468,10 @@ void SerialWorker::sendCommValidation() gotValidated = false; output.append((char)0xF1); //another command to the GVRET output.append((char)0x09); //request a reply to get validation + //send it twice for good measure. + output.append((char)0xF1); //another command to the GVRET + output.append((char)0x09); //request a reply to get validation + serial->write(output); }