From b024e34b82c75a41ec0a5911e4ea8ea0e65fed2c Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 16 Oct 2024 13:21:33 +0200 Subject: [PATCH] writeToSerial(): Write to serial line in one call as before. --- src/com.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/com.cpp b/src/com.cpp index 4be8ae7..51163bc 100644 --- a/src/com.cpp +++ b/src/com.cpp @@ -42,19 +42,13 @@ 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 { - 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; - } + int bytesWritten = CatSerial->write(buffer); + 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();