use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class GcodeCommandBuffer method appendCommandString.
public GcodeCommand appendCommandString(String commandString) {
GcodeCommand command = new GcodeCommand(commandString);
command.setCommandNumber(this.numCommands++);
this.commandQueue.add(command);
// Preload first command, or next command if the first batch finished.
if (this.currentCommand == null || this.currentCommand.isSent()) {
this.nextCommand();
}
return command;
}
use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class GUIBackendTest method sendGcodeCommandWhenConnectedShouldBeOk.
@Test
public void sendGcodeCommandWhenConnectedShouldBeOk() throws Exception {
// Given
instance.connect(FIRMWARE, PORT, BAUD_RATE);
when(controller.isCommOpen()).thenReturn(true);
GcodeCommand gcodeCommand = new GcodeCommand("G00");
when(controller.createCommand(any())).thenReturn(gcodeCommand);
// When
instance.sendGcodeCommand("G00");
// Then
verify(controller, times(1)).sendCommandImmediately(any());
verify(controller, times(1)).sendCommandImmediately(gcodeCommand);
verify(controller, times(0)).restoreParserModalState();
}
use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class GUIBackendTest method sendGcodeCommandWhenNotConnectedShouldThrowException.
@Test(expected = Exception.class)
public void sendGcodeCommandWhenNotConnectedShouldThrowException() throws Exception {
// Given
instance.connect(FIRMWARE, PORT, BAUD_RATE);
when(controller.isCommOpen()).thenReturn(false);
GcodeCommand gcodeCommand = new GcodeCommand("G00");
when(controller.createCommand(any())).thenReturn(gcodeCommand);
// When
instance.sendGcodeCommand("G00");
}
use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class GcodeStreamTest method testGcodeStreamReadWrite.
/**
* Writes 1,000,000 rows to a file then reads it back out.
*/
@Test
public void testGcodeStreamReadWrite() throws FileNotFoundException, IOException, GcodeStreamReader.NotGcodeStreamFile {
int rows = 1000000;
File f = new File(tempDir, "gcodeFile");
try {
try (GcodeStreamWriter gsw = new GcodeStreamWriter(f)) {
for (int i = 0; i < rows; i++) {
gsw.addLine("Line " + i + " before", "Line " + i + " after", null, i);
}
}
try (GcodeStreamReader gsr = new GcodeStreamReader(f)) {
Assert.assertEquals(rows, gsr.getNumRows());
int count = 0;
while (gsr.getNumRowsRemaining() > 0) {
GcodeCommand gc = gsr.getNextCommand();
Assert.assertEquals("Line " + count + " after", gc.getCommandString());
Assert.assertEquals("", gc.getComment());
Assert.assertEquals(count, gc.getCommandNumber());
count++;
Assert.assertEquals(rows - count, gsr.getNumRowsRemaining());
}
Assert.assertEquals(rows, count);
}
} finally {
FileUtils.forceDelete(f);
}
}
use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class GrblCommunicatorTest method testStreamCommands.
/**
* Test of sendStringToComm method, of class GrblCommunicator.
*/
@Test
public void testStreamCommands() {
System.out.println("streamCommands");
MockConnection mc = new MockConnection(mg.in, mg.out);
GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);
String term = "\n";
String thirtyNineCharString = "thirty-nine character command here.....";
boolean result;
boolean expResult;
// Make sure CommUtil is still an overly cautious jerk.
LinkedList<GcodeCommand> l = new LinkedList<>();
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);
// Add a bunch of commands so that the buffer is full.
// 39*3 + 3 newlines + 3 CommUtils caution = 123 == buffer size.
instance.queueStringForComm(thirtyNineCharString);
instance.queueStringForComm(thirtyNineCharString);
instance.queueStringForComm(thirtyNineCharString);
// Stream them so that there are active commands.
instance.streamCommands();
expResult = true;
result = instance.areActiveCommands();
assertEquals(expResult, result);
// Add another command and stream it so that something is queued.
instance.queueStringForComm(thirtyNineCharString);
instance.streamCommands();
expResult = true;
result = instance.areActiveCommands();
assertEquals(expResult, result);
// Check with MockGrbl to verify the fourth command wasn't sent.
String output = mg.readStringFromGrblBuffer();
String goal = thirtyNineCharString + term + thirtyNineCharString + term + thirtyNineCharString + term;
assertEquals(goal, output);
// Make room for the next command.
mc.sendResponse("ok");
// Send it.
instance.streamCommands();
// Make sure the queued command was sent.
output = mg.readStringFromGrblBuffer();
assertEquals(thirtyNineCharString + term, output);
// Wrap up.
mc.sendResponse("ok");
mc.sendResponse("ok");
mc.sendResponse("ok");
expResult = false;
result = instance.areActiveCommands();
assertEquals(expResult, result);
}
Aggregations