Java mac 上的 rxtx lib segv 错误

Java rxtx lib segv error on mac

我正在尝试使用 Java 从串口读取数据。我让它从串口读入,但是当我关闭它时,我得到了这个致命错误

#
# 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.

这是我正在使用的代码

主要class: 导入 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;
                }
            }

        }
    }


}

完整的控制台输出:

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.
#

编辑:

这是日志的系统部分,因为完整的日志太大无法放在这里

---------------  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

如控制台输出中所述,问题相当清楚:

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 不匹配,librxtxSerial.jnilib 期待它的不同版本。您可以将 RXTEXComm.jarlibrxtxSerial.jnilib 的正确版本复制到 /Library/Java/Extensions 中,或者将本机版本复制到您的应用程序;它可能会解决问题。

另外请post输出自:

# /Users/daxloy/Documents/workspace/VexUART/hs_err_pid510.log