diff --git a/src/core/ifirmware.cpp b/src/core/ifirmware.cpp --- a/src/core/ifirmware.cpp +++ b/src/core/ifirmware.cpp @@ -72,5 +72,5 @@ QByteArray IFirmware::translate(const QString &command) { - return command.toLocal8Bit(); + return command.append(QStringLiteral("\n")).toLocal8Bit(); } diff --git a/src/core/seriallayer.h b/src/core/seriallayer.h --- a/src/core/seriallayer.h +++ b/src/core/seriallayer.h @@ -108,13 +108,6 @@ */ void push(); - /** - * @brief Check if is a command available - * - * @return bool - */ - bool commandAvailable() const; - /** * @brief Return a QStringList of valids serial baud rates * diff --git a/src/core/seriallayer.cpp b/src/core/seriallayer.cpp --- a/src/core/seriallayer.cpp +++ b/src/core/seriallayer.cpp @@ -31,9 +31,6 @@ namespace { -QByteArray _return = QByteArray("\r"); -QByteArray _newLine = QByteArray("\n"); -QByteArray _newLineReturn = QByteArray("\n"); QStringList _validBaudRates = { QStringLiteral("9600"), QStringLiteral("14400"), @@ -57,8 +54,6 @@ { public: bool _serialOpened; //!< @param _serialOpened: is serial port opened - QByteArray _rawData; //!< @param _rawData: the raw serial data - QVector _rByteCommands; //!< @param _rByteCommand: received Messages QVector _sByteCommands; //!< @param _sByteCommand: sent Messages }; @@ -75,22 +70,12 @@ void SerialLayer::readAllData() { - d->_rawData.append(readAll()); - - //Remove any \r in the string, then split by \n. - //This removes any trailing \r or \n from the commands - // Proper line endings are added when the command is pushed. - d->_rawData = d->_rawData.replace(_return, QByteArray()); - - QList tempList = d->_rawData.split(_newLine.at(0)); - for (auto i = tempList.begin(); i != tempList.end(); ++i) { - // Get finished line to _byteCommands - if (i < tempList.end() - 1) { - d->_rByteCommands.append(*i); - emit receivedCommand(*i); - } else { - d->_rawData.clear(); - d->_rawData.append(*i); + // Some firmwares can return \n, \r, \n\r or \r\n + QStringList tempList = QString::fromLatin1(readAll()).split(QRegExp(QStringLiteral("(\\n|\\r)"))); + for (const auto& command : tempList) { + // Remove empty strings if there is any + if(!command.isEmpty()) { + emit receivedCommand(command.toLocal8Bit()); } } } @@ -109,7 +94,7 @@ void SerialLayer::pushCommand(const QByteArray &comm) { - pushCommand(comm, _newLineReturn); + pushCommand(comm); } void SerialLayer::add(const QByteArray &comm, const QByteArray &term) @@ -120,7 +105,7 @@ void SerialLayer::add(const QByteArray &comm) { - add(comm, _newLineReturn); + add(comm); } void SerialLayer::push() @@ -136,11 +121,6 @@ d->_sByteCommands.clear(); } -bool SerialLayer::commandAvailable() const -{ - return !d->_rByteCommands.isEmpty(); -} - QStringList SerialLayer::validBaudRates() const { return _validBaudRates; diff --git a/src/plugins/grblplugin.cpp b/src/plugins/grblplugin.cpp --- a/src/plugins/grblplugin.cpp +++ b/src/plugins/grblplugin.cpp @@ -72,5 +72,6 @@ } temp.removeAll(QString()); + temp.append({}); return temp.join(QStringLiteral("\n")).toLocal8Bit(); }