Added sanity check if there is a command active but no data can be read on the serial line
This commit is contained in:
parent
0f7ab3c71c
commit
209132054f
31
src/com.cpp
31
src/com.cpp
@ -21,7 +21,12 @@ 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
|
// logic: exactly one command is sent to DC. no other command can be sent
|
||||||
|
// until the respond has been read from the serial line.
|
||||||
|
|
||||||
|
static int errorCnt = 0;
|
||||||
|
|
||||||
|
if (readCmds.size() == 0) { // no other read command active: ok
|
||||||
if (CatSerial->isOpen())
|
if (CatSerial->isOpen())
|
||||||
{
|
{
|
||||||
if (CatSerial->error() != QSerialPort::NoError) {
|
if (CatSerial->error() != QSerialPort::NoError) {
|
||||||
@ -53,14 +58,32 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
readCmds.append(data.constData()[2]);
|
|
||||||
|
// save last command sent.
|
||||||
|
readCmds.append(data.constData()[2]); // 2: index of the last command
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCritical() << __func__ << ":" << __LINE__
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
<< "ERROR sending" << data.toHex(':') << "port is not open";
|
<< "ERROR sending" << data.toHex(':') << "port is not open";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << __func__ << "" << __LINE__ << "ERROR detected active read cmd" << readCmds[0];
|
qCritical() << __func__ << "" << __LINE__ << "ERROR detected active read cmd" << readCmds[0];
|
||||||
readCmds.clear();
|
if (CatSerial->isOpen()) {
|
||||||
|
int availableBytes = CatSerial->bytesAvailable();
|
||||||
|
qCritical() << __func__ << "" << __LINE__ << "ERROR available bytes" << availableBytes;
|
||||||
|
if (availableBytes == 0) {
|
||||||
|
errorCnt += 1;
|
||||||
|
if (errorCnt > 100) {
|
||||||
|
readCmds.clear();
|
||||||
|
errorCnt = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errorCnt = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
|
<< "ERROR sending" << data.toHex(':') << "port is not open";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user