java串口编程 RXTXcomm

来源:互联网 发布:谷歌浏览器调试js 编辑:程序博客网 时间:2024/06/10 12:24
再次从网上查询,搜到了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下

    测试度串口程序:

   

[java] view plaincopyprint?
  1. /**
  2.      * 查找系统中已知端口
  3.      * @param args
  4.      */ 
  5.     public staticvoid main(String[] args) { 
  6.         //获得一个枚举,枚举中为包含系统中所有已知端口的 
  7.         portList = CommPortIdentifier.getPortIdentifiers(); 
  8.         while (portList.hasMoreElements()) { 
  9.             portId = (CommPortIdentifier) portList.nextElement(); 
  10.             if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { 
  11.             if (portId.getName().equals("COM1") || portId.getName().equals("COM2")) { 
  12.                 //if (portId.getName().equals("/dev/term/a")) { 
  13.                     System.out.println(portId.getName()); 
  14.                     SimpleRead reader = new SimpleRead(); 
  15.                 } 
  16.             } 
  17.         } 
  18.     } 


    结果:

    Stable Library
    =========================================
   Native lib Version = RXTX-2.1-7
   Java lib Version   = RXTX-2.1-7
   COM1
   COM2

0 0
原创粉丝点击