VB5 GPS and serial data

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?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

DalinConnect With a Mentor Commented:
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

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.
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?
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

dragabyteAuthor Commented:
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.
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..

dragabyteAuthor Commented:
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.

dragabyteAuthor Commented:
Thanks that worked well
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.