Search in sources :

Example 1 with GcodeStreamReader

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

the class MainWindow method UGSEvent.

@Override
public void UGSEvent(UGSEvent evt) {
    if (evt.isFileChangeEvent() || evt.isStateChangeEvent()) {
        this.updateControls();
    }
    if (evt.isFileChangeEvent()) {
        switch(evt.getFileState()) {
            case FILE_LOADING:
                File f = backend.getGcodeFile();
                fileModePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(Localization.getString("mainWindow.swing.fileLabel") + ": " + backend.getGcodeFile().getName()));
                fileModePanel.setToolTipText(backend.getGcodeFile().getAbsolutePath());
                processedGcodeFile = null;
                gcodeFile = evt.getFile();
                break;
            case FILE_LOADED:
                processedGcodeFile = evt.getFile();
                try {
                    try (GcodeStreamReader gsr = new GcodeStreamReader(backend.getProcessedGcodeFile())) {
                        resetSentRowLabels(gsr.getNumRows());
                    }
                } catch (IOException | GcodeStreamReader.NotGcodeStreamFile ex) {
                }
                break;
            default:
                break;
        }
        setVisualizerFile();
    }
}
Also used : GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) IOException(java.io.IOException) File(java.io.File)

Example 2 with GcodeStreamReader

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

the class SendStatusPanel method resetSentRowLabels.

private void resetSentRowLabels() {
    long numRows = 0;
    if (backend.getProcessedGcodeFile() != null) {
        try {
            try (GcodeStreamReader gsr = new GcodeStreamReader(backend.getProcessedGcodeFile())) {
                numRows = gsr.getNumRows();
                System.out.println("NUM ROWS: " + numRows);
            }
        } catch (GcodeStreamReader.NotGcodeStreamFile | IOException ex) {
        }
    }
    // Reset labels
    String totalRows = String.valueOf(numRows);
    resetTimerLabels();
    this.sentRowsValue.setText("0");
    this.remainingRowsValue.setText(totalRows);
    this.rowsValue.setText(totalRows);
}
Also used : GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) IOException(java.io.IOException)

Example 3 with GcodeStreamReader

use of com.willwinder.universalgcodesender.utils.GcodeStreamReader 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 4 with GcodeStreamReader

use of com.willwinder.universalgcodesender.utils.GcodeStreamReader 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 5 with GcodeStreamReader

use of com.willwinder.universalgcodesender.utils.GcodeStreamReader 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)

Aggregations

GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)15 File (java.io.File)11 Test (org.junit.Test)9 GcodeStreamWriter (com.willwinder.universalgcodesender.utils.GcodeStreamWriter)7 GcodeStreamTest (com.willwinder.universalgcodesender.utils.GcodeStreamTest)6 IOException (java.io.IOException)6 Connection (com.willwinder.universalgcodesender.connection.Connection)3 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)3 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)3 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)3 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)2 Position (com.willwinder.universalgcodesender.model.Position)2 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)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 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)1 GcodeViewParse (com.willwinder.universalgcodesender.visualizer.GcodeViewParse)1 BufferedReader (java.io.BufferedReader)1