use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class CommUtilsTest method testCheckRoomInBuffer.
/**
* Test of checkRoomInBuffer method, of class CommUtils.
*/
@Test
public void testCheckRoomInBuffer() {
System.out.println("checkRoomInBuffer");
GcodeCommand nextCommand;
Boolean expResult;
Boolean result;
List<GcodeCommand> list = new LinkedList<>();
list.add(new GcodeCommand("twenty characters...", 0));
list.add(new GcodeCommand("twenty characters...", 1));
list.add(new GcodeCommand("twenty characters...", 2));
list.add(new GcodeCommand("twenty characters...", 3));
list.add(new GcodeCommand("twenty characters...", 4));
// 100 characters + 5 for newlines, 18 characters remaining in buffer.
StringBuilder biggestString = new StringBuilder();
for (int i = 0; i < (GrblUtils.GRBL_RX_BUFFER_SIZE - 105 - 1); i++) {
biggestString.append('.');
}
// This command should just barely fit.
nextCommand = new GcodeCommand(biggestString.toString(), 5);
result = CommUtils.checkRoomInBuffer(list, nextCommand, GrblUtils.GRBL_RX_BUFFER_SIZE);
expResult = true;
assertEquals(expResult, result);
biggestString.append('.');
nextCommand = new GcodeCommand(biggestString.toString(), 5);
expResult = false;
result = CommUtils.checkRoomInBuffer(list, nextCommand, GrblUtils.GRBL_RX_BUFFER_SIZE);
assertEquals(expResult, result);
}
use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class CommUtilsTest method testGetSizeOfBuffer.
/**
* Test of getSizeOfBuffer method, of class CommUtils.
*/
@Test
public void testGetSizeOfBuffer() {
System.out.println("getSizeOfBuffer");
List<GcodeCommand> list = new LinkedList<>();
list.add(new GcodeCommand("twenty characters...", 0));
list.add(new GcodeCommand("twenty characters...", 1));
list.add(new GcodeCommand("twenty characters...", 2));
list.add(new GcodeCommand("twenty characters...", 3));
list.add(new GcodeCommand("twenty characters...", 4));
// 100characters + 5 newlines.
int expResult = 105;
int result = CommUtils.getSizeOfBuffer(list);
assertEquals(expResult, result);
}
use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class GrblControllerTest method testIsStreaming.
/**
* Test of isStreamingmethod, of class GrblController.
*/
@Test
public void testIsStreaming() throws Exception {
System.out.println("isStreaming");
GrblController instance = new GrblController(mgc);
instance.openCommPort("blah", 1234);
instance.rawResponseHandler("Grbl 0.8c");
// $G and $$ get queued on startup
assertEquals(2, mgc.numQueueStringForCommCalls);
assertEquals(2, mgc.numStreamCommandsCalls);
// By default nothing is streaming.
Boolean expResult = false;
Boolean result = instance.isStreaming();
assertEquals(expResult, result);
// Test begining stream with no data to stream.
expResult = false;
boolean threwException = false;
try {
// instance.openCommPort("blah", 123);
instance.beginStreaming();
} catch (Exception ex) {
assertEquals("There are no commands queued for streaming.", ex.getMessage());
threwException = true;
}
assertTrue(threwException);
result = instance.isStreaming();
assertEquals(expResult, result);
GcodeCommand cmd = instance.createCommand("G0X1");
instance.queueCommand(cmd);
try {
instance.beginStreaming();
} catch (Exception ex) {
fail("Unexpected exception from GrblController: " + ex.getMessage());
}
result = instance.isStreaming();
expResult = true;
assertEquals(expResult, result);
assertEquals(3, mgc.numQueueStringForCommCalls);
assertEquals(3, mgc.numStreamCommandsCalls);
// Wrap up streaming and make sure isStreaming switches back.
// Whitespace removed.
GcodeCommand command = new GcodeCommand("G0X1");
command.setSent(true);
command.setResponse("ok");
try {
instance.commandSent(command);
instance.commandComplete(command.getCommandString());
} catch (Exception ex) {
ex.printStackTrace();
fail("Unexpected exception from command complete: " + ex.getMessage());
}
result = instance.isStreaming();
expResult = false;
assertEquals(expResult, result);
}
use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class GrblControllerTest method testRowsAsteriskMethods.
/**
* Test of rowsInSend method, of class GrblController.
*/
@Test
public void testRowsAsteriskMethods() throws Exception {
System.out.println("testRowsAsteriskMethods");
GrblController instance = new GrblController(mgc);
instance.openCommPort("blah", 1234);
instance.rawResponseHandler("Grbl 0.8c");
// Test 1.
// When not sending, no commands queues, everything should be zero.
assertCounts(instance, 0, 0, 0);
// Add 30 commands.
for (int i = 0; i < 30; i++) {
instance.queueCommand(instance.createCommand("G0X" + i));
}
try {
// instance.openCommPort("blah", 123);
instance.beginStreaming();
mgc.areActiveCommands = true;
} catch (Exception ex) {
fail("Unexpected exception from GrblController: " + ex.getMessage());
}
// Test 2.
// 30 Commands queued, zero sent, 30 completed.
assertCounts(instance, 30, 0, 30);
// Sent 15 of them, none completed.
try {
for (int i = 0; i < 15; i++) {
GcodeCommand command = new GcodeCommand("G0 X1");
command.setSent(true);
command.setResponse("ok");
instance.commandSent(command);
}
} catch (Exception ex) {
ex.printStackTrace();
fail("Unexpected exception from command sent: " + ex.getMessage());
}
assertCounts(instance, 30, 15, 30);
// Complete 15 of them.
try {
for (int i = 0; i < 15; i++) {
// Whitespace removed.
GcodeCommand command = new GcodeCommand("G0X1");
command.setSent(true);
command.setResponse("ok");
instance.commandComplete(command.getCommandString());
}
} catch (Exception ex) {
ex.printStackTrace();
fail("Unexpected exception from command complete: " + ex.getMessage());
}
assertCounts(instance, 30, 15, 15);
// Finish sending/completing the remaining 15 commands.
try {
for (int i = 0; i < 15; i++) {
GcodeCommand command = new GcodeCommand("G0 X1");
command.setSent(true);
command.setResponse("ok");
instance.commandSent(command);
instance.commandComplete(command.getCommandString());
}
} catch (Exception ex) {
ex.printStackTrace();
fail("Unexpected exception from command complete: " + ex.getMessage());
}
mgc.areActiveCommands = false;
assertCounts(instance, 30, 30, 0);
}
use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.
the class GrblController method jogMachine.
@Override
public void jogMachine(int dirX, int dirY, int dirZ, double stepSize, double feedRate, Units units) throws Exception {
if (capabilities.hasCapability(GrblCapabilitiesConstants.HARDWARE_JOGGING)) {
// Format step size from spinner.
String formattedStepSize = Utils.formatter.format(stepSize);
String formattedFeedRate = Utils.formatter.format(feedRate);
String commandString = GcodeUtils.generateXYZ("G91", units, formattedStepSize, formattedFeedRate, dirX, dirY, dirZ);
GcodeCommand command = createCommand("$J=" + commandString);
sendCommandImmediately(command);
} else {
super.jogMachine(dirX, dirY, dirZ, stepSize, feedRate, units);
}
}
Aggregations