VB5 GPS and serial data

Posted on 1998-07-28
Last Modified: 2010-05-03
To All

I am starting a project that use GPS data through a serial port. I don't know what type of GPS unit will be used yet so I thought it may be possible to emulate this with a second computer linked through the serial ports. The remote computer could put out a stream of data through its port and the other will read. At the moment I only an need X,Y coordinate for the emulation. Any ideas?
Question by:dragabyte
  • 3
  • 3
LVL 14

Expert Comment

ID: 1466921
I think you could use the communication OCX from Microsoft on both part.

But for the moment, the better solution should writing a class for communication with serial port, and first of all, simulate it with some kind of files.

Expert Comment

ID: 1466922
Do you need help in transferring data via serial port or processing the data once it recieve from the port? Can you give a little more information?

Author Comment

ID: 1466923
I will using data coming into the serial port to drive a GIS program - that is - with the X,Y data I will draw a symbol on a Microstation drawing in global coords. All the drawing stuff is fine. I have a HP Palmtop that I could use as the simulated GPS unit or a Laptop, whatever. I am not quite sure what form the data will be streaming from the GPS but as a start I thought I would do the above while looking for info on the GPS data. There maybe a VB5 program already out there but I would need the code.
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.


Expert Comment

ID: 1466924
So you are looking for the data transfer via serial port.
Generally, you need to know the something about the way external device (GPS, in your case) is send data: is it binary or Ascii, what baudrate, databits, stopbit, parity, starting/ending characters....
In your VB program, you just need to drop a MSCOmm control, set the port, and set itsetting match that of the device, and then you can go read the data using
Dim lIndata as String
lIndata = Com1.Input

I have example code to read/send data through the comport, but you need to know the format of the incoming data and then put in the form for you to do the graphics.

I would be happy to help you further, if you can provide me with infor about want would be the format of incoming data and the format it need to be in.  The transfer part is not difficult..


Author Comment

ID: 1466925
I have a bit more detail now. The GPS unit will most probably be a Garmin. The data protocol is NMEA 0183, 4800 baud,8 bits,no parity,1 stop bit.


Accepted Solution

Dalin earned 300 total points
ID: 1466926
You can do some test like this, if you have two pC connected:

Have the first PC Send Data to the 2nd PC
On the First PC: Assume this is your PC to control the external device:

Drop a textBox to your form, set multiline to True and Scrollbar to both

Drop a MSComm control to your form, name it myComm; set port to 1, and setting to 4800,N,8,1

in the OnComm event of myComm (double click the icon will put you there, add the code:
Dim lstring as String

If myComm.CommEvent = MSComm_EV_Recieve then
       lString = fReadCom(myComm, false)
       text1 = text1 & lString & vbCRLF
   End if

Add a new Procedure to your  form:

Public Function fReadCOM(theComm As MSComm, WaitOrNot As Boolean, Optional EndCha As String) As String

'   Name:       fReadCOM
'   Author:     Dalin Nie
'   Written:    4/14/96
'   Purpose:

'       This function read one line of data from the RS-232 Com port;
'   Called procedures and functions:

'   Input:  theComm:  Name of the MSComm control which is connected to the port you want to read
'           Wait--Boolean
'                 True:  Keep reading the port until the EndCha is received or timed out
'                        Soutable for contineous recieveing until the endCha after a command is issued, and

'                 False: Just Read once, get whatever is in the put and then get out, suitable
                         ' for use with OnComm event
'            EndCha: the external devices ending characters, usually vbCR or vbCRLF, optional
'   Output: The string it read
Dim lInput As String
Dim lMessage As String
Dim curReading As Single
Dim lLastTwo As String
Dim I As Integer
Dim lTime As Long

On Error GoTo fReadCOMErrHandler

' Set up output of fReadCOM to be blank by default

'add number of lines you expect to read

lMessage = ""

'Get one Line of Data
If WaitOrNot = True Then
        lTime = Timer
        Do Until Right(lMessage, Len(lStRespEnd)) = lStRespEnd
                If theComm.InBufferCount > 0 Then
                        lInput = theComm.Input
                        lMessage = lMessage + lInput
                    End If ' If frmDeckLayout.Comm1.InBufferCount = dataLen
                'Time out, I use 5 seconds here, change accordingly
                If Timer - lTime > 5 Then Exit Do
        lMessage = theComm.Input
    End If
     ' strip the EndCha, if what we received is ended with the End Cha
   If Right(lMessage, Len(EndCha)) = EndCha Then
         lMessage = Left(lMessage, Len(lMessage) - Len(EndCha))
     End If
    fReadCOM = lMessage
    'Put the response to some textbox
    'frmMain.txtCaroResp = lMessage
Exit Function

   fReadCOM = "ERROR" & Err.Number & " " & Err.Description
   ' Oprional gui.

End Function

Now in your 2nd PC, (assume it is the external device),
Drop a textbox in the form, name it txtOut

Drop a command button, name it cmdSend, in the Click event, add
Dim lYesNo as Boolean
If txtOut.Text >"" then lTesNo = fSendCom(myComm, txtOut.text)

Drop a MSComm, name it myComm, do the same Setting.

Add a new Procedure to your form/module:

Public Function fSendCom(theComm As MSComm, theData As String, Optional StartCha As String, Optional EndCha As String) As Boolean

'   Name:       fSendCom
'   Author:     Dalin Nie
'   Written:    4/21/96
'   Purpose:    Send a command to a Instrument through the RS-232

'   Called procedures and functions:

'   Input:
'       theData     DataToBeSend to the Port

'   Output: True-- Successfuly send to the comm port
'           False -- Failed

Dim Temp As String
Dim lData As String

On Error GoTo fSendComErrHandler

    ' Add the Start/Ending Chars
    lData = STartChr & theData & EndCha
    'Ensure the port is Open
    If theComm.PortOpen = False Then
            theComm.PortOpen = True
        End If

      'Clear the Input buffer
      Temp = theComm.Input

      ' Send the Data
      theComm.Output = lData
      fSendCom = True

    Exit Function

    If Err.Number = 68 Then
            MsgBox "Could not communicate with COM port! Forcing system state into a 'Stopped' state."
            'lProcessCall = fSetSystemState(gcState_Stop)
            ' Force it to continue        Resume Next
         End If
    fSendCom = False

End Function

Now, run the 2nd PC first,
then run the 1st PC,
Type something in the 2nd pc's textbox, click send


Author Comment

ID: 1466927
Thanks that worked well

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now