基于64位Windows系统的JAVA程序连接串口命令概述



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这个外接的串口,连接成功!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值