From kde-commits Mon Jul 31 23:16:36 2017 From: Chris Rizzitello Date: Mon, 31 Jul 2017 23:16:36 +0000 To: kde-commits Subject: [atcore] src: Report no serial when detecting fw and nothing connected. initSerial now returns true Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=150154301022349 Git commit 03257a185bd6cb6fa2fe125e4e02959e0c5d4b31 by Chris Rizzitello. Committed on 31/07/2017 at 20:13. Pushed by rizzitello into branch 'master'. Report no serial when detecting fw and nothing connected. initSerial now re= turns true if connection attempt successful Signed-off-by: Chris Rizzitello M +9 -3 src/atcore.cpp M +2 -1 src/atcore.h https://commits.kde.org/atcore/03257a185bd6cb6fa2fe125e4e02959e0c5d4b31 diff --git a/src/atcore.cpp b/src/atcore.cpp index ac38974..9cc6916 100644 --- a/src/atcore.cpp +++ b/src/atcore.cpp @@ -197,13 +197,17 @@ void AtCore::loadFirmwarePlugin(const QString &fwName) } } = -void AtCore::initSerial(const QString &port, int baud) +bool AtCore::initSerial(const QString &port, int baud) { d->serial =3D new SerialLayer(port, baud); if (serialInitialized()) { setState(AtCore::CONNECTING); + connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::fi= ndFirmware); + return true; + } else { + qCDebug(ATCORE_CORE) << "Failed to open device."; + return false; } - connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFi= rmware); } = bool AtCore::serialInitialized() const @@ -329,9 +333,11 @@ void AtCore::emergencyStop() = void AtCore::requestFirmware() { - qCDebug(ATCORE_CORE) << "Sending " << GCode::toString(GCode::M115); if (serialInitialized()) { + qCDebug(ATCORE_CORE) << "Sending " << GCode::toString(GCode::M115); serial()->pushCommand(GCode::toCommand(GCode::M115).toLocal8Bit()); + } else { + qCDebug(ATCORE_CORE) << "There is no open device to send commands"; } } = diff --git a/src/atcore.h b/src/atcore.h index a4dbded..77457b2 100644 --- a/src/atcore.h +++ b/src/atcore.h @@ -102,9 +102,10 @@ public: * @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 + * @return True is connection was successful * @sa serialPorts(),serial(),closeConnection() */ - void initSerial(const QString &port, int baud); + bool initSerial(const QString &port, int baud); = /** * @brief Main access ot the serialLayer