Search in sources :

Example 1 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class AbstractController method offsetTool.

@Override
public void offsetTool(String axis, double offset, UnitUtils.Units units) throws Exception {
    logger.log(Level.INFO, "Probe offset.");
    String offsetPattern = "G43.1 %s%s";
    String offsetCommand = String.format(offsetPattern, axis, formatter.format(offset * scaleUnits(units, MM)));
    GcodeCommand state = createCommand("G21 G90");
    state.setTemporaryParserModalChange(true);
    this.sendCommandImmediately(state);
    this.sendCommandImmediately(createCommand(offsetCommand));
    restoreParserModalState();
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Example 2 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class AbstractController method probe.

@Override
public void probe(String axis, double feedRate, double distance, UnitUtils.Units units) throws Exception {
    logger.log(Level.INFO, "Probing.");
    String probePattern = "G38.2 %s%s F%s";
    double unitScale = scaleUnits(units, MM);
    String probeCommand = String.format(probePattern, axis, formatter.format(distance * unitScale), formatter.format(feedRate * unitScale));
    GcodeCommand state = createCommand("G21 G91 G49");
    state.setTemporaryParserModalChange(true);
    GcodeCommand probe = createCommand(probeCommand);
    probe.setTemporaryParserModalChange(true);
    this.sendCommandImmediately(state);
    this.sendCommandImmediately(probe);
    restoreParserModalState();
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Example 3 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class AbstractController method restoreParserModalState.

@Override
public void restoreParserModalState() {
    StringBuilder cmd = new StringBuilder();
    if (getDistanceModeCode() != null) {
        cmd.append(getDistanceModeCode()).append(" ");
    }
    if (getUnitsCode() != null) {
        cmd.append(getUnitsCode()).append(" ");
    }
    try {
        GcodeCommand command = createCommand(cmd.toString());
        command.setTemporaryParserModalChange(true);
        sendCommandImmediately(command);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) IOException(java.io.IOException)

Example 4 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class BufferedCommunicator method responseMessage.

/**
 * Processes message from GRBL. This should only be called from the
 * connection object.
 * @param response
 */
@Override
public void responseMessage(String response) {
    // Send this information back up to the Controller.
    dispatchListenerEvents(SerialCommunicatorEvent.RAW_RESPONSE, response);
    // Pause if there was an error and if there are more commands queued
    if (processedCommandIsError(response) && (// No cached command
    nextCommand != null || // No more commands (except for the one being popped further down)
    (activeCommandList.size() > 1) || // No more rows in stream
    (commandStream != null && commandStream.getNumRowsRemaining() > 0) || (commandBuffer != null && commandBuffer.size() > 0))) {
        // No commands in buffer
        pauseSend();
        dispatchListenerEvents(PAUSED, "");
    }
    // Keep the data flow going in case of an "ok" or an "error".
    if (processedCommand(response)) {
        // Pop the front of the active list.
        if (this.activeCommandList != null && this.activeCommandList.size() > 0) {
            GcodeCommand command = this.activeCommandList.pop();
            this.sentBufferSize -= (command.getCommandString().length() + 1);
            if (!isPaused()) {
                this.streamCommands();
            }
        }
    }
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Example 5 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class BufferedCommunicator method activeCommandSummary.

@Override
public String activeCommandSummary() {
    StringBuilder sb = new StringBuilder();
    String comma = "";
    for (GcodeCommand gc : activeCommandList) {
        sb.append(comma).append(gc.getCommandString());
        comma = ", ";
    }
    if (commandStream != null) {
        sb.append(comma).append(commandStream.getNumRowsRemaining()).append(" streaming commands.");
    }
    return sb.toString();
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Aggregations

GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)51 Test (org.junit.Test)26 GcodeStreamTest (com.willwinder.universalgcodesender.utils.GcodeStreamTest)19 IOException (java.io.IOException)11 Connection (com.willwinder.universalgcodesender.connection.Connection)4 Position (com.willwinder.universalgcodesender.model.Position)4 ControllerListener (com.willwinder.universalgcodesender.listeners.ControllerListener)3 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)3 File (java.io.File)3 LinkedList (java.util.LinkedList)3 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)2 EasyMock.anyString (org.easymock.EasyMock.anyString)2 UnexpectedCommand (com.willwinder.universalgcodesender.AbstractController.UnexpectedCommand)1 GcodeMeta (com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta)1 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)1 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)1 LineSplitter (com.willwinder.universalgcodesender.gcode.processors.LineSplitter)1 M30Processor (com.willwinder.universalgcodesender.gcode.processors.M30Processor)1 MeshLeveler (com.willwinder.universalgcodesender.gcode.processors.MeshLeveler)1 Translator (com.willwinder.universalgcodesender.gcode.processors.Translator)1