Changeset View
Standalone View
src/core/atcore.cpp
Show All 26 Lines | |||||
27 | #include <QSerialPortInfo> | 27 | #include <QSerialPortInfo> | ||
28 | #include <QPluginLoader> | 28 | #include <QPluginLoader> | ||
29 | #include <QCoreApplication> | 29 | #include <QCoreApplication> | ||
30 | #include <QLoggingCategory> | 30 | #include <QLoggingCategory> | ||
31 | #include <QTime> | 31 | #include <QTime> | ||
32 | #include <QTimer> | 32 | #include <QTimer> | ||
33 | #include <QThread> | 33 | #include <QThread> | ||
34 | #include <QMetaEnum> | 34 | #include <QMetaEnum> | ||
35 | #include <QProcess> | ||||
35 | 36 | | |||
36 | #include "atcore.h" | 37 | #include "atcore.h" | ||
37 | #include "atcore_version.h" | 38 | #include "atcore_version.h" | ||
38 | #include "seriallayer.h" | 39 | #include "seriallayer.h" | ||
39 | #include "gcodecommands.h" | 40 | #include "gcodecommands.h" | ||
40 | #include "printthread.h" | 41 | #include "printthread.h" | ||
41 | #include "atcore_default_folders.h" | 42 | #include "atcore_default_folders.h" | ||
42 | 43 | | |||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Line(s) | 199 | } else { | |||
210 | setState(IDLE); | 211 | setState(IDLE); | ||
211 | } | 212 | } | ||
212 | } else { | 213 | } else { | ||
213 | qCDebug(ATCORE_CORE) << "Plugin:" << fwName << ": Not found."; | 214 | qCDebug(ATCORE_CORE) << "Plugin:" << fwName << ": Not found."; | ||
214 | emit atcoreMessage(tr("No plugin found for %1.").arg(fwName)); | 215 | emit atcoreMessage(tr("No plugin found for %1.").arg(fwName)); | ||
215 | } | 216 | } | ||
216 | } | 217 | } | ||
217 | 218 | | |||
218 | bool AtCore::initSerial(const QString &port, int baud) | 219 | bool AtCore::initSerial(const QString &port, int baud, bool disableROC) | ||
219 | { | 220 | { | ||
221 | if (disableROC) { | ||||
222 | disableResetOnConnect(port); | ||||
223 | } | ||||
224 | | ||||
220 | d->serial = new SerialLayer(port, baud); | 225 | d->serial = new SerialLayer(port, baud); | ||
221 | if (serialInitialized() && d->serial->isWritable()) { | 226 | if (serialInitialized() && d->serial->isWritable()) { | ||
222 | setState(AtCore::CONNECTING); | 227 | setState(AtCore::CONNECTING); | ||
223 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | 228 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | ||
224 | d->serialTimer->stop(); | 229 | d->serialTimer->stop(); | ||
225 | return true; | 230 | return true; | ||
226 | } else { | 231 | } else { | ||
227 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | 232 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | ||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 394 | if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { | |||
390 | disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); | 395 | disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); | ||
391 | d->tempTimer->stop(); | 396 | d->tempTimer->stop(); | ||
392 | } | 397 | } | ||
393 | //Attempt to unload the firmware plugin. | 398 | //Attempt to unload the firmware plugin. | ||
394 | QString name = firmwarePlugin()->name(); | 399 | QString name = firmwarePlugin()->name(); | ||
395 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | 400 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | ||
396 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | 401 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | ||
397 | } | 402 | } | ||
403 | //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection. | ||||
398 | serial()->close(); | 404 | serial()->close(); | ||
399 | //Clear our copy of the sdcard filelist | 405 | //Clear our copy of the sdcard filelist | ||
400 | clearSdCardFileList(); | 406 | clearSdCardFileList(); | ||
401 | setState(AtCore::DISCONNECTED); | 407 | setState(AtCore::DISCONNECTED); | ||
402 | d->serialTimer->start(); | 408 | d->serialTimer->start(); | ||
403 | } | 409 | } | ||
404 | } | 410 | } | ||
405 | 411 | | |||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Line(s) | |||||
765 | void AtCore::sdCardPrintStatus() | 771 | void AtCore::sdCardPrintStatus() | ||
766 | { | 772 | { | ||
767 | //One request for the Sd Job status in the queue at a time. | 773 | //One request for the Sd Job status in the queue at a time. | ||
768 | if (d->commandQueue.contains(GCode::toCommand(GCode::M27))) { | 774 | if (d->commandQueue.contains(GCode::toCommand(GCode::M27))) { | ||
769 | return; | 775 | return; | ||
770 | } | 776 | } | ||
771 | pushCommand(GCode::toCommand(GCode::M27)); | 777 | pushCommand(GCode::toCommand(GCode::M27)); | ||
772 | } | 778 | } | ||
779 | | ||||
780 | void AtCore::disableResetOnConnect(const QString &port) | ||||
781 | { | ||||
782 | #ifdef Q_OS_UNIX | ||||
783 | //should work on all unix' | ||||
784 | QProcess process; | ||||
patrickelectric: I think that a QFuture and a QFutureWatcher will be more suitable. | |||||
785 | QStringList args({QStringLiteral("-F/dev/%1").arg(port), QStringLiteral("-hupcl")}); | ||||
patrickelectric: QStringList args({..., ... }) | |||||
patrickelectric: -F [space] /dev | |||||
-F<space> the space is optional and causes errors with the command some times. rizzitello: -F<space> the space is optional and causes errors with the command some times.
| |||||
patrickelectric: will this fail in IOS no ? | |||||
I don't know if it will work on ios or not . that will depend on if it comes with stty. however much like for android i do not expect this to be run directly on that platform. rizzitello: I don't know if it will work on ios or not . that will depend on if it comes with stty. however… | |||||
stty -F /dev/ttyUSB0 -h upcl stty: invalid argument ‘-h’ Try 'stty --help' for more information. This command does not work here. patrickelectric: ```
stty -F /dev/ttyUSB0 -h upcl
stty: invalid argument ‘-h’
Try 'stty --help' for more… | |||||
rizzitello: -hupcl is the option it is not -h upcl
| |||||
786 | process.start(QStringLiteral("stty"), args); | ||||
do you need to open stty to set the serial stuff? tcanabrava: do you need to open stty to set the serial stuff?
there's no posix interface for that? (real… | |||||
I tried several methods using various Q methods and connection options. The only way I was able to find that consistently worked (on Linux) was using stty. This method is also flawed and If we can find a better way before merging that would be great. Ideally this would be a solution that works cross platform. I honestly didn't even look at any posix specific calls to do this since i was looking for a solution and only stty worked consistently . rizzitello: I tried several methods using various Q methods and connection options. The only way I was able… | |||||
787 | process.waitForFinished(500); | ||||
788 | | ||||
789 | connect(&process, &QProcess::errorOccurred, this, [this, &process] { | ||||
790 | qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString(); | ||||
791 | }); | ||||
792 | | ||||
793 | #elif Q_OS_WIN | ||||
794 | //TODO: Disable hangup on windows. | ||||
795 | #endif | ||||
796 | } |
I think that a QFuture and a QFutureWatcher will be more suitable.