Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: VB6 serial port help

  1. #1
    Variable Bitrate kamikaze2112's Avatar
    Join Date
    Feb 2005
    Location
    Barrie Ontario
    Posts
    406

    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


  2. #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

  3. #3
    Confusion Master
    Auto Apps:loading...
    Enforcer's Avatar
    Join Date
    Sep 2003
    Location
    If you go down to the woods today, You're sure of
    Posts
    14,585
    Here is where I got the code to dismantle to get the info I want.

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

  4. #4
    Raw Wave Laidback's Avatar
    Join Date
    Oct 2003
    Location
    Madrid
    Posts
    1,984
    I presume you've checked your code without using xport?

  5. #5
    FreeDrive Creator CdRsKuLL's Avatar
    Join Date
    Feb 2004
    Location
    Manchester
    Posts
    3,507
    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

  6. #6

  7. #7
    Variable Bitrate kamikaze2112's Avatar
    Join Date
    Feb 2005
    Location
    Barrie Ontario
    Posts
    406
    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 Attached Files


  8. #8
    Variable Bitrate kamikaze2112's Avatar
    Join Date
    Feb 2005
    Location
    Barrie Ontario
    Posts
    406
    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


  9. #9
    Raw Wave Laidback's Avatar
    Join Date
    Oct 2003
    Location
    Madrid
    Posts
    1,984
    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. :-)

  10. #10

Page 1 of 2 12 LastLast

Similar Threads

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •