最近要做一个项目,接口数据可能通过RS232串口给我们传过来,所以就事先学了一下java如何通过串口接收数据,怕自己忘了,所以记录下来。
java操作串口是通过RXTX实现的,可以从http://fizzed.com/oss/rxtx-for-java下载。
安装说明:
Windows
RXTXcomm.jar goes in \jre\lib\ext (under java)
rxtxSerial.dll goes in \jre\bin
Mac OS X (x86 and ppc) (there is an Installer with the source)
RXTXcomm.jar goes in /Library/Java/Extensions
librxtxSerial.jnilib goes in /Library/Java/Extensions
Run fixperm.sh thats in the directory. Fix perms is in the Mac_OS_X
subdirectory.
Linux (only x86, x86_64, ia64 here but more in the ToyBox)
RXTXcomm.jar goes in /jre/lib/ext (under java)
librxtxSerial.so goes in /jre/lib/[machine type] (i386 for instance)
Make sure the user is in group lock or uucp so lockfiles work.
Solaris (sparc only so far)
RXTX