Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


VB5 GPS and serial data

Posted on 1998-07-28
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


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 1200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

618 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