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();
}
}
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);
}
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());
}
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);
}
}
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());
}
Aggregations