</pre>java read the serial port technology <p></p><p> 1, rxtx </p> <p> http://rxtx.qbang.org/wiki/index.php/Download</p><pre code_snippet_id= "1674392" Snippet_file_name= "blog_20160506_2_2194645" name= "code" class= "java" >package Fpx.grs.aliexpress.com;import Java.io.ioexception;import Java.io.inputstream;import Java.util.enumeration;import Java.util.toomanylistenersexception;import Gnu.io.commportidentifier;import Gnu.io.portinuseexception;import Gnu.io.serialport;import Gnu.io.serialportevent;import Gnu.io.serialporteventlistener;import Gnu.io.unsupportedcommoperationexception;public class Simpleread implements Runnable, Serialporteventlistener { Static Commportidentifier Portid; Static enumeration portlist; InputStream InputStream; SerialPort SerialPort; Thread Readthread; public static void Main (string[] args) {portlist = Commportidentifier.getportidentifiers (); while (portlist. hasMoreElements ()) {Portid = (commportidentifier) portlist.nextelement (); if (portid.getporttype () = = commportidentifier.port_serial) {if (Portid.getname (). Equals ("COM4")) { if (Portid.getname (). Equals ("/dev/term/a")) {Simpleread reader = new Simplerea D (); }}}} public Simpleread () {try {SerialPort = (serialPort) portid.open ("Simpl Ereadapp ", 2000); } catch (Portinuseexception e) {System.out.println (e);} try {InputStream = Serialport.getinputstream (); } catch (IOException e) {System.out.println (e);} try {Serialport.addeventlistener (this); } catch (Toomanylistenersexception e) {System.out.println (e);} Serialport.notifyondataavailable (TRUE); try {serialport.setserialportparams (9600, Serialport.databits_8, Serialport.stop Bits_1, Serialport.parity_none); } catch (Unsupportedcommoperationexception e) {System.out.println (e);} Readthread = new Thread (this); Readthread.start (); } public void Run () {try {thread.sleep (20000); } catch (Interruptedexception e) {System.out.println (e);} } public void Serialevent (Serialportevent event) {switch (Event.geteventtype ()) {case Serialportevent.bi : Case SerialPortEvent.OE:case SerialPortEvent.FE:case SerialPortEvent.PE:case Serialportev Ent. Cd:case SerialPortEvent.CTS:case SerialPortEvent.DSR:case SerialPortEvent.RI:case Serialpo RtEvent.OUTPUT_BUFFER_EMPTY:break; Case serialportevent.data_available:byte[] Readbuffer = new BYTE[20]; try {while (inputstream.available () > 0) {int numbytes = Inputstream.read (Readbuffe R); } SYSTEM.OUt.print (New String (Readbuffer)); } catch (IOException e) {System.out.println (e);} Break } }}
2, Jserialcomm
No need to add DLL to the system on RXTX basis
Https://github.com/Fazecast/jSerialComm/wiki
3, JSSC
Google's DLLs that don't need to rely on the system
Https://code.google.com/archive/p/java-simple-serial-connector/downloads
Java Read COM port