Windows
----------------------------------------------------
Choose your binary build - x64 or x86 (based on which version of
the JVM you are installing to)
NOTE: You MUST match your architecture. You can't install the i386
version on a 64-bit version of the JDK and vice-versa.
For a JDK installation:
Copy RXTXcomm.jar ---> <JAVA_HOME>\jre\lib\ext
Copy rxtxSerial.dll ---> <JAVA_HOME>\jre\bin
Copy rxtxParallel.dll ---> <JAVA_HOME>\jre\bin
三个文件都要按照官方install文档的位置放置自己JDK的环境中,这点非常重要!!!
安装完成后插上串口,这里使用RS-232进行测试,使用JAVA写一个小的方法读出外接RS-232连接的COM口号。
package SerialPort;
import java.util.Enumeration;
import gnu.io.CommPortIdentifier;
public class Rs232 {
public static void main(String[] args) {
Enumeration<?> en = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId;
try {
en = CommPortIdentifier.getPortIdentifiers();
while (en.hasMoreElements()) {
portId = (CommPortIdentifier) en.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println(portId.getName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
我当前可以获得COM4这个外接的串口,连接成功!