再次从网上查询,搜到了RXTXcomm.jar包比较好,是封装了comm.jar的方法。
安装:
1.copy rxtxSerial.dll to [JDK-directory]/jre/bin/rxtxSerial.dll
2.copy RXTXcomm.jar to [JDK-directory]/jre/lib/ext/RXTXcomm.jar
3.windows是rxtxParallel.dll复制到windows/system32下
测试度串口程序:
/**
* 查找系统中已知端口
* @param args
*/
public static void main(String[] args) {
//获得一个枚举,枚举中为包含系统中所有已知端口的
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1") || portId.getName().equals("COM2")) {
//if (portId.getName().equals("/dev/term/a")) {
System.out.println(portId.getName());
SimpleRead reader = new SimpleRead();
}
}
}
}
结果:
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
COM1
COM2