操作系统linux:red hat enterprise Linux Server release 6.3,kernel 2.6.32-279.e16.x86_64 on x86_64
java版本:自带的/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.
使用串口:RXTX,版本:rxtx-2.1-7-bins-r2。目前已将 rxtx-2.1-7-bins-r2\rxtx-2.1-7-bins-r2\Linux\x86_64-unknown-linux-gnu\librxtxSerial.so拷贝到了/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64下.
代码在windows中运行是正常的,打开串口、发送数据、接收数据都正常。但在linux下只有打开串口是成功的,一发送数据或接收数据就报错。(程序编写时,已注意到windows中打开串口"COM1",linux中打开"/dev/ttyS0")。打开串口代码:
public SerialPort openPort() throws SerialPortParameterFailure, NotASerialPort, NoSuchPort, PortInUse { try { //通过端口名识别端口
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(m_comPortNumString); //打开端口,并给端口名字和一个timeout(打开操作的超时时间)
CommPort commPort = portIdentifier.open(m_comPortNumString, 2000); //判断是不是串口
if (commPort instanceof SerialPort) {
m_serialPort = (SerialPort) commPort;
try {
//设置一下串口的波特率等参数
m_serialPort.setSerialPortParams(m_bound, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
throw new SerialPortParameterFailure();
}
addListener(new SerialListener());
System.out.println("Open " + m_comPortNumString + " sucessfully !");
return m_serialPort;
}
else {
//不是串口
throw new NotASerialPort();
}
} catch (NoSuchPortException e1) {
throw new NoSuchPort();
} catch (PortInUseException e2) {
System.out.println("err:port In Use");
throw new PortInUse();
}
}发送数据代码:
public void sendToPort( byte[] order) {//throws SendDataToSerialPortFailure, SerialPortOutputStreamCloseFailure {
OutputStream out = null;
try {
out = m_serialPort.getOutputStream();
out.write(order);
out.flush();
} catch (IOException e) {
//TODO throw new SendDataToSerialPortFailure();
System.out.println("err:SendDataToSerialPort Failure");
} finally {
try {
if (out != null) {
out.close();
out = null;
}
} catch (IOException e) {
//TODO throw new SerialPortOutputStreamCloseFailure();
}
}
}目前在打开串口时可见打印出“"Open /dev/ttyS0 sucessfully ”,但一调用到发送数据就报错:#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f8faa8e4733, pid=1991, tid=0x00007f8faa7db700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build 1.8.0_121-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [librxtxSerial.so+0x7733] Java_gnu_io_RXTXPort_nativeDrain+0xc3
#
# 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:
# /root/out---/hs_err_pid1991.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.
#
Aborted (core dumped)打开hs_err_pid1991.log文件中,有如下描述:
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j gnu.io.RXTXPort.nativeDrain(Z)Z+0
j gnu.io.RXTXPort$SerialOutputStream.flush()V+72
j serialPort.SerialTool.sendToPort([B)V+15
j serialPort.mainTest.heartthrobTimer()V+12
j serialPort.HeartthrobTimes.run()V+46
v ~StubRoutines::call_stub可见问题发生在sendToPort函数的这一行out = m_serialPort.getOutputStream();-------------
因初接触使用linux,百思不得其解,以为是jdk环境问题,安装了 jre1.8.0_121版本(放到了/usr/lib/jvm//jre1.8.0_121),还是以上错误,请大家走过路过帮帮忙
java版本:自带的/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.
使用串口:RXTX,版本:rxtx-2.1-7-bins-r2。目前已将 rxtx-2.1-7-bins-r2\rxtx-2.1-7-bins-r2\Linux\x86_64-unknown-linux-gnu\librxtxSerial.so拷贝到了/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64下.
代码在windows中运行是正常的,打开串口、发送数据、接收数据都正常。但在linux下只有打开串口是成功的,一发送数据或接收数据就报错。(程序编写时,已注意到windows中打开串口"COM1",linux中打开"/dev/ttyS0")。打开串口代码:
public SerialPort openPort() throws SerialPortParameterFailure, NotASerialPort, NoSuchPort, PortInUse { try { //通过端口名识别端口
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(m_comPortNumString); //打开端口,并给端口名字和一个timeout(打开操作的超时时间)
CommPort commPort = portIdentifier.open(m_comPortNumString, 2000); //判断是不是串口
if (commPort instanceof SerialPort) {
m_serialPort = (SerialPort) commPort;
try {
//设置一下串口的波特率等参数
m_serialPort.setSerialPortParams(m_bound, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
throw new SerialPortParameterFailure();
}
addListener(new SerialListener());
System.out.println("Open " + m_comPortNumString + " sucessfully !");
return m_serialPort;
}
else {
//不是串口
throw new NotASerialPort();
}
} catch (NoSuchPortException e1) {
throw new NoSuchPort();
} catch (PortInUseException e2) {
System.out.println("err:port In Use");
throw new PortInUse();
}
}发送数据代码:
public void sendToPort( byte[] order) {//throws SendDataToSerialPortFailure, SerialPortOutputStreamCloseFailure {
OutputStream out = null;
try {
out = m_serialPort.getOutputStream();
out.write(order);
out.flush();
} catch (IOException e) {
//TODO throw new SendDataToSerialPortFailure();
System.out.println("err:SendDataToSerialPort Failure");
} finally {
try {
if (out != null) {
out.close();
out = null;
}
} catch (IOException e) {
//TODO throw new SerialPortOutputStreamCloseFailure();
}
}
}目前在打开串口时可见打印出“"Open /dev/ttyS0 sucessfully ”,但一调用到发送数据就报错:#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f8faa8e4733, pid=1991, tid=0x00007f8faa7db700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build 1.8.0_121-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [librxtxSerial.so+0x7733] Java_gnu_io_RXTXPort_nativeDrain+0xc3
#
# 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:
# /root/out---/hs_err_pid1991.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.
#
Aborted (core dumped)打开hs_err_pid1991.log文件中,有如下描述:
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j gnu.io.RXTXPort.nativeDrain(Z)Z+0
j gnu.io.RXTXPort$SerialOutputStream.flush()V+72
j serialPort.SerialTool.sendToPort([B)V+15
j serialPort.mainTest.heartthrobTimer()V+12
j serialPort.HeartthrobTimes.run()V+46
v ~StubRoutines::call_stub可见问题发生在sendToPort函数的这一行out = m_serialPort.getOutputStream();-------------
因初接触使用linux,百思不得其解,以为是jdk环境问题,安装了 jre1.8.0_121版本(放到了/usr/lib/jvm//jre1.8.0_121),还是以上错误,请大家走过路过帮帮忙
解决方案 »
- 请教一个screen命令问题,困扰已久!!!
- linux pppd 中兴MF832S 4G拨号。100分!急急急急急急!!!!!
- aix安装jdk8
- 支持中文的Write命令实现 linux运行环境下实现
- RK3288+RTL8201F-VB-CG网卡芯片,kernel3.10配置问题?
- 利用TCP/UDP Socket调试工具给服务器指定端口发送信息,接受问题
- 求大神给分析分析
- ssh
- 安装samba找不到配置文件
- shell脚本
- 在用迅为4418开发板,Linux+QT下,为什么在/dev下没有SPI的设备结点,如何操作SPI
- 大家帮忙看一下这个IP配置好了之后为什么还是ping不同。。。
可见问题发生在sendToPort函数的这一行
out.flush();