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