writeToSerial():
Write to serial line in one call as before.
This commit is contained in:
parent
8714071a30
commit
b024e34b82
@ -42,20 +42,14 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
|
|||||||
CatSerial->clear();
|
CatSerial->clear();
|
||||||
|
|
||||||
QByteArray buffer(data);
|
QByteArray buffer(data);
|
||||||
int bytesToWrite = buffer.size();
|
|
||||||
while (bytesToWrite > 0 && !buffer.isEmpty()) {
|
|
||||||
int bytesWritten = CatSerial->write(buffer);
|
int bytesWritten = CatSerial->write(buffer);
|
||||||
if (bytesWritten != -1) {
|
if (bytesWritten == -1) {
|
||||||
bytesToWrite -= bytesWritten;
|
|
||||||
buffer = buffer.right(bytesWritten);
|
|
||||||
} else {
|
|
||||||
qCritical() << __func__ << ":" << __LINE__
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
<< QString("ERROR %1 for sending %2").arg(CatSerial->errorString()).arg(data.toHex(':').constData());
|
<< QString("ERROR %1 for sending %2").arg(CatSerial->errorString()).arg(data.toHex(':').constData());
|
||||||
CatSerial->clearError();
|
CatSerial->clearError();
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "cleared error on serial line. returning ...";
|
qCritical() << __func__ << ":" << __LINE__ << "cleared error on serial line. returning ...";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
CatSerial->flush();
|
CatSerial->flush();
|
||||||
writeCount += 1;
|
writeCount += 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user