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