Results 1 to 2 of 2
- 12-08-2011, 10:56 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 2
- Rep Power
- 0
Receiving GPS data through Comm port
EDIT: Dumb mistake... see reply if you don't want to waste time reading this first post.
Hello all,
I just recently started working on a project in Java. So I'm rather new to java, but I have been programming for around 13 years now. This project among other things has a need to receive GPS data from a USB GPS Receiver that is connected as a Comm port. I know the Comm number and can get the GPS data by connecting directly to that comm port using putty, but having some problems doing it in Java.
I downloaded and am using the Rxtx comm library. I first tried using their example serialreader code, but that spit out complete gibberish. So I have written my own code that is returning some non gibberish information, but it is as though it's completely missing some of the data.
This is my code I'm using currently to read the incoming data from the com. (Some preliminary information, this.in is an InputStream that is passed into the function. The inputstream is created using the rxtx method (SerialPort)commPort.getInputStream() after successfully connecting to the correct port.
Java Code:String readIn=""; boolean processing=true; try { while(processing) { if (this.in.read()!=-1) readIn = new String (readIn + (char)this.in.read()); if (this.in.read()==-1) { if (readIn != "") System.out.println(readIn); readIn=""; } } } catch (IOException e) { System.out.println(e.getMessage()); }
Java Code:PA000,435,0123,2,11.0,27M0,06 PA,00121222,,910.* GS3,,,,709182151,,,,96C $G,291124031,,,,3085527 PV,0202,* GM24.0,435,0123,044602,D1?
I know there are projects and stuff already out there to work with GPS devices and such, but I'm doing this as a hobby and enjoy trying to figure things out and write it from scratch myself. Sometimes though I get stumped on something like this and just can't figure out why it's doing what it's doing so I have to seek help :)
It would be nice if there was a bare minimalistic project out there for reading data from the serial port on Windows with no bells and whistles so that I could figure out the root concept and build on it.
Any help on this would be appreciated.Last edited by steven6282; 12-08-2011 at 11:06 PM.
- 12-08-2011, 11:02 PM #2
Member
- Join Date
- Dec 2011
- Posts
- 2
- Rep Power
- 0
Re: Receiving GPS data through Comm port
Wow...
what a dumb mistake.
I looked at that code right after posting it reviewing my post.. and realized I'm calling this.in.read() multiple times.. and it just makes sense that every time I call it, it's reading the next character, so of course I'm missing characters, I'm only capturing 1 in 3 characters...
*sigh*.... *facepalm*
Sorry to have wasted your time reading that post! If a mod wants to delete the post feel free, I'm leaving it there as a reference on how to make dumb mistakes and look foolish posting them .. haha.Last edited by steven6282; 12-08-2011 at 11:05 PM.
Similar Threads
-
javax.comm.CommPort serial port reopen PortInUseException
By Jim Ryan in forum Advanced JavaReplies: 1Last Post: 12-08-2011, 05:39 PM -
help please~~ my javax.comm prog hangs outputting to bluetooth com port
By ducks in forum New To JavaReplies: 2Last Post: 03-04-2011, 10:14 AM -
GIOVYNET Java Serial Comm Port Question
By the_justin in forum New To JavaReplies: 1Last Post: 11-30-2010, 01:13 PM -
Receiving data from a socket and querying database
By cotarelo in forum JDBCReplies: 7Last Post: 06-22-2010, 11:49 AM
Bookmarks