Search in sources :

Example 31 with GcodeCommand

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

the class GcodeCommandBuffer method appendCommandString.

public GcodeCommand appendCommandString(String commandString) {
    GcodeCommand command = new GcodeCommand(commandString);
    command.setCommandNumber(this.numCommands++);
    this.commandQueue.add(command);
    // Preload first command, or next command if the first batch finished.
    if (this.currentCommand == null || this.currentCommand.isSent()) {
        this.nextCommand();
    }
    return command;
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Example 32 with GcodeCommand

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

the class GUIBackendTest method sendGcodeCommandWhenConnectedShouldBeOk.

@Test
public void sendGcodeCommandWhenConnectedShouldBeOk() throws Exception {
    // Given
    instance.connect(FIRMWARE, PORT, BAUD_RATE);
    when(controller.isCommOpen()).thenReturn(true);
    GcodeCommand gcodeCommand = new GcodeCommand("G00");
    when(controller.createCommand(any())).thenReturn(gcodeCommand);
    // When
    instance.sendGcodeCommand("G00");
    // Then
    verify(controller, times(1)).sendCommandImmediately(any());
    verify(controller, times(1)).sendCommandImmediately(gcodeCommand);
    verify(controller, times(0)).restoreParserModalState();
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test)

Example 33 with GcodeCommand

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

the class GUIBackendTest method sendGcodeCommandWhenNotConnectedShouldThrowException.

@Test(expected = Exception.class)
public void sendGcodeCommandWhenNotConnectedShouldThrowException() throws Exception {
    // Given
    instance.connect(FIRMWARE, PORT, BAUD_RATE);
    when(controller.isCommOpen()).thenReturn(false);
    GcodeCommand gcodeCommand = new GcodeCommand("G00");
    when(controller.createCommand(any())).thenReturn(gcodeCommand);
    // When
    instance.sendGcodeCommand("G00");
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test)

Example 34 with GcodeCommand

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

the class GcodeStreamTest method testGcodeStreamReadWrite.

/**
 * Writes 1,000,000 rows to a file then reads it back out.
 */
@Test
public void testGcodeStreamReadWrite() throws FileNotFoundException, IOException, GcodeStreamReader.NotGcodeStreamFile {
    int rows = 1000000;
    File f = new File(tempDir, "gcodeFile");
    try {
        try (GcodeStreamWriter gsw = new GcodeStreamWriter(f)) {
            for (int i = 0; i < rows; i++) {
                gsw.addLine("Line " + i + " before", "Line " + i + " after", null, i);
            }
        }
        try (GcodeStreamReader gsr = new GcodeStreamReader(f)) {
            Assert.assertEquals(rows, gsr.getNumRows());
            int count = 0;
            while (gsr.getNumRowsRemaining() > 0) {
                GcodeCommand gc = gsr.getNextCommand();
                Assert.assertEquals("Line " + count + " after", gc.getCommandString());
                Assert.assertEquals("", gc.getComment());
                Assert.assertEquals(count, gc.getCommandNumber());
                count++;
                Assert.assertEquals(rows - count, gsr.getNumRowsRemaining());
            }
            Assert.assertEquals(rows, count);
        }
    } finally {
        FileUtils.forceDelete(f);
    }
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) File(java.io.File) Test(org.junit.Test)

Example 35 with GcodeCommand

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

the class GrblCommunicatorTest method testStreamCommands.

/**
 * Test of sendStringToComm method, of class GrblCommunicator.
 */
@Test
public void testStreamCommands() {
    System.out.println("streamCommands");
    MockConnection mc = new MockConnection(mg.in, mg.out);
    GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);
    String term = "\n";
    String thirtyNineCharString = "thirty-nine character command here.....";
    boolean result;
    boolean expResult;
    // Make sure CommUtil is still an overly cautious jerk.
    LinkedList<GcodeCommand> l = new LinkedList<>();
    l.add(new GcodeCommand("12characters"));
    assertEquals(13, CommUtils.getSizeOfBuffer(l));
    // Make sure GrblUtils hasn't updated RX buffer size.
    assertEquals(123, GrblUtils.GRBL_RX_BUFFER_SIZE);
    // Add a bunch of commands so that the buffer is full.
    // 39*3 + 3 newlines + 3 CommUtils caution  = 123 == buffer size.
    instance.queueStringForComm(thirtyNineCharString);
    instance.queueStringForComm(thirtyNineCharString);
    instance.queueStringForComm(thirtyNineCharString);
    // Stream them so that there are active commands.
    instance.streamCommands();
    expResult = true;
    result = instance.areActiveCommands();
    assertEquals(expResult, result);
    // Add another command and stream it so that something is queued.
    instance.queueStringForComm(thirtyNineCharString);
    instance.streamCommands();
    expResult = true;
    result = instance.areActiveCommands();
    assertEquals(expResult, result);
    // Check with MockGrbl to verify the fourth command wasn't sent.
    String output = mg.readStringFromGrblBuffer();
    String goal = thirtyNineCharString + term + thirtyNineCharString + term + thirtyNineCharString + term;
    assertEquals(goal, output);
    // Make room for the next command.
    mc.sendResponse("ok");
    // Send it.
    instance.streamCommands();
    // Make sure the queued command was sent.
    output = mg.readStringFromGrblBuffer();
    assertEquals(thirtyNineCharString + term, output);
    // Wrap up.
    mc.sendResponse("ok");
    mc.sendResponse("ok");
    mc.sendResponse("ok");
    expResult = false;
    result = instance.areActiveCommands();
    assertEquals(expResult, result);
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) MockConnection(com.willwinder.universalgcodesender.mockobjects.MockConnection) LinkedList(java.util.LinkedList) Test(org.junit.Test)

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