Solved

VB5 GPS and serial data

Posted on 1998-07-28
7
379 Views
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?
0
Comment
Question by:dragabyte
  • 3
  • 3
7 Comments
 
LVL 14

Expert Comment

by:waty
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.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1466922
dragabyte,
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?
Regards
Dalin
0
 

Author Comment

by:dragabyte
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Expert Comment

by:Dalin
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..

Regards
Dalin
0
 

Author Comment

by:dragabyte
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.

0
 
LVL 9

Accepted Solution

by:
Dalin earned 300 total points
ID: 1466926
dragabyte,
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
                DoEvents
                'Time out, I use 5 seconds here, change accordingly
                If Timer - lTime > 5 Then Exit Do
            Loop
       
    Else
       
        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

fReadCOMErrHandler:
   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

fSendComErrHandler:
    If Err.Number = 68 Then
            MsgBox "Could not communicate with COM port! Forcing system state into a 'Stopped' state."
            'lProcessCall = fSetSystemState(gcState_Stop)
        Else
            ' Force it to continue        Resume Next
           
         End If
   
    Err.Clear
    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



0
 

Author Comment

by:dragabyte
ID: 1466927
Thanks that worked well
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now