use of com.willwinder.universalgcodesender.listeners.ControllerListener in project Universal-G-Code-Sender by winder.
the class GUIBackend method connect.
@Override
public void connect(String firmware, String port, int baudRate) throws Exception {
logger.log(Level.INFO, "Connecting to {0} on port {1}", new Object[] { firmware, port });
updateWithFirmware(firmware);
this.controller = fetchControllerFromFirmware(firmware);
applySettings(settings);
this.controller.addListener(this);
for (ControllerListener l : controllerListeners) {
this.controller.addListener(l);
}
this.controller.getFirmwareSettings().addListener(this);
if (openCommConnection(port, baudRate)) {
// reset
streamFailed = false;
}
}
use of com.willwinder.universalgcodesender.listeners.ControllerListener in project Universal-G-Code-Sender by winder.
the class GrblControllerTest method errorInCheckModeSending.
@Test
public void errorInCheckModeSending() throws Exception {
// Given
AbstractCommunicator communicator = mock(AbstractCommunicator.class);
ControllerListener controllerListener = mock(ControllerListener.class);
GrblController gc = new GrblController(communicator);
gc.addListener(controllerListener);
// We will assume that we are using version Grbl 1.0 with streaming support
gc.rawResponseHandler("Grbl 1.1f");
gc.rawResponseHandler("<Check|MPos:0.000,0.000,0.000|FS:0,0|Pn:XYZ>");
doReturn(true).when(communicator).isCommOpen();
// When
gc.queueCommand(new GcodeCommand("G0 X10"));
gc.beginStreaming();
gc.communicatorPausedOnError();
gc.rawResponseHandler("error:1");
// Then
assertEquals(gc.getControlState(), COMM_CHECK);
assertFalse(gc.isPaused());
verify(communicator, times(1)).sendByteImmediately(GRBL_PAUSE_COMMAND);
verify(controllerListener, times(1)).controlStateChange(COMM_SENDING_PAUSED);
}
use of com.willwinder.universalgcodesender.listeners.ControllerListener in project Universal-G-Code-Sender by winder.
the class GrblControllerTest method rawResponseHandlerOnErrorWithNoSentCommandsShouldSendMessageToConsole.
@Test
public void rawResponseHandlerOnErrorWithNoSentCommandsShouldSendMessageToConsole() throws Exception {
// Given
GrblController instance = new GrblController(mgc);
instance.setDistanceModeCode("G90");
instance.setUnitsCode("G21");
instance.openCommPort("foo", 2400);
ControllerListener controllerListener = mock(ControllerListener.class);
instance.addListener(controllerListener);
// When
instance.rawResponseHandler("error:1");
// Then
String genericErrorMessage = "An unexpected error was detected: (error:1) G-code words consist of a letter and a value. Letter was not found.\n";
verify(controllerListener, times(1)).messageForConsole(ControllerListener.MessageType.ERROR, genericErrorMessage);
verify(controllerListener, times(1)).messageForConsole(any(), anyString());
instance.removeListener(controllerListener);
assertFalse(instance.getActiveCommand().isPresent());
}
use of com.willwinder.universalgcodesender.listeners.ControllerListener in project Universal-G-Code-Sender by winder.
the class GrblControllerTest method testAddListener.
/**
* Test of addListener method, of class GrblController.
*/
@Test
public void testAddListener() {
System.out.println("addListener");
ControllerListener cl = null;
GrblController instance = new GrblController(mgc);
instance.addListener(cl);
// TODO: Test that (multiple?) listener events work.
}
use of com.willwinder.universalgcodesender.listeners.ControllerListener in project Universal-G-Code-Sender by winder.
the class GrblControllerTest method rawResponseHandlerWithKnownErrorShouldWriteMessageToConsole.
@Test
public void rawResponseHandlerWithKnownErrorShouldWriteMessageToConsole() throws Exception {
// Given
GrblController instance = new GrblController(mgc);
instance.setDistanceModeCode("G90");
instance.setUnitsCode("G21");
instance.openCommPort("foo", 2400);
instance.commandSent(new GcodeCommand("G0"));
ControllerListener controllerListener = mock(ControllerListener.class);
instance.addListener(controllerListener);
// When
instance.rawResponseHandler("error:1");
// Then
String genericErrorMessage = "Error while processing response <error:1>\n";
verify(controllerListener, times(0)).messageForConsole(ControllerListener.MessageType.ERROR, genericErrorMessage);
String errorMessage = "An error was detected while sending 'G0': (error:1) G-code words consist of a letter and a value. Letter was not found. Streaming has been paused.\n";
verify(controllerListener).messageForConsole(ControllerListener.MessageType.ERROR, errorMessage);
verify(controllerListener, times(1)).messageForConsole(any(), anyString());
instance.removeListener(controllerListener);
assertFalse(instance.getActiveCommand().isPresent());
}
Aggregations