Package com.willwinder.universalgcodesender.types

Examples of com.willwinder.universalgcodesender.types.GcodeCommand


        assertEquals(expResult, result);
        assertEquals(1, mgc.numQueueStringForCommCalls);
        assertEquals(1, mgc.numStreamCommandsCalls);
   
        // Wrap up streaming and make sure isStreaming switches back.
        GcodeCommand command = new GcodeCommand("G0X1"); // Whitespace removed.
        command.setSent(true);
        command.setResponse("ok");
        try {
            instance.commandSent(command.getCommandString());
            instance.commandComplete(command.getCommandString());
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception from command complete: " + ex.getMessage());
        }
        result = instance.isStreamingFile();
View Full Code Here


            fail("Unexpected exception from Thread.sleep: " + ex.getMessage());
        }

        // Test 3.
        // Wrap up the send and check the duration.
        GcodeCommand command = new GcodeCommand("G0X1"); // Whitespace removed.
        command.setSent(true);
        command.setResponse("ok");
        try {
            instance.commandSent(command.getCommandString());
            instance.commandComplete(command.getCommandString());
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception from command complete: " + ex.getMessage());
        }
View Full Code Here

       
        // Test 3.
        // 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.getCommandString());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception from command sent: " + ex.getMessage());
        }
        expResult = 30;
        result = instance.rowsInSend();
        assertEquals(expResult, result);
        expResult = 15;
        result = instance.rowsSent();
        assertEquals(expResult, result);
        expResult = 30;
        result = instance.rowsRemaining();
        assertEquals(expResult, result);
       
        // Test 4.
        // Complete 15 of them.
        try {
            for (int i=0; i < 15; i++) {
                GcodeCommand command = new GcodeCommand("G0X1"); // Whitespace removed.
                command.setSent(true);
                command.setResponse("ok");
                instance.commandComplete(command.getCommandString());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception from command complete: " + ex.getMessage());
        }
        expResult = 30;
        result = instance.rowsInSend();
        assertEquals(expResult, result);
        expResult = 15;
        result = instance.rowsSent();
        assertEquals(expResult, result);
        expResult = 15;
        result = instance.rowsRemaining();
        assertEquals(expResult, result);
       
        // Test 5.
        // 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.getCommandString());
                instance.commandComplete(command.getCommandString());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception from command complete: " + ex.getMessage());
        }
View Full Code Here

            assertEquals("Cannot stream while there are active commands (controller).", ex.getMessage());
        }
        assertEquals(1, mgc.numQueueStringForCommCalls);
        assertEquals(true, check);
        // Wrap up test 2.
        GcodeCommand command = new GcodeCommand("G0X1"); // Whitespace removed.
        command.setSent(true);
        command.setResponse("ok");
        instance.commandSent(command.getCommandString());
        instance.commandComplete(command.getCommandString());
       
        // Test 3. Stream some commands and make sure they get sent.
        for (int i=0; i < 30; i++) {
            instance.preprocessAndAppendGcodeCommand("G0X" + i);
        }
        try {
            instance.beginStreaming();
        } catch (Exception ex) {
            fail("Unexpected exception in GrblController: " + ex.getMessage());
        }
        assertEquals(30, instance.rowsRemaining());
        assertEquals(31, mgc.numQueueStringForCommCalls);
        // Wrap up test 3.
        for (int i=0; i < 30; i++) {
            command.setCommand("G0X" + i);
            instance.commandSent(command.getCommandString());
            instance.commandComplete(command.getCommandString());
        }

        // Test 4. Commands being sent are properly preprocessed.
        instance.setSpeedOverride(1000.0);
        instance.setRemoveAllWhitespace(true);
        instance.preprocessAndAppendGcodeCommand("G0 X1 Y1 Z1 F100");
        try {
            // Start the stream.
            instance.beginStreaming();
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception in GrblController: " + ex.getMessage());
        }
        assertEquals(32, mgc.numQueueStringForCommCalls);
        assertEquals("G0X1Y1Z1F1000.0", mgc.queuedString.trim());
        // Wrap up test 4.
        command.setCommand("G0X1Y1Z1F1000.0");
        instance.commandSent(command.getCommandString());
        instance.commandComplete(command.getCommandString());

    }
