[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1009
  • Last Modified:

MSComm and GPS

Trying to gather information from a Garmin GPS III+ using the MSComm control in Visual Basic.

After many futile attemps on my own, I'd appreciate it if someone could post sample code that would retrieve standard com port data and display it in a text box. I'm not sure if there are any special parameters for GPSs or not.

If anyone has gotten further than this (actually interpreting the GPS data) that would be also appreciated. But I have to walk before I can run.

0
rgroves
Asked:
rgroves
  • 7
  • 6
  • 2
1 Solution
 
VBGuruCommented:
check out
http://codeguru.developer.com/network/commspy.shtml



Some Funde from the help file
1. MSComm control has many important properties, there are a few that you should be familiar with first.

Properties      Description
CommPort      Sets and returns the communications port number.
Settings            Sets and returns the baud rate, parity, data bits, and stop bits as a string.
PortOpen      Sets and returns the state of a communications port. Also opens and closes a port.
Input            Returns and removes characters from the receive buffer.
Output            Writes a string of characters to the transmit buffer.

2. The MSComm control provides the following two ways for handling communications
      2.1 Event-driven communications is a very powerful method for handling serial port interactions. In many situations you want to be notified the moment an event takes place, such as when a character arrives or a change occurs in the Carrier Detect (CD) or Request To Send (RTS) lines. In such cases, use the MSComm control's OnComm event to trap and handle these communications events. The OnComm event also detects and handles communications errors. For a list of all possible events and communications errors, see the CommEvent property.

      2.2 You can also poll for events and errors by checking the value of the CommEvent property after each critical function of your program. This may be preferable if your application is small and self-contained. For example, if you are writing a simple phone dialer, it may not make sense to generate an event after receiving every character, because the only characters you plan to receive are the OK response from the modem.

Exmple
---------
In this project have the mscomm control and the text box. I assume there is another device sensding the data on com port1 with the default settings for the above said property.
Then copy paste the following code. It should work for you. I am using the Event-driven communication.

Option Explicit

Private Sub Form_Load()
MSComm1.RThreshold = 1                  'Get the OnComm event triggered as soon as a charcter comes
MSComm1.SThreshold = 1
MSComm1.InputLen = 1
End Sub

Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
    ' Handle each event or error by placing
    ' code below each case statement

    ' Errors
        Case comEventBreak  ' A Break was received.
        Case comEventCDTO   ' CD (RLSD) Timeout.
        Case comEventCTSTO  ' CTS Timeout.
        Case comEventDSRTO  ' DSR Timeout.
        Case comEventFrame  ' Framing Error
        Case comEventOverrun    ' Data Lost.
        Case comEventRxOver ' Receive buffer overflow.
        Case comEventRxParity   ' Parity Error.

        Case comEventTxFull ' Transmit buffer full.
        Case comEventDCB    ' Unexpected error retrieving DCB]

    ' Events
        Case comEvCD    ' Change in the CD line.
        Case comEvCTS   ' Change in the CTS line.
        Case comEvDSR   ' Change in the DSR line.
        Case comEvRing  ' Change in the Ring Indicator.
       
'USE THIS EVENT TO GET THE DATA
       
        Case comEvReceive   ' Received RThreshold # of
                                ' chars.
        Text1 = Text1 & MSComm1.Input               'Get the charcter and concatinate the charcter with the existing one.
       
       

       
       
       
        Case comEvSend  ' There are SThreshold number of
                            ' characters in the transmit
                            ' buffer.

        Case comEvEOF   ' An EOF charater was found in                              ' the input stream
    End Select

End Sub

Private Sub Text1_Change()

End Sub
0
 
VBGuruCommented:
Sorry please modify the form_load event like this

Private Sub Form_Load()
MSComm1.RThreshold = 1                  'Get the OnComm event triggered as soon as a charcter comes
MSComm1.SThreshold = 1
MSComm1.InputLen = 1
MSComm1.PortOpen                        'Open the port
End Sub

0
 
rgrovesAuthor Commented:
I haven't tried the code you wrote yet, but I've tried something very similar. What would be going on if every time I read the mscomm1.input, nothing was returned?

I know the device is connected because I've used other applications to upload to it. But it seems like the OnComm event is never triggered when I use it.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
dmagnusCommented:
Here is a URL that will provide you with everything you need to interpret the info coming from the Garmin...
http://www.joe.mehaffey.com/
0
 
rgrovesAuthor Commented:
That site's got a ton of great info--but i haven't had much luck in finding sample code there.
0
 
dmagnusCommented:
They have programs that you can download to "talk" to the Garmin.  I was referring to the tables of information on how to interpret the data received.  Don't have my Garmin at work right now, but I'll try the above sample code using the mscomm ctl.  One thing to check:  what output mode do you have set on the Garmin?  usually there are something like NMEA/NMEA or GRMN/GRMN, etc.  There might be one that is NMEA/HOST or something like that.  Also the baud rate is 4800 I believe.
0
 
rgrovesAuthor Commented:
I think that may have been my problem all along: I wasn't setting the GPS up for any output mode--I just plugged it into the serial port and turned it on.

I'll check the documentation for output modes.
0
 
dmagnusCommented:
I was wrong.  Baud rate is 9600
Here's a good page for understanding the protocol:
http://vancouver-webpages.com/pub/peter/grmnprot.html
0
 
rgrovesAuthor Commented:
That GRMN protocal which is 9600 is for the proprietary Garmin protocal--not NMEA which 3rd parties frequently used. So if I use the NMEA protocol, should that always be 4800 bps?

I found how to set all the interface settings in the manual.

Does anyone know if data will be transferred when the GPS is in Simulator mode?

0
 
dmagnusCommented:
Yes, that's the way I usually test mine.  You need to set a start point and then go to the navigation page and enter a speed and direction so it starts moving somewhere - otherwise  you'll get the same position all the time.
I think the baud rate might be dependent on the NMEA protocol you use, but it's  probably 4800 bps...
The manual should also tell you what baud rate to use with each protocol..
0
 
rgrovesAuthor Commented:
The owner's manual is very sparse when it comes to serial communication. Maybe the MapSource (garmin's pc-software) manual will be more helpful.

Thanks for all the input so far. I'll award the points when i get home and try it out tonite.
0
 
dmagnusCommented:
If you don't mind, what are you trying to accomplish?  Do you have a specific application that you are developing?  Just curious.  I use my Garmin 90 for navigation in my small airplane, but love to just goof around with it and various software...
0
 
rgrovesAuthor Commented:
Basically, I'm trying to reinvent the wheel: write an app that tracks my trip and plots it on a street map.

My main goal is to be able to overlay other types of maps, such as radar maps, since I storm chase, and this would be an incredible asset. This means I'd need a way to coordinate lat/long points from map to map.
0
 
dmagnusCommented:
Check out www.teletype.com/gps  I bought software from them that runs on both the my Laptop/Desktop and my HP Jornada WinCE machine.  It has streets, highways, etc. and will display and save the track from your Garmin.  You can also load other types of maps.  The software is only about $100...  I believe they also have the stuff for coordinating the maps by lat/long...
0
 
rgrovesAuthor Commented:
Turns out the problem was the interface setting on the GPS unit, which needed to be set to NMEA.

But VBGuru answered the question I asked, so he gets the points.

Now....maybe someone can help me out with some parsing routines!

Thanks all!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now