RXTX is an extension of Javacomm serial communication
RXTX files required for development: Http://rxtx.qbang.org/wiki/index.php/Download
After unpacking, you can see the folders that support each platform:
If the installation path for Java is D:\java\jre7, the RxtxSerial.dll in the selected folder is copied to D:\java\jre7\bin\,
Copy Rxtxcomm.jar to D:java\jre\lib\ext\
The Rxtxcomm.jar is then introduced in the project's Lib package.
1 /**2 * Get computer serial port3 * @return4 * @throwsException5 * RXTX6 */7 PublicList<combean> listallcom ()throwsException {8List<combean> listcom =NewArraylist<>();9 commportidentifier Portid;TenEnumeration<?>portlist; One Try { APortlist =commportidentifier.getportidentifiers (); - while(Portlist.hasmoreelements ()) { -Carmanagebean car =NewCarmanagebean (); thePortid =(Commportidentifier) portlist.nextelement (); - if(Portid.getporttype () = =commportidentifier.port_serial) { - car.setcom (Portid.getname ()); - Listcom.add (car); + } - } + if(listcom.size () = = 0) { ACarmanagebean car =NewCarmanagebean (); atCar.setcom ("Serial not Found!")); - Listcom.add (car); - } -}Catch(Exception e) { - e.printstacktrace (); - } in returnlistcom; -}
Using RXTX to get the computer serial port