Sending a sequence of commands and wait for response <p>I have to update firmware and settings on a device connected to a serial port. Since this is done by a sequence of commands, I send a command and wait until I recive an answer. Inside the answere (many lines) I search for a string that indicates if the operation is finished successfully.</p> <pre><code>Serial-&gt;write(“boot”, 1000); Serial-&gt;waitForKeyword(“boot successful”); Serial-&gt;sendFile(“image.dat”); … </code></pre> <p>So I’ve created a new Thread for this blocking read/write method. Inside the thread I make use of the waitForX() functions. If I call watiForKeyword() it will call readLines() until it detects the keyword or timesout</p> <pre><code>bool waitForKeyword(const QString &amp;keyword) { QString str; // read all lines while(serial-&gt;readLines(10000)) { // check each line while((str = serial-&gt;getLine()) != "") { // found! if(str.contains(keyword)) return true; } } // timeout return false; } </code></pre> <p>readLines() reads everything available and separates it into lines , each line is placed inside a QStringList and to get a string I call getLine() which returns the first string in the list and deletes it.</p> <pre><code>bool SerialPort::readLines(int waitTimeout) { if(!waitForReadyRead(waitTimeout)) { qDebug() &lt;&lt; "Timeout reading" &lt;&lt; endl; return false; } QByteArray data = readAll(); while (waitForReadyRead(100)) data += readAll(); char* begin = data.data(); char* ptr = strstr(data, "\r\n"); while(ptr != NULL) { ptr+=2; buffer.append(begin, ptr - begin); emit readyReadLine(buffer); lineBuffer.append(QString(buffer)); // store line in Qstringlist buffer.clear(); begin = ptr; ptr = strstr(begin, "\r\n"); } // rest buffer.append(begin, -1); return true; } </code></pre> <p>The problem is if I send a file via terminal to test the app readLines() will only read a smale part of the file ( 5 Lines or so). Since these lines do not contain the keyword. the function will run once again, but this time it dosnt wait for timeout, readLines just return false immediately. Whats wrong ? Also I'm not shure if this is the right approach... Does anyone know how to send a sequenze of commands and wait for a response each time?</p>