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