The MP3car.com Store The MP3car.com Store    

Sponsored links

Go Back   MP3Car.com > Mp3Car Technical > Software & Software Development > Coders Corner

Reply
 
LinkBack Thread Tools Display Modes
Old 08-06-2006, 06:33 PM   #1
Variable Bitrate
 
kamikaze2112's Avatar
 
Join Date: Feb 2005
Location: Barrie Ontario
Posts: 405
VB6 serial port help

I'm trying to figure out how to get the proper data off the serial port from my GPS adapter. I'm using xPort to split my GPS into 3 virtual coms, 1 for iGuidance, one for netstumbler, and one for my frontend. All i really want is speed and bearing, so I can have a basic compass in my front end all the time.

Now I know what part of the NMEA sentence I need, but I'm having trouble getting the sentences into VB in a consistant form. I can see the data that I need in the status bar in xPort, but I'm getting alot of garbage and | characters in my input stream.

I can zip up my test app that i wrote and attach it if someone wants to take a look at it.

any help is appreciated.

Trevor
__________________
1999 Pontiac Sunfire

New CarPC on it's way! Check out my worklog for details ;)
kamikaze2112 is offline   Reply With Quote
Advertisement
 
Advertisement
Sponsored links

Old 08-07-2006, 02:40 AM   #2
Newbie
 
Join Date: Jun 2006
Posts: 30
Hi Trevor,

are you converting the data properly? ie; if Bytearray is passed, you would either have to deal with it in bytes or convert it into String. If you upload your file, I can have a quick look.

Rana
RanaUK is offline   Reply With Quote
Old 08-07-2006, 07:07 AM   #3
Confusion Master
 
Enforcer's Avatar
 
Join Date: Sep 2003
Location: If you go down to the woods today, You're sure of
Posts: 10,223
Here is where I got the code to dismantle to get the info I want.

http://www.developerfusion.co.uk/show/5426/
Enforcer is offline   Reply With Quote
Old 08-07-2006, 09:09 AM   #4
Raw Wave
 
Laidback's Avatar
 
Join Date: Oct 2003
Location: Madrid
Posts: 1,982
I presume you've checked your code without using xport?
__________________
Laidback

Laidback Carputer
Laidback is offline   Reply With Quote
Old 08-07-2006, 09:19 AM   #5
FreeDrive Creator
 
CdRsKuLL's Avatar
 
Join Date: Feb 2004
Location: Manchester
Posts: 3,197
pulled from RR source

Code:
Public Sub ReadGPS() Static Ltry As Double 'Last Time we tried to reconnect GPS Static Buff As String 'Buffer of Data Dim NB As Long 'Number of Bytes Dim b() As Byte 'Array of Bytes Dim DT() As String 'GPS Fields Dim sData As String 'Temp GPS Data On Error Resume Next 'Prevention -- Issue posted by Arathranar If Hibernated Then Exit Sub 'If MM running If MMRunning Then Buff = frmMM.MM.Custom("GetNMEA|GGA", "D3Request") + vbCrLf Buff = Buff + frmMM.MM.Custom("GetNMEA|RMC", "D3Request") + vbCrLf GoTo ProcGPSData End If 'If nothing to do If GPSPort = 0 Then Exit Sub 'Try to read bytes NB = CommRead(GPSPort, b, 1024) 'If Got Data If NB > 0 Then Buff = Buff + StrConv(b, vbUnicode) ProcGPSData: NB = InStr(1, Buff, Chr(10), vbBinaryCompare) 'while there are complete lines While NB > 0 'Get Line of Data sData = Left(Buff, NB - 1) 'Adjust Buffer Buff = Mid(Buff, NB + 1) 'Process Line of Data If Left(sData, 1) = "$" Then DT = Split(sData, ",") Select Case DT(0) Case "$GPRMC" 'Get Lat, Long, Speed and Heading GPS.Lat = CDbl(Left(DT(3), InStr(1, DT(3), ".") - 1)) GPS.Lon = CDbl(Left(DT(5), InStr(1, DT(5), ".") - 1)) If CommaSys Then 'Prepare for Conversions If CommaSys Then DT(3) = Replace(DT(3), ".", ",") If CommaSys Then DT(5) = Replace(DT(5), ".", ",") If CommaSys Then DT(7) = Replace(DT(7), ".", ",") If CommaSys Then DT(8) = Replace(DT(8), ".", ",") 'Get Lat/Long GPS.Lat = GPS.Lat \ 100# + (CDbl(Mid(DT(3), InStr(1, DT(3), ",") - 2)) / 60#) GPS.Lon = GPS.Lon \ 100# + (CDbl(Mid(DT(5), InStr(1, DT(5), ",") + -2)) / 60#) Else GPS.Lat = GPS.Lat \ 100# + (CDbl(Mid(DT(3), InStr(1, DT(3), ".") - 2)) / 60#) GPS.Lon = GPS.Lon \ 100# + (CDbl(Mid(DT(5), InStr(1, DT(5), ".") + -2)) / 60#) End If If DT(4) = "S" Then GPS.Lat = -GPS.Lat If DT(6) = "W" Then GPS.Lon = -GPS.Lon GPS.speed = CDbl(DT(7)) GPS.HDG = CInt(DT(8)) Case "$GPGGA" 'Get Altitude and Sat Count If CommaSys Then DT(9) = Replace(DT(9), ".", ",") GPS.Alt = CDbl(DT(9)) GPS.SATS = CInt(DT(7)) GPS.Valid = (Val(DT(6)) > 0) End Select End If 'Check for more lines NB = InStr(1, Buff, Chr(10), vbBinaryCompare) Wend 'Reset Timeout Timer Ltry = Timer Else 'Didn't get any data in 10 seconds (Problem ?) 'Try to reconnect GPS If Timer - Ltry > 10 And MMRunning = False And CurSCR <> "destinator_gps.skin" Then GPS.Valid = False 'Close Port CommClose GPSPort 'Give O.S. processing time Sleep 1 'Try to Re-open it CommOpen GPSPort, "\\.\COM" + CStr(GPSPort), "baud=4800 parity=N data=8 stop=1" CommSetLine GPSPort, 2, True 'Data Terminal Ready ON (in case) Ltry = Timer End If If Ltry > Timer Then Ltry = Timer End If End Sub

