forked from scream3r/java-simple-serial-connector
-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Labels
clean-upcomponent:mavenChanges to the java build processChanges to the java build processgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededlanguage:javaNeeds changes to java sources.Needs changes to java sources.
Milestone
Description
A placeholder to port over some of @vogt31337's unit tests from the 2.8.1-experimental branch.
public void testSerialPortListing() {
String[] out = SerialPortList.getPortNames();
System.out.println(Arrays.toString(out));
// if we reached this point, loading the dynamic lib worked.
assertTrue(true);
}
private String findASerialPort() {
String[] out = SerialPortList.getPortNames();
if (out.length > 0) {
return out[0];
} else {
return null;
}
}
public void testSerialPortRead() {
String port = findASerialPort(); // could also be "COM1" under windows, or /dev/ttyS0 under linux
if (port != null) {
SerialPort serialPort = new SerialPort(port);
try {
serialPort.openPort();//Open serial port
serialPort.setParams(9600, 8, 1, 0);//Set params.
byte[] buffer = serialPort.readBytes(10);//Read 10 bytes from serial port
serialPort.closePort();//Close serial port
} catch (SerialPortException ex) {
System.out.println(ex);
}
} else {
Assert.fail("No comport found. Maybe running on a laptop? Or cables aren't attached?");
}
assertTrue(true);
}
private String findASerialPort() {
String[] out = SerialPortList.getPortNames();
if (out.length > 0) {
return out[0];
} else {
return null;
}
}
public void testSerialPortWrite() {
String port = findASerialPort(); // could also be "COM1" under windows, or /dev/ttyS0 under linux
if (port != null) {
SerialPort serialPort = new SerialPort(port);
try {
serialPort.openPort();//Open serial port
serialPort.setParams(SerialPort.BAUDRATE_9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);//Set params. Also you can set params by this string: serialPort.setParams(9600, 8, 1, 0);
serialPort.writeBytes("This is a test string".getBytes());//Write data to port
serialPort.closePort();//Close serial port
} catch (SerialPortException ex) {
System.out.println(ex);
}
} else {
Assert.fail("No comport found. Maybe running on a laptop? Or cables aren't attached?");
}
assertTrue(true);
}Metadata
Metadata
Assignees
Labels
clean-upcomponent:mavenChanges to the java build processChanges to the java build processgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededlanguage:javaNeeds changes to java sources.Needs changes to java sources.