Changeset View
Standalone View
src/core/atcore.cpp
Show All 25 Lines | |||||
26 | #include <QDir> | 26 | #include <QDir> | ||
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 <QProcess> | ||||
34 | 35 | | |||
35 | #include "atcore.h" | 36 | #include "atcore.h" | ||
36 | #include "atcore_version.h" | 37 | #include "atcore_version.h" | ||
37 | #include "seriallayer.h" | 38 | #include "seriallayer.h" | ||
38 | #include "gcodecommands.h" | 39 | #include "gcodecommands.h" | ||
39 | #include "printthread.h" | 40 | #include "printthread.h" | ||
40 | #include "atcore_default_folders.h" | 41 | #include "atcore_default_folders.h" | ||
41 | 42 | | |||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 193 | } else { | |||
204 | setState(IDLE); | 205 | setState(IDLE); | ||
205 | } | 206 | } | ||
206 | } else { | 207 | } else { | ||
207 | qCDebug(ATCORE_CORE) << "Plugin:" << fwName << ": Not found."; | 208 | qCDebug(ATCORE_CORE) << "Plugin:" << fwName << ": Not found."; | ||
208 | emit atcoreMessage(tr("No plugin found for %1.").arg(fwName)); | 209 | emit atcoreMessage(tr("No plugin found for %1.").arg(fwName)); | ||
209 | } | 210 | } | ||
210 | } | 211 | } | ||
211 | 212 | | |||
212 | bool AtCore::initSerial(const QString &port, int baud) | 213 | bool AtCore::initSerial(const QString &port, int baud, bool disableROC) | ||
213 | { | 214 | { | ||
215 | if (disableROC) { | ||||
216 | disableResetOnConnect(port); | ||||
217 | } | ||||
218 | | ||||
214 | d->serial = new SerialLayer(port, baud); | 219 | d->serial = new SerialLayer(port, baud); | ||
215 | if (serialInitialized() && d->serial->isWritable()) { | 220 | if (serialInitialized() && d->serial->isWritable()) { | ||
216 | setState(AtCore::CONNECTING); | 221 | setState(AtCore::CONNECTING); | ||
217 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | 222 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | ||
218 | d->serialTimer->stop(); | 223 | d->serialTimer->stop(); | ||
219 | return true; | 224 | return true; | ||
220 | } else { | 225 | } else { | ||
221 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | 226 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | ||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 388 | if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { | |||
384 | disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); | 389 | disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); | ||
385 | d->tempTimer->stop(); | 390 | d->tempTimer->stop(); | ||
386 | } | 391 | } | ||
387 | //Attempt to unload the firmware plugin. | 392 | //Attempt to unload the firmware plugin. | ||
388 | QString name = firmwarePlugin()->name(); | 393 | QString name = firmwarePlugin()->name(); | ||
389 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | 394 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | ||
390 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | 395 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | ||
391 | } | 396 | } | ||
397 | //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection. | ||||
392 | serial()->close(); | 398 | serial()->close(); | ||
393 | //Clear our copy of the sdcard filelist | 399 | //Clear our copy of the sdcard filelist | ||
394 | clearSdCardFileList(); | 400 | clearSdCardFileList(); | ||
395 | setState(AtCore::DISCONNECTED); | 401 | setState(AtCore::DISCONNECTED); | ||
396 | d->serialTimer->start(); | 402 | d->serialTimer->start(); | ||
397 | } | 403 | } | ||
398 | } | 404 | } | ||
399 | 405 | | |||
▲ Show 20 Lines • Show All 375 Lines • ▼ Show 20 Line(s) | |||||
775 | void AtCore::sdCardPrintStatus() | 781 | void AtCore::sdCardPrintStatus() | ||
776 | { | 782 | { | ||
777 | //One request for the Sd Job status in the queue at a time. | 783 | //One request for the Sd Job status in the queue at a time. | ||
778 | if (d->commandQueue.contains(GCode::toCommand(GCode::M27))) { | 784 | if (d->commandQueue.contains(GCode::toCommand(GCode::M27))) { | ||
779 | return; | 785 | return; | ||
780 | } | 786 | } | ||
781 | pushCommand(GCode::toCommand(GCode::M27)); | 787 | pushCommand(GCode::toCommand(GCode::M27)); | ||
782 | } | 788 | } | ||
789 | | ||||
790 | void AtCore::disableResetOnConnect(const QString &port) | ||||
791 | { | ||||
792 | #ifdef Q_OS_UNIX | ||||
793 | //should work on all unix' | ||||
794 | QProcess process; | ||||
patrickelectric: I think that a QFuture and a QFutureWatcher will be more suitable. | |||||
795 | 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
| |||||
796 | 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… | |||||
797 | process.waitForFinished(500); | ||||
798 | | ||||
799 | connect(&process, &QProcess::errorOccurred, this, [this, &process] { | ||||
800 | qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString(); | ||||
801 | }); | ||||
802 | | ||||
803 | #elif Q_OS_WIN | ||||
804 | //TODO: Disable hangup on windows. | ||||
805 | #endif | ||||
806 | } |
I think that a QFuture and a QFutureWatcher will be more suitable.