I am trying to read from a serial port using Java. I got it to read in from the serial port but when I go to close it I get this fatal error
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000010dbb612f, pid=510, tid=5891
#
# JRE version: Java(TM) SE Runtime Environment (7.0_79-b15) (build 1.7.0_79-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [librxtxSerial.jnilib+0x312f] Java_gnu_io_RXTXPort_interruptEventLoop+0x6b
#
# 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:
# /Users/daxloy/Documents/workspace/VexUART/hs_err_pid510.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.
This is the code I am using
Main class: import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("What TeleTypeWriter port is it on?");
Scanner s = new Scanner(System.in);
TwoWaySerialComm TWSC = new TwoWaySerialComm(s.nextLine());
s.close();
try{
TWSC.connect();
}catch(Exception e){
e.printStackTrace();
}
}
}
TwoWaySerialComm class:
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class TwoWaySerialComm {
String portName;
public TwoWaySerialComm(String pn){
//Sets the portName it has been passed
portName = pn;
}
public void connect() throws Exception{
//Creates the portId to have the port
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portName);
//Checks if it is currently owned so we do not have an issue with over writing anything
if(portId .isCurrentlyOwned()){
System.out.println("Port is already owned!");
}else{
//timeout for the communication
System.out.println("Port not owned");
int timeout = 2000;
//opens the port for communication
CommPort commPort = portId.open(this.getClass().getName(), timeout);
System.out.println("Casted as CommPort");
if(commPort instanceof SerialPort){
System.out.println("commPort is an instance of SerialPort");
//changes the commPort to the serialPort
SerialPort serialPort = (SerialPort)commPort;
//Sets the Baud rate, total bits of transfer, the stopping bits, and the parity for the serial port
serialPort.setSerialPortParams(230400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
InputStream in = serialPort.getInputStream(); //Creates the input for the serial port
OutputStream out = serialPort.getOutputStream(); //Creates the output for the serial port
//Starts threads for both input and output now
communication(in, out);
Thread.sleep(20);
commPort.close();
}else{
System.out.println("Port is not a Serial Port!");
}
}
}
public void communication(InputStream in, OutputStream out) throws IOException{
System.out.println("Starting communication");
int counter = 0;
int inInt = 0;
int previousint = -1;
boolean close = false;
while(!close){
inInt = in.read();
if(inInt != previousint){
System.out.println(inInt);
counter++;
if(counter == 5){
close = true;
}
}
}
}
}
Full consol output:
What TeleTypeWriter port is it on?
/dev/cu.usbserial
Stable Library
=========================================
Native lib Version = RXTX-2.2pre2
Java lib Version = RXTX-2.1-7
WARNING: RXTX Version mismatch
Jar version = RXTX-2.1-7
native lib Version = RXTX-2.2pre2
Port not owned
Casted as CommPort
commPort is an instance of SerialPort
Starting communication
76
76
76
76
76
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000010dbb612f, pid=510, tid=5891
#
# JRE version: Java(TM) SE Runtime Environment (7.0_79-b15) (build 1.7.0_79-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [librxtxSerial.jnilib+0x312f] Java_gnu_io_RXTXPort_interruptEventLoop+0x6b
#
# 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:
# /Users/daxloy/Documents/workspace/VexUART/hs_err_pid510.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.
#
EDIT:
Here is the system part of the log since the complete log was too large to put here
--------------- S Y S T E M ---------------
OS:Bsduname:Darwin 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
rlimit: STACK 8192k, CORE 0k, NPROC 709, NOFILE 10240, AS infinity
load average:9.08 4.20 1.71
CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 69 stepping 1, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, erms, ht, tsc, tscinvbit
Memory: 4k page, physical 4194304k(1048576k free)
/proc/meminfo:
vm_info: Java HotSpot(TM) 64-Bit Server VM (24.79-b02) for bsd-amd64 JRE (1.7.0_79-b15), built on Apr 10 2015 11:35:04 by "java_re" with gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
time: Sat Jan 21 17:49:06 2017
elapsed time: 16 seconds
The problem is fairly clear as mentioned in the console output:
Native lib Version = RXTX-2.2pre2
Java lib Version = RXTX-2.1-7
WARNING: RXTX Version mismatch
Jar version = RXTX-2.1-7
native lib Version = RXTX-2.2pre2
RXTXComm.jar
is mismatched, and librxtxSerial.jnilib
is expecting a different version of it. You can probably copy the correct versions of RXTEXComm.jar
and librxtxSerial.jnilib
into /Library/Java/Extensions
, or copy the native version to your app; it might solve the problem.
Also please post the output from:
# /Users/daxloy/Documents/workspace/VexUART/hs_err_pid510.log