writeToSerial():

Write to serial line in one call as before.
This commit is contained in:
Gerhard Hoffmann 2024-10-16 13:21:33 +02:00
parent 8714071a30
commit b024e34b82

View File

@ -42,20 +42,14 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
CatSerial->clear();
QByteArray buffer(data);
int bytesToWrite = buffer.size();
while (bytesToWrite > 0 && !buffer.isEmpty()) {
int bytesWritten = CatSerial->write(buffer);
if (bytesWritten != -1) {
bytesToWrite -= bytesWritten;
buffer = buffer.right(bytesWritten);
} else {
if (bytesWritten == -1) {
qCritical() << __func__ << ":" << __LINE__
<< QString("ERROR %1 for sending %2").arg(CatSerial->errorString()).arg(data.toHex(':').constData());
CatSerial->clearError();
qCritical() << __func__ << ":" << __LINE__ << "cleared error on serial line. returning ...";
return;
}
}
CatSerial->flush();
writeCount += 1;