Search in sources :

Example 6 with GcodeCommand

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

the class BufferedCommunicator method streamCommands.

/**
 * Streams anything in the command buffer to the comm port.
 * Synchronized to prevent commands from sending out of order.
 */
@Override
public synchronized void streamCommands() {
    // If there are no commands to send, exit.
    if (this.getNextCommand() == null) {
        logger.log(Level.INFO, "There are no more commands to stream");
        return;
    }
    // OR  We are in single command mode and there are no active commands.
    while (this.getNextCommand() != null && !isPaused() && CommUtils.checkRoomInBuffer(this.sentBufferSize, this.getNextCommand().getCommandString(), this.getBufferSize()) && allowMoreCommands()) {
        GcodeCommand command = this.getNextCommand();
        if (command.getCommandString().isEmpty()) {
            dispatchListenerEvents(COMMAND_SKIPPED, command);
            nextCommand = null;
            continue;
        }
        String commandString = command.getCommandString().trim();
        this.activeCommandList.add(command);
        this.sentBufferSize += (commandString.length() + 1);
        // Command already has a newline attached.
        this.sendMessageToConsoleListener(">>> " + commandString + "\n");
        try {
            this.sendingCommand(commandString);
            conn.sendStringToComm(commandString + "\n");
            dispatchListenerEvents(COMMAND_SENT, command);
            nextCommand = null;
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) IOException(java.io.IOException)

Example 7 with GcodeCommand

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

the class GrblController method viewParserState.

@Override
public void viewParserState() throws Exception {
    if (this.isCommOpen()) {
        String gcode = GrblUtils.getViewParserStateCommand(this.grblVersion, this.grblVersionLetter);
        if (!"".equals(gcode)) {
            GcodeCommand command = createCommand(gcode);
            this.sendCommandImmediately(command);
            return;
        }
    }
    // Throw exception
    super.viewParserState();
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Example 8 with GcodeCommand

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

the class GrblController method performHomingCycle.

/**
 * Sends the version specific homing cycle to the machine.
 */
@Override
public void performHomingCycle() throws Exception {
    if (this.isCommOpen()) {
        String gcode = GrblUtils.getHomingCommand(this.grblVersion, this.grblVersionLetter);
        if (!"".equals(gcode)) {
            GcodeCommand command = createCommand(gcode);
            this.sendCommandImmediately(command);
            return;
        }
    }
    // Throw exception
    super.performHomingCycle();
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Example 9 with GcodeCommand

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

the class GrblController method resetCoordinatesToZero.

@Override
public void resetCoordinatesToZero() throws Exception {
    if (this.isCommOpen()) {
        String gcode = GrblUtils.getResetCoordsToZeroCommand(this.grblVersion, this.grblVersionLetter);
        if (!"".equals(gcode)) {
            GcodeCommand command = createCommand(gcode);
            this.sendCommandImmediately(command);
            return;
        }
    }
    // Throw exception
    super.resetCoordinatesToZero();
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Example 10 with GcodeCommand

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

the class GrblController method returnToHome.

@Override
public void returnToHome() throws Exception {
    if (this.isCommOpen()) {
        ArrayList<String> commands = GrblUtils.getReturnToHomeCommands(this.grblVersion, this.grblVersionLetter, this.controllerStatus.getWorkCoord().z);
        if (!commands.isEmpty()) {
            Iterator<String> iter = commands.iterator();
            // Perform the homing commands
            while (iter.hasNext()) {
                String gcode = iter.next();
                GcodeCommand command = createCommand(gcode);
                this.sendCommandImmediately(command);
            }
            return;
        }
        restoreParserModalState();
    }
    // Throw exception
    super.returnToHome();
}
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