Search in sources :

Example 1 with GcodeStreamWriter

use of com.willwinder.universalgcodesender.utils.GcodeStreamWriter in project Universal-G-Code-Sender by winder.

the class GcodeParserUtils method processAndExportText.

/**
 * Attempts to read the input file in gcode-text format.
 * @return whether or not we succeed processing the file.
 */
private static void processAndExportText(GcodeParser gcp, BufferedReader input, File output) throws IOException, GcodeParserException {
    // Preprocess a regular gcode file.
    try (BufferedReader br = input) {
        try (GcodeStreamWriter gsw = new GcodeStreamWriter(output)) {
            int i = 0;
            for (String line; (line = br.readLine()) != null; ) {
                i++;
                String comment = GcodePreprocessorUtils.parseComment(line);
                String commentRemoved = GcodePreprocessorUtils.removeComment(line);
                write(gcp, gsw, line, commentRemoved, comment, i);
            }
        }
    }
}
Also used : GcodeStreamWriter(com.willwinder.universalgcodesender.utils.GcodeStreamWriter) BufferedReader(java.io.BufferedReader)

Example 2 with GcodeStreamWriter

use of com.willwinder.universalgcodesender.utils.GcodeStreamWriter in project Universal-G-Code-Sender by winder.

the class GrblControllerTest method controllerShouldHaveStateRunningWhenStreamingAndInCheckMode.

@Test
public void controllerShouldHaveStateRunningWhenStreamingAndInCheckMode() throws Exception {
    // Given
    GrblController instance = new GrblController(mgc);
    instance.setDistanceModeCode("G90");
    instance.setUnitsCode("G21");
    instance.openCommPort("foo", 2400);
    // We will assume that we are using version Grbl 1.0 with streaming support
    instance.rawResponseHandler("Grbl 1.1f");
    instance.rawResponseHandler("<Check|MPos:0.000,0.000,0.000|FS:0,0|Pn:XYZ>");
    assertTrue(instance.isIdle());
    // Create a gcode file stream
    File gcodeFile = new File(tempDir, "gcodeFile");
    GcodeStreamWriter gcodeStreamWriter = new GcodeStreamWriter(gcodeFile);
    gcodeStreamWriter.addLine("G0", "G0", null, 0);
    gcodeStreamWriter.addLine("G0", "G0", null, 0);
    gcodeStreamWriter.close();
    // When
    instance.queueStream(new GcodeStreamReader(gcodeFile));
    instance.beginStreaming();
    // Then
    assertFalse(instance.isIdle());
    assertFalse(instance.isPaused());
    assertEquals(COMM_SENDING, instance.getControlState());
}
Also used : GcodeStreamWriter(com.willwinder.universalgcodesender.utils.GcodeStreamWriter) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) File(java.io.File) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 3 with GcodeStreamWriter

use of com.willwinder.universalgcodesender.utils.GcodeStreamWriter in project Universal-G-Code-Sender by winder.

the class AbstractControllerTest method testQueueStreamForComm.

/**
 * Test of queueStream method, of class AbstractController.
 */
@Test
public void testQueueStreamForComm() throws Exception {
    System.out.println("queueStream");
    String command = "command";
    Collection<String> commands = Arrays.asList(command, command);
    String port = "/some/port";
    int rate = 1234;
    File f = new File(tempDir, "gcodeFile");
    try {
        try (GcodeStreamWriter gsw = new GcodeStreamWriter(f)) {
            for (String i : commands) {
                gsw.addLine("blah", command, null, -1);
            }
        }
        try (GcodeStreamReader gsr = new GcodeStreamReader(f)) {
            openInstanceExpectUtility(port, rate, false);
            streamInstanceExpectUtility();
            // TODO Fix this
            // Making sure the commands get queued.
            mockCommunicator.queueStreamForComm(gsr);
            EasyMock.expect(EasyMock.expectLastCall()).times(1);
            EasyMock.replay(instance, mockCommunicator);
            // Open port, send some commands, make sure they are streamed.
            instance.openCommPort(port, rate);
            instance.queueStream(gsr);
            instance.beginStreaming();
        }
        EasyMock.verify(mockCommunicator, instance);
    } finally {
        FileUtils.forceDelete(f);
    }
}
Also used : GcodeStreamWriter(com.willwinder.universalgcodesender.utils.GcodeStreamWriter) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) EasyMock.anyString(org.easymock.EasyMock.anyString) File(java.io.File) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 4 with GcodeStreamWriter

use of com.willwinder.universalgcodesender.utils.GcodeStreamWriter in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method responseMessageOnErrorOnLastCommandStreamShouldNotPauseTheCommunicator.

@Test
public void responseMessageOnErrorOnLastCommandStreamShouldNotPauseTheCommunicator() throws IOException, GcodeStreamReader.NotGcodeStreamFile {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    // Create a gcode file stream
    File gcodeFile = new File(tempDir, "gcodeFile");
    GcodeStreamWriter gcodeStreamWriter = new GcodeStreamWriter(gcodeFile);
    gcodeStreamWriter.addLine("G0", "G0", null, 0);
    gcodeStreamWriter.close();
    // Stream
    instance.queueStreamForComm(new GcodeStreamReader(gcodeFile));
    instance.streamCommands();
    // When
    instance.responseMessage("error");
    // Then
    assertFalse(instance.isPaused());
}
Also used : GcodeStreamWriter(com.willwinder.universalgcodesender.utils.GcodeStreamWriter) Connection(com.willwinder.universalgcodesender.connection.Connection) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) File(java.io.File) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 5 with GcodeStreamWriter

use of com.willwinder.universalgcodesender.utils.GcodeStreamWriter in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method testStreamCommandsOrderStringCommandsFirst.

@Test
public void testStreamCommandsOrderStringCommandsFirst() throws Exception {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    ArgumentCaptor<String> commandCaptor = ArgumentCaptor.forClass(String.class);
    doNothing().when(connection).sendStringToComm(commandCaptor.capture());
    // Create a gcode file stream
    File gcodeFile = new File(tempDir, "gcodeFile");
    GcodeStreamWriter gcodeStreamWriter = new GcodeStreamWriter(gcodeFile);
    gcodeStreamWriter.addLine("G0", "G0", null, 0);
    gcodeStreamWriter.close();
    instance.queueStreamForComm(new GcodeStreamReader(gcodeFile));
    instance.queueStringForComm("G1");
    // When
    instance.streamCommands();
    // Then
    assertEquals(2, commandCaptor.getAllValues().size());
    assertEquals("The first command processed should be the string command", "G1\n", commandCaptor.getAllValues().get(0));
    assertEquals("The second command should be from the stream", "G0\n", commandCaptor.getAllValues().get(1));
}
Also used : GcodeStreamWriter(com.willwinder.universalgcodesender.utils.GcodeStreamWriter) Connection(com.willwinder.universalgcodesender.connection.Connection) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) File(java.io.File) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Aggregations

GcodeStreamWriter (com.willwinder.universalgcodesender.utils.GcodeStreamWriter)8 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)7 GcodeStreamTest (com.willwinder.universalgcodesender.utils.GcodeStreamTest)6 File (java.io.File)6 Test (org.junit.Test)6 Connection (com.willwinder.universalgcodesender.connection.Connection)3 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)1 BufferedReader (java.io.BufferedReader)1 EasyMock.anyString (org.easymock.EasyMock.anyString)1