diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index 7fec64a8304651dfb448a3cf90d1bad43a5e1fd0..39b8817f7ec008e743946d33bb10cabf029b356b 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -213,7 +213,8 @@ SerialLink::SerialLink(QString portname, int baudRate, bool hardwareFlowControl, int dataBits, int stopBits) : port(NULL), ports(new QVector()), - m_stopp(false) + m_stopp(false), + bytesRead(0) { // Setup settings this->porthandle = portname.trimmed(); @@ -396,6 +397,10 @@ void SerialLink::run() hardwareConnect(); // Qt way to make clear what a while(1) loop does + quint64 msecs = QDateTime::currentMSecsSinceEpoch(); + quint64 bytes = 0; + bool triedreset = false; + bool triedDTR = false; forever { { @@ -408,6 +413,37 @@ void SerialLink::run() } // Check if new bytes have arrived, if yes, emit the notification signal checkForBytes(); + if (bytes != bytesRead) + { + bytes = bytesRead; + msecs = QDateTime::currentMSecsSinceEpoch(); + } + else + { + if (QDateTime::currentMSecsSinceEpoch() - msecs > 10000) + { + //It's been 10 seconds since the last data came in. Reset and try again + msecs = QDateTime::currentMSecsSinceEpoch(); + if (!triedDTR && triedreset) + { + triedDTR = true; + qDebug() << "No data!!! Attempting reset via DTR."; + port->setDtr(true); + this->msleep(250); + port->setDtr(false); + } + else if (!triedreset) + { + qDebug() << "No data!!! Attempting reset via reboot command."; + port->write("reboot\r\n",8); + triedreset = true; + } + else + { + qDebug() << "No data!!!"; + } + } + } /* Serial data isn't arriving that fast normally, this saves the thread * from consuming too much processing time */ @@ -435,6 +471,7 @@ void SerialLink::checkForBytes() if(available > 0) { readBytes(); + bytesRead += available; } else if (available < 0) { /* Error, close port */ diff --git a/src/comm/SerialLink.h b/src/comm/SerialLink.h index 8844d8ce509081b0b6c6fbe7acab806fd7d5e46d..5ba8dee1a613db423f1938a81f1d0c6363344aa8 100644 --- a/src/comm/SerialLink.h +++ b/src/comm/SerialLink.h @@ -144,6 +144,7 @@ protected slots: void checkForBytes(); protected: + quint64 bytesRead; TNX::QSerialPort * port; TNX::QPortSettings portSettings; #ifdef _WIN32