java开发 Ubuntu下串口通信 rxtx
依照教材,我直接在相关网站下载了RXTXcomm的相关包:Download - Rxtx (qbang.org)
在Ubuntu里面,将 librxtxParallel.so librxtxSerial.so 拷贝到jre文件夹下的 lib/amd64/里面
然后拷贝 RXTXcomm.jar 到jre文件夹下的 lib//ext 里面
写代码:略(网上一抓一大把,有空补充,如果有人问的话)
运行jar包后报错:
# # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007f84ae95e733, pid=8075, tid=0x00007f84ae855700 # # JRE version: Java(TM) SE Runtime Environment (8.0_281-b09) (build 1.8.0_281-b09) # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.281-b09 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: # /home/boocax/download/hs_err_pid8075.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. # 已放弃 (核心已转储)
解决办法:
sudo apt-get install librxtx-java
在: /urs/lib/jni/ 文件夹中找到新的 lib, librxtxParallel.so 和 librxtxSerial.so 拷贝到 jre文件夹下的 lib/amd64/ 里面
备注:
在Spring下,可以使用依赖,来代替jar包
<dependency> <groupId>org.rxtx</groupId> <artifactId>rxtx</artifactId> <version>2.1.7</version> </dependency>