writeToSerial():
Write to serial line in one call as before.
This commit is contained in:
parent
8714071a30
commit
b024e34b82
20
src/com.cpp
20
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();
|
||||
|
Loading…
Reference in New Issue
Block a user