使用RXTX擷取電腦串口

來源:互聯網
上載者:User

標籤:通訊   cat   class   ret      bin   code   return   平台   

  RXTX是javacomm串口通訊的一個擴充

  RXTX開發所需檔案的:http://rxtx.qbang.org/wiki/index.php/Download

  解壓之後可以看到支援各個平台的檔案夾:

  如果java的安裝路徑為D:\java\jre7,則將選中的檔案夾中的rxtxSerial.dll複製到D:\java\jre7\bin\,

                               將RXTXcomm.jar複製到D:java\jre\lib\ext\

  然後在項目的lib包中引入RXTXcomm.jar。

 

 1 /** 2 * 擷取電腦串口 3 * @return 4 * @throws Exception 5 * RXTX 6 */ 7 public List<ComBean> listAllCom() throws Exception { 8   List<ComBean> listCom = new ArrayList<>(); 9   CommPortIdentifier portId;10   Enumeration<?> portList;11   try {12     portList = CommPortIdentifier.getPortIdentifiers();13     while (portList.hasMoreElements()) {14       CarManageBean car = new CarManageBean();15       portId = (CommPortIdentifier) portList.nextElement();16       if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {17         car.setCom(portId.getName());18         listCom.add(car);19       }20     }21     if (listCom.size() == 0) {22       CarManageBean car = new CarManageBean();23       car.setCom("未找到串口!");24       listCom.add(car);25     }26   } catch (Exception e) {27     e.printStackTrace();28   }29   return listCom;30 }

 

使用RXTX擷取電腦串口

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.