I have a GPS receptor, which send me NMEA frames. My code retrieve these ones, but in a really strange form :
I am using PuTTY to see the NMEA frames received by my receptor, and there is no problem.
EDIT - Here is the code I am using :
public class GPSFrame extends Observable implements Runnable
{
static Thread myThread=null;
static BufferedReader br;
static BufferedWriter wr;
static PrintWriter out;
static InputStreamReader isr;
static OutputStreamWriter osw;
static java.io.RandomAccessFile port;
/** CONSTRUCTOR **/
public GPSFrame()
{
myThread=new Thread(this);
}
public void start()
{
try
{
port=new java.io.RandomAccessFile("COM5","rwd");
port.writeBytes("\r\n");
port.writeBytes("c,31,0,0,5\r\n");
port.writeBytes("T,1000,1\r\n");
}
catch (Exception e){ System.out.println("start "+e.toString()); }
// The thread start automatically run() method
myThread.start();
}
/**********************************************************************************************
*************************** RETRIEVE GPS FRAMES AND SEND TO SERVEUR **************************
**********************************************************************************************/
public void run()
{
System.out.println("lecture COM...");
// INFINIT LOOP - GPSFrame is always listening for the GPS receptor
for(;;)
{
String st = null;
try
{
st=port.readLine();
String[]gpsframe=st.split(",");
/* IMPORTANT - DON'T FORGET SETCHANGED() or GPSFrame'll never
* notify UPDATE() ServerBoard method - We'll never see any changes */
setChanged();
notifyObservers(st);
}
catch (IOException e){ System.out.println(e.getMessage()); }
// Show in console
System.out.println(st);
}
}
}
EDIT :
When I first read GPS Frames with PuTTY then launch my application, I can see correct GPS Frames in console. But when I try to read the GPS Frame with my application first, I have encoded Frames.
I don't know why I can't retrieve the frames in this form. Can someone guide me to resolve this problem please ?
Thanks to you in advance !
Regards,
Tofuw
I've found a solution for my problem ! :D
My code is a little problematic because I used RandomAccessFile to read on my COM Port. With this method I can read the frame sended by the receptor, but not properly. The solved it, I have to
CONFIGURE the COM PORT
, which is not possible with RandomAccessFile.I did a configuration test :
With DATABITS_5 or DATABITS_6, I received these sort of frame :
But with DATABITS_7 or DATABITS_8, I received good frame :
I think by default, Databits or configured with 5 or 6. It depends. That is why it is better configure up ourselves the Port.
The way (or one of the way ?) to configure the COM Port, is to use SerialPort.
Here is a solution which is really helpfull (in this example we are reading data with an event mode, but you can use the flow mode - please see the 2nd links below for it) :
This is where I found this solution (/!\ French sites :D ):
I hope it will help you if you encounter the same problem as me
Have a nice day !!!
Tofuw
PS : Thanks to Aphex and AlexWien who helped me