diff --git a/src/core/atcore.h b/src/core/atcore.h
--- a/src/core/atcore.h
+++ b/src/core/atcore.h
@@ -144,10 +144,11 @@
* @brief Initialize a connection to \p port at a speed of \p baud
* @param port: the port to initialize
* @param baud: the baud of the port
+ * @param disableROC: atcore will attempt to disable reset on connect for this device.
* @return True is connection was successful
* @sa serialPorts(),serial(),closeConnection()
*/
- Q_INVOKABLE bool initSerial(const QString &port, int baud);
+ Q_INVOKABLE bool initSerial(const QString &port, int baud, bool disableROC = false);
/**
* @brief Returns a list of valid baud speeds
@@ -500,6 +501,12 @@
*/
void locateSerialPort();
+ /**
+ * @brief Attempts to disableResetOnConnect for the selected port.
+ * @param port: the port.
+ */
+ void disableResetOnConnect(const QString &port);
+
/**
* @brief Send request to the printer for the sd card file list.
*/
diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp
--- a/src/core/atcore.cpp
+++ b/src/core/atcore.cpp
@@ -31,6 +31,7 @@
#include
#include
#include
+#include
#include "atcore.h"
#include "atcore_version.h"
@@ -212,8 +213,12 @@
}
}
-bool AtCore::initSerial(const QString &port, int baud)
+bool AtCore::initSerial(const QString &port, int baud, bool disableROC)
{
+ if (disableROC) {
+ disableResetOnConnect(port);
+ }
+
d->serial = new SerialLayer(port, baud);
if (serialInitialized() && d->serial->isWritable()) {
setState(AtCore::CONNECTING);
@@ -392,6 +397,7 @@
QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close.");
qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg);
}
+ //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection.
serial()->close();
//Clear our copy of the sdcard filelist
clearSdCardFileList();
@@ -783,3 +789,21 @@
}
pushCommand(GCode::toCommand(GCode::M27));
}
+
+void AtCore::disableResetOnConnect(const QString &port)
+{
+#ifdef Q_OS_UNIX
+//should work on all unix'
+ QProcess process;
+ QStringList args = {QStringLiteral("-F/dev/%1").arg(port), QStringLiteral("-hupcl")};
+ process.start(QStringLiteral("stty"), args);
+ process.waitForFinished(500);
+
+ connect(&process, &QProcess::errorOccurred, this, [this, &process] {
+ qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString();
+ });
+
+#elif Q_OS_WIN
+ //TODO: Disable hangup on windows.
+#endif
+}
diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h
--- a/testclient/mainwindow.h
+++ b/testclient/mainwindow.h
@@ -164,6 +164,7 @@
QComboBox *comboBAUD = nullptr;
QComboBox *comboPlugin = nullptr;
QPushButton *buttonConnect = nullptr;
+ QCheckBox *cbReset = nullptr;
void makeMoveDock();
QDockWidget *moveDock = nullptr;
diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp
--- a/testclient/mainwindow.cpp
+++ b/testclient/mainwindow.cpp
@@ -24,6 +24,7 @@
#include
#include
#include
+#include
#include
#include "mainwindow.h"
@@ -245,6 +246,14 @@
hBoxLayout->addWidget(comboPlugin, 75);
mainLayout->addLayout(hBoxLayout);
+ cbReset = new QCheckBox(tr("Attempt to stop Reset on connect"));
+ cbReset->setHidden(true);
+ mainLayout->addWidget(cbReset);
+
+ connect(comboPlugin, &QComboBox::currentTextChanged, this, [this](const QString & currentText) {
+ cbReset->setHidden(currentText == tr("Autodetect"));
+ });
+
buttonConnect = new QPushButton(tr("Connect"));
connect(buttonConnect, &QPushButton::clicked, this, &MainWindow::connectPBClicked);
mainLayout->addWidget(buttonConnect);
@@ -413,13 +422,17 @@
void MainWindow::connectPBClicked()
{
if (core->state() == AtCore::DISCONNECTED) {
- if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt())) {
+ if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt(), cbReset->isChecked())) {
connect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog);
connect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog);
buttonConnect->setText(tr("Disconnect"));
logWidget->appendLog(tr("Serial connected"));
if (!comboPlugin->currentText().contains(tr("Autodetect"))) {
core->loadFirmwarePlugin(comboPlugin->currentText());
+ if (cbReset->isChecked()) {
+ //Wait a few seconds after connect to avoid the normal errors
+ QTimer::singleShot(5000, core, &AtCore::sdCardPrintStatus);
+ }
}
}
} else {