java - How do I read text from a serial port? -


I am trying to read data from Windows Serial Port via Java. I have javax.comm library and I am able to get some data but I am not correcting the data. When I read the port in a byte array and convert it to text then I get a series of series, but there is no real text string. I have tried to specify the byte array as both "UTF-8" and "US-ASCII" Do anyone know how to get real text from it?

This is my code:

  while (inputstream.available ()> gt; {int numBytes = inputstream .read (readBuffer); System.out.println (" "+ PortId.getName () +" Reading: "); System.out.println (" read "+ numbytes +" bytes ");} System.out.println (new string (readBuffer); System.out Println (new string (readBuffer, "UTF-8"); System.out.println (new string (readbuff, "US-ASCII"));  

Production of the first three lines I will not copy and paste (I think because these are not normal characters). Here's the output of hex: 78786000e67e9e60061e8606781e66e0869e98e086f898 98861878809e1e9880

I'm reading from the Hollks GPS device which outputs in string format. I know to make sure because I did it through C #.

Settings which I am using for communication that are correct in the C # app I: Baud Rate: 9600 Database: 8 Stop Bit: 1 Parity: Any

I can not tell with your code, but it seems that you can read the object To Using java.io.InputStream you either java.io.buffferedReader or java.io.InputSreamReader .

There are several ways to do this, but we use this:

  javax.comm.SerialPort port = ... {start your serial port} BufferedReader PortReader = new BufferedReader (new InputStreamReader (port.getInputStream ())); Try {string line = ponderre.light (); } Hold (IOException e) {...}  

Comments