diff --git a/src/plugins/grblplugin.cpp b/src/plugins/grblplugin.cpp --- a/src/plugins/grblplugin.cpp +++ b/src/plugins/grblplugin.cpp @@ -49,19 +49,21 @@ QByteArray GrblPlugin::translate(const QString &command) { QString temp = command; - //Match all G and M Commands up until the start of the next G/M command or the end of the string. + //Match all G and M commands followed by one or more digits up to and include the space, + //if thats followed by a letter capture any non G or M starting text + //else just grab the digits that follow. //ex: G28 X Y M1 would capture "G28 X Y" and "M1" - static const auto regEx = QRegularExpression(QStringLiteral("[GM]\\d+.[^GM]+")); + static const auto regEx = QRegularExpression(QStringLiteral("[GM]\\d+.(?(?=\\D)[^GM]+|\\d+)?")); + QRegularExpressionMatch secondCommand = regEx.match(temp, 1); if (secondCommand.hasMatch()) { QRegularExpressionMatchIterator commandMatch = regEx.globalMatch(temp); temp.clear(); while (commandMatch.hasNext()) { QRegularExpressionMatch t = commandMatch.next(); - temp.append(t.captured()); + temp.append(t.captured().simplified()); if (commandMatch.hasNext()) { - temp = temp.simplified(); temp.append(QStringLiteral("\r\n")); } } diff --git a/unittests/atcoretests.cpp b/unittests/atcoretests.cpp --- a/unittests/atcoretests.cpp +++ b/unittests/atcoretests.cpp @@ -197,9 +197,10 @@ { QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G28")) == "G28"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("M104 S50 G28 X")) == "M104 S50\r\nG28 X"); - QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G00 G43 H0 Z0.1")) == "G00\r\nG43 H0 Z0.1"); + QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G00 G43 H0 Z0.1")) == "G00\r\nG43 H0 Z0.1"); QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("M6 T0")) == "M6 T0"); - + QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G0 G49 G40 G17 G80 G50 G90")) == "G0\r\nG49\r\nG40\r\nG17\r\nG80\r\nG50\r\nG90"); + QVERIFY(core->firmwarePlugin()->translate(QStringLiteral("G0 S49 XY G40")) == "G0 S49 XY\r\nG40"); } void AtCoreTests::testPluginMarlin_load()