diff --git a/sources/buzzerconn.cpp b/sources/buzzerconn.cpp index a8960d2..80b17be 100644 --- a/sources/buzzerconn.cpp +++ b/sources/buzzerconn.cpp @@ -51,13 +51,14 @@ bool BuzzerConn::connect() //wait for the connection to finish loop.exec(); - timer.stop(); - if(timer.remainingTime() == 0){ + //loop finished + if(timer.remainingTime() == -1){ //the time has been triggered -> timeout setState("disconnected"); return(false); } + timer.stop(); QList times = gettimes(2000, true); @@ -115,7 +116,6 @@ QList BuzzerConn::gettimes(int timeout, bool bothTimes) QList times; signed long ret; ret = this->sendCommand("GET_TIMESTAMP", timeout); - qDebug() << timeout << bothTimes; if(ret >= 0){ times.append(double(200)); @@ -262,15 +262,17 @@ signed long BuzzerConn::sendCommand(QString command, int timeout){ loop.exec(); //loop finished - timer.stop(); - if(timer.remainingTime() == 0){ + if(timer.remainingTime() == -1){ //the time has been triggered -> timeout return(-1); } + timer.stop(); + + //if the data is not 4 bytes long it is invalid -> clear and terminate if(this->socket->bytesAvailable() != 4){ - qDebug() << this->socket->readAll(); + this->socket->readAll(); return(-2); } long data = 0;