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

一.需要的工具和文件

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

2.rxtx-2.1-7-bins-r2 .zip 出处:http://users.frii.com/jarvi/rxtx/download.html。

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

二.环境搭建的步骤

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

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

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。

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

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

importgnu.io.CommPortIdentifier;

importjava.util.Enumeration;

publicclassCommTest {

staticCommPortIdentifier portId;

staticEnumeration portList;

staticintbauds[] = {9600,19200,57600,115200};

publicstaticvoidmain(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、付费专栏及课程。

余额充值