writeToSerial():
Only write to serial interface if no current command has been sent to DC already.
This commit is contained in:
parent
6321f9068f
commit
26a11e6c56
43
src/com.cpp
43
src/com.cpp
@ -20,13 +20,48 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
|
|||||||
{
|
{
|
||||||
sendBuffer=data;
|
sendBuffer=data;
|
||||||
sendLen=sendLength;
|
sendLen=sendLength;
|
||||||
|
|
||||||
|
if (readCmds.size() == 0) { // no other read command active
|
||||||
if (CatSerial->isOpen())
|
if (CatSerial->isOpen())
|
||||||
{
|
{
|
||||||
//qDebug() << "sending..." << sendBuffer;
|
if (CatSerial->error() != QSerialPort::NoError) {
|
||||||
CatSerial->write(sendBuffer);
|
qCritical() << __func__ << "" << __LINE__ << "ERROR on serial line" << CatSerial->errorString();
|
||||||
} else
|
CatSerial->clearError();
|
||||||
qDebug() << "error sending, port is not open";
|
qCritical() << __func__ << "" << __LINE__ << "cleared error on serial line";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CatSerial->atEnd()) {
|
||||||
|
qCritical() << QString("ERROR %1 bytes available on serial line before write").arg(CatSerial->bytesAvailable());
|
||||||
|
qCritical() << CatSerial->readAll().toHex(':');
|
||||||
|
CatSerial->clear();
|
||||||
|
qCritical() << __func__ << "" << __LINE__ << "read all data from serial line";
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray buffer(data);
|
||||||
|
|
||||||
|
int bytesToWrite = buffer.size();
|
||||||
|
while (bytesToWrite > 0 && !buffer.isEmpty()) {
|
||||||
|
int bytesWritten = CatSerial->write(buffer);
|
||||||
|
if (bytesWritten != -1 && CatSerial->waitForBytesWritten(1000)) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
readCmds.append(data.constData()[2]);
|
||||||
|
} else {
|
||||||
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
|
<< "ERROR sending" << data.toHex(':') << "port is not open";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << __func__ << "" << __LINE__ << "ERROR detected active read cmd" << readCmds[0];
|
||||||
|
readCmds.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user