Skip to content

Commit

Permalink
Adding a basic working unit test for GCODE devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed May 12, 2016
1 parent 1566923 commit 09c6a65
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ public void disconnectDeviceImp() {
}
outs=null;
}
if(serial.isConnected())
serial.disconnect();
}

@Override
public boolean connectDeviceImp() {
disconnectDeviceImp();
serial.connect();
if(!serial.connect()){
throw new RuntimeException("Failed to connect to the serial device");
}
ins=serial.getInputStream();
outs = serial.getOutputStream();

Expand All @@ -69,19 +73,19 @@ public ArrayList<String> getNamespacesImp() {
private String getLine(){
@SuppressWarnings("resource")
String ret=null;
synchronized(ins){
java.util.Scanner s = new java.util.Scanner(ins).useDelimiter("\\n");
//synchronized(ins){
java.util.Scanner s = new java.util.Scanner(ins).useDelimiter("\\A");
ret =s.hasNext() ? s.next() : "";
}
//}
return ret;
}

@Override
public String runLine(String line) {
try {
synchronized(outs){
//synchronized(outs){
outs.write(line.getBytes());
}
//}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
34 changes: 15 additions & 19 deletions test/java/src/junit/test/neuronrobotics/utilities/GCODETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.neuronrobotics.sdk.addons.kinematics.gcodebridge.GcodeDevice;
Expand All @@ -15,31 +17,25 @@ public class GCODETest {

private static final String GCODE = "GCODE";

@Before
public void setUp() throws Exception {
NRSerialPort port = new NRSerialPort("/dev/ttyUSB0", 250000);
GcodeDevice device = new GcodeDevice(port);
device.connect();
DeviceManager.addConnection(device, GCODE);


}

@After
public void tearDown() throws Exception {
DeviceManager.getSpecificDevice(GcodeDevice.class, GCODE).disconnect();

}

@Test
public void test() {
Object d = DeviceManager.getSpecificDevice(GcodeDevice.class, GCODE);
GcodeDevice device;
if(d==null){
return;
NRSerialPort port = new NRSerialPort("/dev/ttyUSB0", 230400);
device = new GcodeDevice(port);
device.connect();
DeviceManager.addConnection(device, GCODE);
}else{
device = (GcodeDevice)d;
}
GcodeDevice device = (GcodeDevice)d;
String response = device.runLine("M105");

System.out.println("Gcode line run: "+device.runLine("M105"));
device.disconnect();
if (response.length()>0)
System.out.println("Gcode line run: "+response);
else
fail("No response");

}

Expand Down

0 comments on commit 09c6a65

Please sign in to comment.