CODE:
import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortException;
import jssc.SerialPortList;
public class Arduino {
public void connect(String portname) {
SerialPort port = new SerialPort(portname);
try {
port.openPort();
port.setParams(
SerialPort.BAUDRATE_9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE
);
port.addEventListener((SerialPortEvent event)->{
if(event.isRXCHAR()) {
try {
String s = port.readString();
System.out.print(s);
} catch (SerialPortException e) {
e.printStackTrace();
}
}
});
} catch (SerialPortException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// we need to array of string that hold all the ports
String portlist[] = SerialPortList.getPortNames();
for(int i =0; i<portlist.length;i++) {
System.out.println(portlist[i]);
}
Arduino obj = new Arduino();
obj.connect(portlist[0]);
}
}
ERROR:
A fatal error has been detected by the Java Runtime Environment: EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007110b5db, pid=22736, tid=23984 JRE version: Java(TM) SE Runtime Environment (14.0.1+7) (build 14.0.1+7) Java VM: Java HotSpot(TM) 64-Bit Server VM (14.0.1+7, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64) Problematic frame: C [jSSC-2.8_x86_64.dll+0xb5db] No core dump will be written. Minidumps are not enabled by default on client versions of Windows An error report file with more information is saved as: C:\Users\giorgi\eclipse-workspace\Arduino\hs_err_pid22736.log If you would like to submit a bug report, please visit: https://bugreport.java.com/bugreport/crash.jsp The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.
User contributions licensed under CC BY-SA 3.0