View Full Code Here

            instance.preprocessAndAppendGcodeCommand("G0 X" + i);
        }
        try {
            instance.beginStreaming();
            for (int i=0; i < 15; i++) {
                GcodeCommand command = new GcodeCommand("G0 X1");
                command.setSent(true);
                command.setResponse("ok");
                instance.commandSent(command.getCommandString());
            }
        } catch (Exception ex) {
            fail("Unexpected exception from command sent: " + ex.getMessage());
        }
        instance.cancelSend();
        assertEquals(30, instance.rowsInSend());
        assertEquals(30, instance.rowsRemaining());
        // wrap up
        try {
            GcodeCommand command = new GcodeCommand("blah");
            command.setSent(true);
            command.setResponse("ok");
            for (int i=0; i < 15; i++) {
                instance.commandComplete(command.getCommandString());
            }
        } catch (Exception ex) {
            fail("Unexpected exception testing cancelSend: " + ex.getMessage());
        }
       
        // Test 3.2
        // Add 30 commands, start send, cancel after sending 15. (Grbl 0.8c)
        instance.rawResponseHandler("Grbl 0.8c");
        for (int i=0; i < 30; i++) {
            instance.preprocessAndAppendGcodeCommand("G0 X" + i);
        }
        try {
            instance.beginStreaming();
            for (int i=0; i < 15; i++) {
                GcodeCommand command = new GcodeCommand("G0 X1");
                command.setSent(true);
                command.setResponse("ok");
                instance.commandSent(command.getCommandString());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception from command sent: " + ex.getMessage());
        }
View Full Code Here

            instance.preprocessAndAppendGcodeCommand("G0 X" + i);
        }
        try {
            instance.beginStreaming();
            for (int i=0; i < 15; i++) {
                GcodeCommand command = new GcodeCommand("G0 X1");
                command.setSent(true);
                command.setResponse("ok");
                instance.commandSent(command.getCommandString());
            }
        } catch (Exception ex) {
            fail("Unexpected exception from command sent: " + ex.getMessage());
        }
        instance.cancelSend();
        assertEquals(30, instance.rowsInSend());
        assertEquals(15, instance.rowsRemaining());
        // wrap up
        try {
            GcodeCommand command = new GcodeCommand("blah");
            command.setSent(true);
            command.setResponse("ok");
            for (int i=0; i < 15; i++) {
                instance.commandComplete(command.getCommandString());
            }
        } catch (Exception ex) {
            fail("Unexpected exception testing cancelSend: " + ex.getMessage());
        }
       
        // Test 3.2
        // Add 30 commands, start send, cancel after sending 15. (Grbl 0.8c)
        instance.rawResponseHandler("Grbl 0.8c");
        for (int i=0; i < 30; i++) {
            instance.preprocessAndAppendGcodeCommand("G0 X" + i);
        }
        try {
            instance.beginStreaming();
            for (int i=0; i < 15; i++) {
                GcodeCommand command = new GcodeCommand("G0 X1");
                command.setSent(true);
                command.setResponse("ok");
                instance.commandSent(command.getCommandString());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception from command sent: " + ex.getMessage());
        }
View Full Code Here

     * Test of commandSent method, of class GrblController.
     */
    @Test
    public void testCommandSent() {
        System.out.println("commandSent");
        GcodeCommand command = new GcodeCommand("G0X1");
        GrblController instance = new GrblController(mgc);
       
        // Test 1. Sending command when none are queued.
        boolean hitException = false;
        try {
            instance.commandSent(command.getCommandString());
        } catch (NoSuchElementException e) {
            hitException = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
View Full Code Here

     * Test of commandComplete method, of class GrblController.
     */
    @Test
    public void testCommandComplete() {
        System.out.println("commandComplete");
        GcodeCommand command = null;
        GrblController instance = new GrblController(mgc);
       
        // Test 1. Complete a command that was marked as sent but never declared
        //         within commandSent(command).
        command = new GcodeCommand("blah");
        command.setSent(true);
        boolean hitException = false;
        try {
            instance.commandComplete(command.getCommandString());
        } catch (Exception ex) {
            hitException = true;
            System.out.println("Exception: " + ex.getMessage());
            assert(ex.getMessage().startsWith(
                    "Attempting to complete a command that doesn't exist: <"));
View Full Code Here

        boolean result;
        boolean expResult;
       
        // Make sure CommUtil is still an overly cautious jerk.
        LinkedList<GcodeCommand> l = new LinkedList<GcodeCommand>();
        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);
View Full Code Here

     */
    @Test
    public void testCheckRoomInBuffer() {
        System.out.println("checkRoomInBuffer");

        GcodeCommand nextCommand;
        Boolean expResult;
        Boolean result;

        List<GcodeCommand> list = new LinkedList<GcodeCommand>();
        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);
        expResult = true;
        assertEquals(expResult, result);
       
        biggestString.append('.');
        nextCommand = new GcodeCommand(biggestString.toString(), 5);

        expResult = false;
        result = CommUtils.checkRoomInBuffer(list, nextCommand);
        assertEquals(expResult, result);
    }
View Full Code Here

TOP

Related Classes of com.willwinder.universalgcodesender.types.GcodeCommand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.