Example data from serial port using System.out.print()
$GPGGA,134658.00,5106.9792,N,11402.3003,W,2,09,1.0,1048.47,M,-16.27,M,08,AAAA*60
This message ends with a carriage return followed by a newline. When I use the code below, I get this output.
$
G
P
G
G
A
,
.
.
.
(Carriage return)
(New Line)
$
G
P
G
S
A
My goal is to get a string that I can then split by ",". I want to reset/refresh that string on a carriage return/new line sequence.
static class SerialPortReader implements SerialPortEventListener {
public void serialEvent(SerialPortEvent event) {
try {
byte[] tester = serialPort.readBytes(1);
//System.out.print(getdata);
InputStream gpsStream = new ByteArrayInputStream(tester);
BufferedReader in = new BufferedReader(new InputStreamReader(gpsStream, StandardCharsets.UTF_8));
String output = in.readLine();
System.out.println(in);
} catch (SerialPortException | IOException ex) {
}
}
}
Lets Assume this is the console output. I want to parse the most recent line. In this case the $GPGSA string.
$GPGGA,134658.00,5106.9792,N,11402.3003,W,2,09,1.0,1048.47,M,-16.27,M,08,AAAA*60
$GPGSA,134658.00,W,2,09,1.0,1048.47,M,-16.27,M,08,AAAA*60
I guess my question is how do I get the input stream into a format that I can parse?
New edit: When I use this code, it prints exactly how I need it.
How can I replicate the System.out.print(); function?
String wtf = serialPort.readString(event.getEventValue());
System.out.print(wtf);
Console output from above string:
$GPGSA,M,3,30,11,28,07,01,17,08,13,,,,,2.3,1.2,2.0*3D
$GPGSV,3,1,12,30,74,226,33,11,64,090,31,28,55,317,32,07,55,169,27*75
$GPGSV,3,2,12,01,51,118,22,17,31,239,25,08,28,050,34,13,18,300,22*75
$GPGSV,3,3,12,48,22,240,,19,08,233,,15,01,324,,22,00,118,*7A