Posts: 6
Joined: Fri Oct 17, 2008 6:12 pm
Location: Australia

BlueTools & GPS

Sun Nov 02, 2008 6:14 pm

Hi All
I am developing a application using maptools and BlueTools in order to connect to a GPS using Bluetools and then pass the data on to maptools for use in application.
I have in part based my code on the FindandConnect example found with bluetools as follows

Private Sub ReadCallback(ByVal result As IAsyncResult)
Dim buffer() As Byte
Dim len As Integer
'nmeaparser below is GpsToolsNET.NmeaParser
' result is always a BlueToolsAsyncResult object
Dim blueAsyncResult As BlueToolsAsyncResult = result

' We passed on buffer as custom object, you can pass on any object here. We passed the stream object
Dim stream As ServiceStream = blueAsyncResult.AsyncState

' The buffer used for reading can be found in the result object.
buffer = blueAsyncResult.Buffer

' EndRead() must always be called!
' If stream has been closed due to an error, we'll have an excpetion here

len = stream.EndRead(result)

Dim str As String
Dim enc As New System.Text.ASCIIEncoding
str = enc.GetString(buffer, 0, len)
' MsgBox(str)

' Start new async read
stream.BeginRead(m_buffer, 0, m_buffer.Length, New AsyncCallback(AddressOf ReadCallback), m_stream)

Catch ex As ObjectDisposedException
' Thrown if stream has been closed.

End Try

End Sub
The application connectss fine with the GPS , the service is started and data is being received but it the nature of the received data which has me worried.
When I examine the 'str' being passsed to the nmeaparser it doesnt always start at the beginning of the NMEA string which should be a $ etc.Is this observation correct? - does the buffer length need adjusting? ?
It appears to be randomly starting somewhere mid nmea string.
Do I need to correct this?
If so - how do I ensure a proper NMEA string is being sent to the maptools nmea parser consistently.
I'm connecting to the GPS ok and sometimes the application works fine yet other times it struggles.
Whilst trying to debug the application I discovered the above and I am wondering if it could be the source of my problems.

Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: BlueTools & GPS

Mon Nov 03, 2008 4:57 pm

The BeginRead will read as much off the stream that it can find. This is not necessarily the entire NMEA string though. Parts of it might not yet have been written to the Stream. You have to actually read all the data off the stream before parsing it.


Posts: 6
Joined: Fri Oct 17, 2008 6:12 pm
Location: Australia

RE: BlueTools & GPS

Sun Nov 16, 2008 3:41 pm

Thanks Jonas - I have since realised that I was trying to skin a cat from the inside - now I just use Bluetools to start service and connect to GPS through standard GPSTools commands - works a treat.

Posts: 3
Joined: Thu Feb 04, 2010 6:53 pm

RE: BlueTools & GPS

Thu Feb 04, 2010 6:54 pm

I know this is an old topic, but:

Can you tell me what bluetooth GPS device you were using? I have a similar project.

Return to “BlueTools”