My old post show how to Install and test java-simple-serial-connector with Arduino, running on Ubuntu and Netbeans IDE.
This video show how to use jSSC on Windows 8.1/Nerbeans IDE. Basically it is the same, with different COM port assignment.
The Java code is listed here. It send a message to Arduino Esplora via USB Serial port, COM3, using jSSC library.
package java_testjssc;
import jssc.SerialPort;
import jssc.SerialPortException;
public class Java_testjSSC {
public static void main(String[] args) {
SerialPort serialPort = new SerialPort("COM3");
try {
System.out.println("Port opened: " + serialPort.openPort());
System.out.println("Params setted: "
+ serialPort.setParams(9600, 8, 1, 0));
System.out.println("\"Hello World!!!\" successfully writen to port: "
+ serialPort.writeBytes("Hello World!!!".getBytes()));
System.out.println("Port closed: "
+ serialPort.closePort());
}
catch (SerialPortException ex){
System.out.println(ex);
}
}
}
The Arduino side code, refer to the post "Serial communication between Arduino Esplora and PC".
No comments:
Post a Comment