Search in sources :

Example 21 with GcodeCommand

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

the class CommUtilsTest method testCheckRoomInBuffer.

/**
 * Test of checkRoomInBuffer method, of class CommUtils.
 */
@Test
public void testCheckRoomInBuffer() {
    System.out.println("checkRoomInBuffer");
    GcodeCommand nextCommand;
    Boolean expResult;
    Boolean result;
    List<GcodeCommand> list = new LinkedList<>();
    list.add(new GcodeCommand("twenty characters...", 0));
    list.add(new GcodeCommand("twenty characters...", 1));
    list.add(new GcodeCommand("twenty characters...", 2));
    list.add(new GcodeCommand("twenty characters...", 3));
    list.add(new GcodeCommand("twenty characters...", 4));
    // 100 characters + 5 for newlines, 18 characters remaining in buffer.
    StringBuilder biggestString = new StringBuilder();
    for (int i = 0; i < (GrblUtils.GRBL_RX_BUFFER_SIZE - 105 - 1); i++) {
        biggestString.append('.');
    }
    // This command should just barely fit.
    nextCommand = new GcodeCommand(biggestString.toString(), 5);
    result = CommUtils.checkRoomInBuffer(list, nextCommand, GrblUtils.GRBL_RX_BUFFER_SIZE);
    expResult = true;
    assertEquals(expResult, result);
    biggestString.append('.');
    nextCommand = new GcodeCommand(biggestString.toString(), 5);
    expResult = false;
    result = CommUtils.checkRoomInBuffer(list, nextCommand, GrblUtils.GRBL_RX_BUFFER_SIZE);
    assertEquals(expResult, result);
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 22 with GcodeCommand

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

the class CommUtilsTest method testGetSizeOfBuffer.

/**
 * Test of getSizeOfBuffer method, of class CommUtils.
 */
@Test
public void testGetSizeOfBuffer() {
    System.out.println("getSizeOfBuffer");
    List<GcodeCommand> list = new LinkedList<>();
    list.add(new GcodeCommand("twenty characters...", 0));
    list.add(new GcodeCommand("twenty characters...", 1));
    list.add(new GcodeCommand("twenty characters...", 2));
    list.add(new GcodeCommand("twenty characters...", 3));
    list.add(new GcodeCommand("twenty characters...", 4));
    // 100characters + 5 newlines.
    int expResult = 105;
    int result = CommUtils.getSizeOfBuffer(list);
    assertEquals(expResult, result);
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 23 with GcodeCommand

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

the class GrblControllerTest method testIsStreaming.

/**
 * Test of isStreamingmethod, of class GrblController.
 */
@Test
public void testIsStreaming() throws Exception {
    System.out.println("isStreaming");
    GrblController instance = new GrblController(mgc);
    instance.openCommPort("blah", 1234);
    instance.rawResponseHandler("Grbl 0.8c");
    // $G and $$ get queued on startup
    assertEquals(2, mgc.numQueueStringForCommCalls);
    assertEquals(2, mgc.numStreamCommandsCalls);
    // By default nothing is streaming.
    Boolean expResult = false;
    Boolean result = instance.isStreaming();
    assertEquals(expResult, result);
    // Test begining stream with no data to stream.
    expResult = false;
    boolean threwException = false;
    try {
        // instance.openCommPort("blah", 123);
        instance.beginStreaming();
    } catch (Exception ex) {
        assertEquals("There are no commands queued for streaming.", ex.getMessage());
        threwException = true;
    }
    assertTrue(threwException);
    result = instance.isStreaming();
    assertEquals(expResult, result);
    GcodeCommand cmd = instance.createCommand("G0X1");
    instance.queueCommand(cmd);
    try {
        instance.beginStreaming();
    } catch (Exception ex) {
        fail("Unexpected exception from GrblController: " + ex.getMessage());
    }
    result = instance.isStreaming();
    expResult = true;
    assertEquals(expResult, result);
    assertEquals(3, mgc.numQueueStringForCommCalls);
    assertEquals(3, mgc.numStreamCommandsCalls);
    // Wrap up streaming and make sure isStreaming switches back.
    // Whitespace removed.
    GcodeCommand command = new GcodeCommand("G0X1");
    command.setSent(true);
    command.setResponse("ok");
    try {
        instance.commandSent(command);
        instance.commandComplete(command.getCommandString());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Unexpected exception from command complete: " + ex.getMessage());
    }
    result = instance.isStreaming();
    expResult = false;
    assertEquals(expResult, result);
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) IOException(java.io.IOException) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 24 with GcodeCommand

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

the class GrblControllerTest method testRowsAsteriskMethods.

/**
 * Test of rowsInSend method, of class GrblController.
 */
@Test
public void testRowsAsteriskMethods() throws Exception {
    System.out.println("testRowsAsteriskMethods");
    GrblController instance = new GrblController(mgc);
    instance.openCommPort("blah", 1234);
    instance.rawResponseHandler("Grbl 0.8c");
    // Test 1.
    // When not sending, no commands queues, everything should be zero.
    assertCounts(instance, 0, 0, 0);
    // Add 30 commands.
    for (int i = 0; i < 30; i++) {
        instance.queueCommand(instance.createCommand("G0X" + i));
    }
    try {
        // instance.openCommPort("blah", 123);
        instance.beginStreaming();
        mgc.areActiveCommands = true;
    } catch (Exception ex) {
        fail("Unexpected exception from GrblController: " + ex.getMessage());
    }
    // Test 2.
    // 30 Commands queued, zero sent, 30 completed.
    assertCounts(instance, 30, 0, 30);
    // Sent 15 of them, none completed.
    try {
        for (int i = 0; i < 15; i++) {
            GcodeCommand command = new GcodeCommand("G0 X1");
            command.setSent(true);
            command.setResponse("ok");
            instance.commandSent(command);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Unexpected exception from command sent: " + ex.getMessage());
    }
    assertCounts(instance, 30, 15, 30);
    // Complete 15 of them.
    try {
        for (int i = 0; i < 15; i++) {
            // Whitespace removed.
            GcodeCommand command = new GcodeCommand("G0X1");
            command.setSent(true);
            command.setResponse("ok");
            instance.commandComplete(command.getCommandString());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Unexpected exception from command complete: " + ex.getMessage());
    }
    assertCounts(instance, 30, 15, 15);
    // Finish sending/completing the remaining 15 commands.
    try {
        for (int i = 0; i < 15; i++) {
            GcodeCommand command = new GcodeCommand("G0 X1");
            command.setSent(true);
            command.setResponse("ok");
            instance.commandSent(command);
            instance.commandComplete(command.getCommandString());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Unexpected exception from command complete: " + ex.getMessage());
    }
    mgc.areActiveCommands = false;
    assertCounts(instance, 30, 30, 0);
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) IOException(java.io.IOException) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 25 with GcodeCommand

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

the class GrblController method jogMachine.

@Override
public void jogMachine(int dirX, int dirY, int dirZ, double stepSize, double feedRate, Units units) throws Exception {
    if (capabilities.hasCapability(GrblCapabilitiesConstants.HARDWARE_JOGGING)) {
        // Format step size from spinner.
        String formattedStepSize = Utils.formatter.format(stepSize);
        String formattedFeedRate = Utils.formatter.format(feedRate);
        String commandString = GcodeUtils.generateXYZ("G91", units, formattedStepSize, formattedFeedRate, dirX, dirY, dirZ);
        GcodeCommand command = createCommand("$J=" + commandString);
        sendCommandImmediately(command);
    } else {
        super.jogMachine(dirX, dirY, dirZ, stepSize, feedRate, units);
    }
}
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