Fix up a crash that could happen if a gvret device was not connected when starting savvycan (when it was connected when savvycan closed)

This commit is contained in:
Collin Kidder
2018-07-24 21:36:25 -04:00
parent 6ee5a7f7d7
commit ec6d716ae3
+12 -2
View File
@@ -342,26 +342,32 @@ void GVRetSerial::connectDevice()
serial->setBaudRate(115200); serial->setBaudRate(115200);
if (!serial->open(QIODevice::ReadWrite)) if (!serial->open(QIODevice::ReadWrite))
{ {
qDebug() << serial->errorString(); //qDebug() << serial->errorString();
} }
else
{
serial->setDataTerminalReady(false); //ESP32 uses these for bootloader selection and reset so turn them off serial->setDataTerminalReady(false); //ESP32 uses these for bootloader selection and reset so turn them off
serial->setRequestToSend(false); serial->setRequestToSend(false);
QTimer::singleShot(3000, this, SLOT(tcpConnected())); //give ESP32 some time as it probably rebooted QTimer::singleShot(3000, this, SLOT(tcpConnected())); //give ESP32 some time as it probably rebooted
} }
}
else else
{ {
serial->setFlowControl(serial->HardwareControl); //this is important though serial->setFlowControl(serial->HardwareControl); //this is important though
serial->setBaudRate(1000000); serial->setBaudRate(1000000);
if (!serial->open(QIODevice::ReadWrite)) if (!serial->open(QIODevice::ReadWrite))
{ {
qDebug() << serial->errorString(); //qDebug() << serial->errorString();
} }
else
{
serial->setDataTerminalReady(true); //you do need to set these or the fan gets dirty serial->setDataTerminalReady(true); //you do need to set these or the fan gets dirty
serial->setRequestToSend(true); serial->setRequestToSend(true);
tcpConnected(); //well, not a proper function name I guess... tcpConnected(); //well, not a proper function name I guess...
} }
} }
} }
}
void GVRetSerial::tcpConnected() void GVRetSerial::tcpConnected()
{ {
@@ -511,9 +517,13 @@ void GVRetSerial::serialError(QSerialPort::SerialPortError err)
killConnection = true; killConnection = true;
break; break;
} }
/*
if (serial)
{
serial->clearError(); serial->clearError();
serial->flush(); serial->flush();
serial->close(); serial->close();
}*/
if (errMessage.length() > 1) if (errMessage.length() > 1)
{ {
qDebug() << errMessage; qDebug() << errMessage;