I'm trying to make an application that communicates Java with Arduino with the RXTXcomm.jar library that I downloaded from here
Now I can list the enabled serial ports and open the connection with a port with the Java lines:
serialPort = (SerialPort) portId.open(this.getClass().
getName(),2000);
// Serial params
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
But then when I'm going to get data from the Arduino, what I get is a fatal error:
En el método evento
Antes de readLine()
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007ffb7d132462, pid=5049, tid=0x00007ffb57601700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_92-b14) (build 1.8.0_92-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.92-b14 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [librxtxSerial.so+0x6462] read_byte_array+0x52
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/juanpa/developer/LaserLab/hs_err_pid5049.log
#
# If you would like to submit a bug report, please visit:
# http://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.
#
The method to read data from the Arduino is as follows:
/**
* Handle an event on the serial port. Read the data and print it.
*/
public synchronized void serialEvent(SerialPortEvent oEvent) {
String dataLine = "";
System.out.println("En el metodo evento");
if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
System.out.println("Antes de readLine()");
// Obtiene el texto
dataLine = input.readLine();
System.out.println(dataLine);
// Actualiza el JTextArea
//updateLog(dataLine);
// Guarda en archivo
System.out.println(dataLine);
} catch (Exception e) {
System.err.println(e.toString());
}
}
The message that is just before the reading of the stream is reached to print, but when it is going to read input.readLine()
it is not executed and the error comes out.
The input stream is defined as follows:
// open the streams
input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
I put the file librxtxSerial.so
in <ruta_java>/jre/lib/amd64
.
I'm using Fedora 24 64 bits with Oracle Java 8, I tried openjdk but I have the same error.
What can I try to solve this?