java串口开发环境_Windows下的java串口开发环境配置

一.需要的工具和文件

1.myeclipse 版本:3.0以上即可。

3.JDK 版本:我用的是1.5版,但是我认为更低的版本也没有问题。

二.环境搭建的步骤

step1.在eclipse中新建一个工程(根据你自己的需要,Applet,tomcat,java工程等均可)。

step2.在工程下建一个lib文件夹。

7d859034d30fd9bd40fca6a34306fd86.png

step3.将rxtx-2.1-7-bins-r2 .zip解压缩,得到文件夹[rxtx-2.1-7-bins-r2]。

step4.将[rxtx-2.1-7-bins-r2]\RXTXcomm.jar这个文件copy到step2创建的lib中。

step5.将[rxtx-2.1-7-bins-r2]\Windows\i368-mingw32目录下的两个dll文件copy到step2创建的lib中。

step6.在工程上右键 -> Properties -> Java Builder Path -> Libraries -> Add JARs -> 选择step2中创建的lib目录下的RXTXcomm.jar -> OK。

step7.最关键的一步:  点RXTXcomm.jar前面的小加号(+) -> 选择Native library location -> 点右边一列按钮中的Edit… -> 选择step2中创建的lib目录 -> OK。

118fd23b4e5a06c647e9b542fb0868e2.png

补充:如果你的代码需要调用本地dll,你可以通过同样的方式设置Native library location。

注意:

系统如果需要64位的插件,可以从下面的链接下载:

http://fizzed.com/oss/rxtx-for-java

三.环境配置完了以后,可以写一个程序来测试一下了。以下是我的test程序。

import gnu.io.CommPortIdentifier;

import java.util.Enumeration;

public class CommTest {

static CommPortIdentifier portId;

static Enumeration portList;

static int bauds[] = { 9600, 19200, 57600, 115200 };

public static void main(String[] args) {

portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {

portId = (CommPortIdentifier) portList.nextElement();

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

System.out.println("Find CommPort: " + portId.getName());

}

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值