Home PageFacebookRSS News Feed
PocketGPS
Web
SatNav,GPS,Navigation
Pocket GPS World - SatNavs | GPS | Speed Cameras: Forums

Pocket GPS World :: View topic - how read nmea data from bt gps via serial port (.net / c#)
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in for private messagesLog in for private messages   Log inLog in 

how read nmea data from bt gps via serial port (.net / c#)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Pocket GPS World Forum Index -> Advanced GPS Lounge
View previous topic :: View next topic  
Author Message
eastlands
Occasional Visitor


Joined: Dec 02, 2004
Posts: 5
Location: UK

PostPosted: Thu Dec 02, 2004 8:46 pm    Post subject: how read nmea data from bt gps via serial port (.net / c#) Reply with quote

I have developed a marine navigation program (www.navstation.co.uk)that has a gps module that works fine for cabled gps via the serial port but I am having real trouble getting data from a bluetooth gps.

I have tomtom installed and the tomtom gps works well by selecting the "bluetooth gps" connection option but it does not work on the "BT on COM6" option.

I have tried to use WinFast Navigator (using all the com ports shown in the list) but I cannot get this to receive data either. I am not able to open port 6 (which I think SHOULD be the BT com port) at all.

I have two questions (no doubt others will follow):
* how does the tomtom "bluetooth gps" option communicate with the gps?
* what might be using the BT com6 port and how can I free it up?

I have tried uninstalling the tomtom gps unit and soft resets with no changes. My gps is an Ambicom unit.

Regards,

Stuart Eastland
Back to top
View user's profile Send private message Visit poster's website
lbendlin
Pocket GPS Staff
Pocket GPS Staff


Joined: 02/11/2002 22:41:59
Posts: 11878
Location: Massachusetts, USA

PostPosted: Thu Dec 02, 2004 8:59 pm    Post subject: Reply with quote

You haven't tried hard enough. you need to deinstall the dreadful TomTom GPS driver twice. Once you made sure it is really, really gone (you can check that in the registry) you can re-install version 2.07 from or downloads page.

After that accessing the COM port from a program is a snap. I can post some sample code if you like
_________________
Lutz

Report Map Errors here:
TomTom/TeleAtlas NAVTEQ
Back to top
View user's profile Send private message Send e-mail
eastlands
Occasional Visitor


Joined: Dec 02, 2004
Posts: 5
Location: UK

PostPosted: Thu Dec 02, 2004 10:11 pm    Post subject: Reply with quote

Wow - fast response!

I'm stuck trying to uninstall TomTom gps a second time. It is no longer in the add/remove programs list. Do you think this is blocking the bt serial port?
There are still entries in the HKLM\software\tottom\gps engine registry hive.

If did try installing tottom gps version 2.07 earlier today after contacting tomtom support, but I could not get this to recognise the gps on a com port, and it does not have a "bluetooth gps" option...

Stuart
Back to top
View user's profile Send private message Visit poster's website
lbendlin
Pocket GPS Staff
Pocket GPS Staff


Joined: 02/11/2002 22:41:59
Posts: 11878
Location: Massachusetts, USA

PostPosted: Fri Dec 03, 2004 6:07 am    Post subject: Reply with quote

You don't need to select a "Bluetooth gps" - just choose the correct COM port - for example COM8 (you can find the right one in the BlueTooth manager, it's listed as Outgoing serial port)
_________________
Lutz

Report Map Errors here:
TomTom/TeleAtlas NAVTEQ
Back to top
View user's profile Send private message Send e-mail
eastlands
Occasional Visitor


Joined: Dec 02, 2004
Posts: 5
Location: UK

PostPosted: Fri Dec 03, 2004 9:35 am    Post subject: com port blocked by tomtom? Reply with quote

Well your suggestion really leads back to my original problem.

In my bluetooth settings, com4 is shown as inbound and com5 is shown as outbound for bluetooth serial port.

With tomtom gps 2.07 I have tried to use various ports with the following results:
com4: no data
com5: no data
BT on com6: no data

With all the above, the bluetooth light on the gps remains flashing, indicating that it is not connected to a device. With tomtom gos 3.x and the "bluetooth gps" option the blue light was solid and I got data...

In WinFast Navigator I have tried to use various ports with the following results:
com4: port appears to open but no data and gps not showing connected light - device hangs trying to exit
com5: port appears to open but no data and gps not showing connected
com6: port cannot be opened

My gps has very few configuration options - it is bonded to my device but I was not able to set / select any serial port options.

Can anyone explain how the "bluetooth gps" option in tomtom connects to the gps? Does it bypass the serial port profile and use native bluetooth commands? If so does anyone know how to do this in .NET?


Stuart
Back to top
View user's profile Send private message Visit poster's website
Pc-Mobile
Frequent Visitor


Joined: 26/10/2002 10:38:36
Posts: 789
Location: Hong Kong

PostPosted: Fri Dec 03, 2004 11:10 am    Post subject: Reply with quote

Since it worked with a wired GPS there is no reason it cannot work with a BT GPS.

You might like to explore if the problem is with the GPS (configuration options?).

Have you tried another BT GPS?
_________________
Pc-Mobile
http://pc-mobile.net/gps.htm
Back to top
View user's profile Send private message Send e-mail Visit poster's website
barryd
Frequent Visitor


Joined: Mar 27, 2004
Posts: 285
Location: Cheshire, England

PostPosted: Fri Dec 03, 2004 2:27 pm    Post subject: Reply with quote

lbendlin wrote:
After that accessing the COM port from a program is a snap. I can post some sample code if you like

Lutz, if you have sample code for reading NMEA strings from a COM port using eVC that is understandable by a novice programmer, I'd be very interested in that. Basically I'm struggling to get to grips with serial comms programming. I can open the port as a file and read from it, but can't see how to get clean blocks of data for each second. If I use a timer set to a second, I just get whatever is waiting on the port at that moment, which is typically the end of one second's worth of data and start of the next. I can't see how to sync my calls to the port with when the GPS has finished sending each second's worth of its data. I have tried understanding an "idiot's guide" to using threaded code and events to do it, but that just succeeded in making me feel like an idiot. Smile
_________________
Barry Davies
Back to top
View user's profile Send private message
eastlands
Occasional Visitor


Joined: Dec 02, 2004
Posts: 5
Location: UK

PostPosted: Fri Dec 03, 2004 3:20 pm    Post subject: Reply with quote

I wouldn't bother trying to sych your code with the gps - not sure how you would do this anyway.
What I do is have a timer (1 sec) which reads the com port into a buffer. I then split the contents of the buffer (on crlf?) into an array of nmea sentences. I assume that the last sentence received may be incomplete so I reset the buffer to the value of the last sentence. I can then parse the nmea stuff as required (split each sentence on comma into array of values. When the timer fires again, I append the stuff from the com port to the buffer....
Hope this helps
Stuart
Back to top
View user's profile Send private message Visit poster's website
lbendlin
Pocket GPS Staff
Pocket GPS Staff


Joined: 02/11/2002 22:41:59
Posts: 11878
Location: Massachusetts, USA

PostPosted: Fri Dec 03, 2004 3:46 pm    Post subject: Reply with quote

It's actually pretty easy. What you need to do is flush the buffer before starting to listen to the port. 1 second is plenty of time to get the position data, but I chose to wait for a particular sequence instead of timing it.

Here's what I do

Code:

LPCTSTR GetPosition(TCHAR * ComPort,const unsigned int ComSpeed) {
   
   DCB dcb;
   COMMTIMEOUTS cto;
   HANDLE hLocal;
   DWORD cBytes;
   int i;
   BOOL bFound = FALSE;
   BYTE szText[256], *pPtr;
   TCHAR szOut[256];
   TCHAR * szPos = TEXT("");

   hLocal = CreateFile (ComPort, GENERIC_READ , 0, NULL, OPEN_EXISTING, 0, NULL);
   if (hLocal != INVALID_HANDLE_VALUE) {
      // Configure port.
      dcb.DCBlength = sizeof (dcb);
      GetCommState (hLocal, &dcb);
      dcb.BaudRate = ComSpeed; //CBR_38400;
      dcb.fParity = FALSE;
      dcb.fNull = FALSE;
      dcb.StopBits = ONESTOPBIT;
      dcb.Parity = NOPARITY;
      dcb.ByteSize = 8;
      SetCommState (hLocal, &dcb);

      // Set the timeouts. Set infinite read timeout.
      cto.ReadIntervalTimeout = MAXDWORD;
      cto.ReadTotalTimeoutMultiplier = 0;
      cto.ReadTotalTimeoutConstant = 0;
      cto.WriteTotalTimeoutMultiplier = 0;
      cto.WriteTotalTimeoutConstant = 0;
      SetCommTimeouts (hLocal, &cto);

      PurgeComm(hLocal,PURGE_RXCLEAR);

      while (!bFound) {
         wsprintf(szPos,TEXT(""));
         pPtr = szText;
         for (i = 0; i < sizeof (szText)-sizeof (TCHAR); i++) {
            ReadFile (hLocal, pPtr, 1, &cBytes, 0);
            if (hLocal == INVALID_HANDLE_VALUE)   return (LPCTSTR)szPos;
            if(cBytes) {
               if(*pPtr++ == 10) {
                  *pPtr-- = 0;
                  *pPtr-- = 0;
                  *pPtr-- = 0;
                  wsprintf(szOut,TEXT("%s"),szText);
                  break;
               }
               *pPtr++ = 0;
            }
         }

         if(wcsncmp(szOut,TEXT("$GPRMC"),6) == 0) { //found a position
            if(*(szOut + 18) != 86) {  //Valid position
               *(szOut + 44) = 0;
               szPos = szOut + 20;
            }
            bFound = TRUE;
         }
         if(wcsncmp(szOut,TEXT("$GPGGA"),6) == 0) { //found a position
            if(*(szOut + 18) != 44) {  //Valid position
               *(szOut + 42) = 0;
               szPos = szOut + 18;
            }
            bFound = TRUE;
         }
         if(wcsncmp(szOut,TEXT("$GPGLL"),6) == 0) { //found a position
            if(*(szOut + 7) != 44) {  //Valid position
               *(szOut + 31) = 0;
               szPos = szOut + 7;
            }
            bFound = TRUE;
         }

      }
      //MessageBox(0,szPos,TEXT("Found in"),MB_OK);

      if(wcscmp(szPos,TEXT("")) != 0) {
         // get decimal values
         double lat = (*(szPos) - 48) * 10 + (*(szPos + 1) - 48);
         for(i = 0; i < 7;i++)
            *(szLat + i) = *(szPos + i + 2);
         *(szLat + 7) = 0;
         lat = lat + (wcstod(szLat, NULL) / 60);
         if(*(szPos + 10) == 83) lat = - lat; // South
         wsprintf(szLat,TEXT("%.6f"),lat);

         double lon = (*(szPos + 12) - 48) * 100 + (*(szPos + 13) - 48) * 10 + (*(szPos + 14) - 48);
         for(i = 0; i < 7;i++)
            *(szLon + i) = *(szPos + i + 15);
         *(szLon + 7) = 0;
         lon = lon + (wcstod(szLon, NULL) / 60);
         if(*(szPos + 23) == 87) lon = - lon;  // West
         wsprintf(szLon,TEXT("%.6f"), lon);
         
         // reformat  position from ddmm.mmmm,N,dddmm.mmmm,W to xx°yy.zzzz'N xxx°yy.zzzz'W
         *(szPos + 26) = 0;
         *(szPos + 25) = *(szPos + 23);
         *(szPos + 24) = 39;
         for(i = 23; i > 16; i--)
            *(szPos + i) = *(szPos + i - 2);
         *(szPos + 16) = 176;
         for(i = 15; i > 12; i--)
            *(szPos + i) = *(szPos + i - 1);
         *(szPos + 12) = 32;
         *(szPos + 11) = *(szPos + 10);
         *(szPos + 10) = 39;
         for(i = 9; i > 2; i--)
            *(szPos + i) = *(szPos + i - 1);
         *(szPos + 2) = 176;


      }

   }
   if (hLocal != INVALID_HANDLE_VALUE)   CloseHandle (hLocal);
   //            MessageBox(0,szPos,TEXT("Found out"),MB_OK);
   return (LPCTSTR)szPos;
}   


So the really important part is the PurgeComm call. Depending on the type of receiver you will have to expect some garbage back from this call - for example the Mitac Mio does a warm start of the GPS reeiver. Other than that it works fine.
_________________
Lutz

Report Map Errors here:
TomTom/TeleAtlas NAVTEQ


Last edited by lbendlin on Fri Dec 03, 2004 3:52 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
eastlands
Occasional Visitor


Joined: Dec 02, 2004
Posts: 5
Location: UK

PostPosted: Fri Dec 03, 2004 3:50 pm    Post subject: solution... Reply with quote

I have got my gps talking at last.
I was hung up on issues / conflicts with tomtom which were irrelevant.
I removed the bluetooth bonding with the gps, did a soft reset and then tried to bond again. This time it asked me if I wanted to create a serial port profile (com5, my outbound bt port) and I did so.
Now able to see gps data on com5 using my own software and others.
Relief,
Stuart :P
Back to top
View user's profile Send private message Visit poster's website
lbendlin
Pocket GPS Staff
Pocket GPS Staff


Joined: 02/11/2002 22:41:59
Posts: 11878
Location: Massachusetts, USA

PostPosted: Fri Dec 03, 2004 3:57 pm    Post subject: Re: com port blocked by tomtom? Reply with quote

eastlands wrote:
Well your suggestion really leads back to my original problem.


Search the forum for BTCEIF.dll - or maybe someone has the registry path handy. You need to correct the registry entry for the Bluetooth driver.
_________________
Lutz

Report Map Errors here:
TomTom/TeleAtlas NAVTEQ
Back to top
View user's profile Send private message Send e-mail
barryd
Frequent Visitor


Joined: Mar 27, 2004
Posts: 285
Location: Cheshire, England

PostPosted: Fri Dec 03, 2004 9:33 pm    Post subject: Reply with quote

Thanks for the quick replies. Will try out both ideas.
_________________
Barry Davies
Back to top
View user's profile Send private message
barryd
Frequent Visitor


Joined: Mar 27, 2004
Posts: 285
Location: Cheshire, England

PostPosted: Sun Dec 05, 2004 6:38 pm    Post subject: Reply with quote

Lutz - am using your code and would appreciate any ideas on a problem I'm getting.

I had to add declarations for szLat and szLon to make it compile. I'm calling it from a one-second timer and it runs fine for about 30-40 seconds (not always the same number) but then freezes up. By tracing the code, when it fails the CreateFile() call takes about a minute to return, rather than under a second usually. It then does return with a valid handle, but then the ReadFile() loop to keep reading garbage forever. I've tried using longer timers, but get the same behaviour after the same number of cycles. If I use a counter to break out of the ReadFile() loop after say 30 lines of garbage, I just keep on getting the same problem on each timer call.

Any ideas what might be going wrong?
_________________
Barry Davies
Back to top
View user's profile Send private message
lbendlin
Pocket GPS Staff
Pocket GPS Staff


Joined: 02/11/2002 22:41:59
Posts: 11878
Location: Massachusetts, USA

PostPosted: Sun Dec 05, 2004 7:02 pm    Post subject: Reply with quote

You're not opening and closing the port every second, are you?

Have a read through the port setup - there are a few option to manipulate error timeouts.
_________________
Lutz

Report Map Errors here:
TomTom/TeleAtlas NAVTEQ
Back to top
View user's profile Send private message Send e-mail
barryd
Frequent Visitor


Joined: Mar 27, 2004
Posts: 285
Location: Cheshire, England

PostPosted: Mon Dec 06, 2004 12:04 am    Post subject: Reply with quote

lbendlin wrote:
You're not opening and closing the port every second, are you?

I did call myself a "complete novice" at comms programming :D
It did strike me as odd to be opening the port for each read, but who was I to question it? I've now done it properly, and it's been running for over 15 minutes without problem. Thanks again for all your help.
_________________
Barry Davies
Back to top
View user's profile Send private message







Posted: Today    Post subject: Pocket GPS Advertising

Back to top
Display posts from previous:   
Post new topic   Reply to topic    Pocket GPS World Forum Index -> Advanced GPS Lounge All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Make a Donation



CamerAlert Database

Click here for the PocketGPSWorld.com Speed Camera Database

Download Speed Camera Database
22.053 (15 May 24)



WORLDWIDE SPEED CAMERA SPOTTERS WANTED!

Click here to submit camera positions to the PocketGPSWorld.com Speed Camera Database


12mth Subscriber memberships awarded every week for verified new camera reports!

Submit Speed Camera Locations Now


CamerAlert Apps



iOS QR Code






Android QR Code







© Terms & Privacy


GPS Shopping