use of com.willwinder.universalgcodesender.utils.GcodeStreamWriter in project Universal-G-Code-Sender by winder.
the class BufferedCommunicatorTest method testSimpleStreamStream.
@Test
public void testSimpleStreamStream() throws Exception {
String[] inputs = { "input1", "input2" };
for (String i : inputs) {
mockScl.messageForConsole(EasyMock.anyString());
EasyMock.expect(EasyMock.expectLastCall());
mockConnection.sendStringToComm(i + "\n");
EasyMock.expect(EasyMock.expectLastCall());
mockScl.commandSent(EasyMock.<GcodeCommand>anyObject());
EasyMock.expect(EasyMock.expectLastCall());
}
EasyMock.replay(mockConnection, mockScl);
File f = new File(tempDir, "gcodeFile");
try (GcodeStreamWriter gsw = new GcodeStreamWriter(f)) {
for (String i : inputs) {
gsw.addLine("blah", i, null, -1);
}
}
GcodeStreamReader gsr = new GcodeStreamReader(f);
instance.queueStreamForComm(gsr);
instance.streamCommands();
assertEquals("input1, input2, 0 streaming commands.", instance.activeCommandSummary());
EasyMock.verify(mockConnection, mockScl);
}
use of com.willwinder.universalgcodesender.utils.GcodeStreamWriter in project Universal-G-Code-Sender by winder.
the class BufferedCommunicatorTest method responseMessageOnErrorOnCommandStreamShouldPauseTheCommunicator.
@Test
public void responseMessageOnErrorOnCommandStreamShouldPauseTheCommunicator() 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.addLine("G0", "G0", null, 0);
gcodeStreamWriter.close();
// Stream
instance.queueStreamForComm(new GcodeStreamReader(gcodeFile));
instance.streamCommands();
// When
instance.responseMessage("error");
// Then
assertTrue(instance.isPaused());
}
use of com.willwinder.universalgcodesender.utils.GcodeStreamWriter in project Universal-G-Code-Sender by winder.
the class GcodeParserUtils method processAndExportGcodeStream.
/**
* Attempts to read the input file in GcodeStream format.
* @return whether or not we succeed processing the file.
*/
private static boolean processAndExportGcodeStream(GcodeParser gcp, BufferedReader input, File output) throws IOException, GcodeParserException {
// Preprocess a GcodeStream file.
try {
GcodeStreamReader gsr = new GcodeStreamReader(input);
try (GcodeStreamWriter gsw = new GcodeStreamWriter(output)) {
int i = 0;
while (gsr.getNumRowsRemaining() > 0) {
i++;
GcodeCommand gc = gsr.getNextCommand();
write(gcp, gsw, gc.getOriginalCommandString(), gc.getCommandString(), gc.getComment(), i);
}
// Done processing GcodeStream file.
return true;
}
} catch (GcodeStreamReader.NotGcodeStreamFile ex) {
// File exists, but isn't a stream reader. So go ahead and try parsing it as a raw gcode file.
}
return false;
}
Aggregations