might be of some help :-)

CdR
__________________
www.extremeoc.co.uk me building a murcielago kitcar ! - check it out !
www.cellsecurity.co.uk are my new employer ! - yeah I got a job !
CdRsKuLL is offline   Reply With Quote
Old 08-07-2006, 09:25 AM   #6
Confusion Master
 
Enforcer's Avatar
 
Join Date: Sep 2003
Location: If you go down to the woods today, You're sure of
Posts: 10,223
Laidback, you're still about then?
Enforcer is offline   Reply With Quote
Old 08-07-2006, 02:22 PM   #7
Variable Bitrate
 
kamikaze2112's Avatar
 
Join Date: Feb 2005
Location: Barrie Ontario
Posts: 405
hey, thanks for the replies.

This is the first time I've ever tried anything regarding the serial port, so what I came up with is not very fancy. It was stuff i found with google here and there, and kinda molded into something that i thought would work, so please bear with me.

I've attached my little test program which basically takes whatever is in the input buffer and using the split function splits it into words() using a comma as the delimiter. If words(0) = "$GPRMC" then it takes words(7) and converts it from knots to km/h and puts it in a textbox, and words(8) (bearing) in another box. I have the MsComm control set to Com10 as that's the com i set aside for it on xPort, it can be changed in the properties of the control. Clicking the start/stop button simply sets the mscomm1.portopen property to true or false.

I'm pretty sure it's not the right way to go about this, but it's very simple and i came up with it in about an hour. I don't know how else I can test my program, and I know very little about serial programming.

Thanks for the help
Attached Files
File Type: zip Project1.zip (2.4 KB, 105 views)
__________________
1999 Pontiac Sunfire

New CarPC on it's way! Check out my worklog for details ;)
kamikaze2112 is offline   Reply With Quote
Old 08-07-2006, 02:55 PM   #8
Variable Bitrate
 
kamikaze2112's Avatar
 
Join Date: Feb 2005
Location: Barrie Ontario
Posts: 405
Quote: Originally Posted by Enforcer
Here is where I got the code to dismantle to get the info I want.

http://www.developerfusion.co.uk/show/5426/

The class file in the zip on the above page was really what I was looking for in the first place, but couldn't find anything. I'd still like to see if what I wrote is going to work with little modification, but if not I can just use the class file
__________________
1999 Pontiac Sunfire

New CarPC on it's way! Check out my worklog for details ;)
kamikaze2112 is offline   Reply With Quote
Old 08-09-2006, 02:24 PM   #9
Raw Wave
 
Laidback's Avatar
 
Join Date: Oct 2003
Location: Madrid
Posts: 1,982
Quote: Originally Posted by Enforcer View Post
Laidback, you're still about then?

Of course, an enforced holiday from broadband, a stuffed mother board and a new house needing plenty of work but I still stick my nose in now & again. :-)
__________________
Laidback

Laidback Carputer
Laidback is offline   Reply With Quote
Old 08-09-2006, 05:17 PM   #10
Confusion Master
 
Enforcer's Avatar
 
Join Date: Sep 2003
Location: If you go down to the woods today, You're sure of
Posts: 10,223
did you send your broadband a postcard
Enforcer is offline   Reply With Quote
Old 08-11-2006, 12:34 PM   #11
Variable Bitrate
 
DeltaFX's Avatar
 
Join Date: Sep 2004
Location: France
Posts: 401
Why not intercept the $GPVTG sentence, which gives you speed in BOTH Mph and km/h ? (This sentence is optional on certain GPS units)

You could use AsyncPro components to deal with serial com.
__________________
Now Galileo is real. Muhahahahaha :p
DeltaFX is offline   Reply With Quote
Sponsored links
Advertisement
 
Advertisement
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
serial port to game port adapter wiring asif General Hardware Discussion 5 08-17-2006 04:47 PM
GPS usb-> serial port zerocover GPS 10 10-07-2005 12:08 AM
Command-line serial port logger..?? tj!2k4 GPS 11 09-23-2005 10:56 AM
serial port switch input th3madc0w Hardware Development 5 01-04-2005 04:27 AM
IR serial port receivers Fusion-One Input Devices 3 08-07-2003 05:49 PM


All times are GMT -5. The time now is 09:03 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 1999 - 2008 Mp3Car.com Inc.Ad Management by RedTyger
Message Board Statistics