MarshallSoft GPS Component
Library for Visual Basic
Programmer's Manual
(MGC4VB)
Version 2.0
July 26, 2007
This software is provided as-is.
There are no warranties, expressed or implied.
Copyright (C) 2007
All rights reserved
MarshallSoft Computing, Inc.
Post Office Box 4543
Huntsville AL 35815
Voice : 1.256.881.4630
web : www.marshallsoft.com
MARSHALLSOFT is a registered trademark of MarshallSoft Computing.
1 Introduction
1.1 Features2 Library Overview
1.2 Documentation Set
1.3 Example Program
1.4 Installation
1.5 Uninstalling
1.6 Pricing
1.7 Updates
2.1 Dynamic Link Libraries3 Compiler Issues
2.2 Keycode
2.3 Using the Library
2.4 MGC4VB Class
2.5 Dynamic Strings
2.6 Adding MGC4VB to Your Project
2.7 Error Display
3.1 Visual Basic Makefiles4 Example Programs
3.2 Compiling Programs
3.3 VB.NET and Visual Studio
3.4 Visual Basic for Applications (VBA)
3.5 Power Builder
4.1 MGCVER5 Revision History
4.2 HELLO
4.3 COMPUTE
4.4 CONVERT
4.5 LATLON
4.6 GPGGA
4.7 GPGLL
4.8 GPGSV
4.9 GPRMC
4.10 GPVTG
4.11 RAW
4.12 GGA_RMC
The MarshallSoft GPS Component for Visual Basic (MGC4VB) library is a powerful toolkit that allows software developers to quickly develop GPS applications in VB or VB.NET. The MarshallSoft GPS Component (MGC) is a library of functions providing direct and simple control of GPS data.
A straightforward interface provides the functionality to read and decode standard GPS (Global Positioning System) NMEA 183 sentences from the RS232 serial port as well as compute great circle distances and bearings.
The MarshallSoft GPS Component for Visual Basic library toolkit supports and has been tested with all Win32 versions of Microsoft Visual Basic (VB 4.0,VB 5.0 and VB 6.0) and Microsoft Visual Studio .NET (VB .NET). MGC4VB can also be used with Microsoft VBA (Visual Basic for Applications) such as EXCEL, ACCESS and WORD as well as with Power Builder.
A Win32 DLL (Dynamic Link Library) is provided. MGC4VB runs under all versions of Windows (Windows 95, Windows 98, Windows ME, Windows 2000, Windows 2003, Windows Vista, Windows NT and Windows XP). The MarshallSoft GPS Component DLL (MGC32.DLL) can also be used from any language (C/C++, Visual C++, .NET, Delphi, Visual FoxPro, COBOL, Xbase++, dBase, Cobol, etc.) capable of calling the Windows API. Since the MGC toolkits use the same DLL for all software languages, a developer can, for example, purchase MGC4VB and use the MGC DLL also with MGC4C (C/C++ version).
MGC4VB includes multiple Visual Basic and VB. NET example programs with full source. Several example programs are included that demonstrate using MGC functions to read and decode GPS data. Refer to Section 4 for more details on each of the example programs.
[PROGRAM] [DESCRIPTION]
MGCVER: Program that displays the MGC4C version & build numbers.
HELLO: Program similar to MGCVER but uses the MGC class fMGC.
GPRMC: Program that decodes GPRMC sentences.
GPGGA: Program that decodes GPGGA sentences.
GPGLL: Program that decodes GPGLL sentences.
GPGSV: Program that decodes GPGSV sentences.
GPVTG: Program that decodes GPVTG sentences.
RAW: Program that decodes all sentences.
LATLON: Program that graphically displays latitude & longitude.
COMPUTE: Computes distances and bearings.
CONVERT: Converts between (deg,min,min/1000), (deg,min,sec), etc.
GGA_RMC: Program that decoded GPGGA & GPRMC sentences.
Our goal is to provide a robust GPS communications library that you and your customers can depend upon. Contact us if you have any questions.
The evaluation and registered versions are identical except that the evaluation version displays the evaluation (SW_Info) screen. The evaluation version can be used for 60 days.
When comparing the MarshallSoft GPS Component library toolkit against our competition, note that:
Some of the many features of the MarshallSoft GPS Component (MGC) library toolkit are:
The complete set of documentation consists of three manuals in three formats. This is the first manual (MGC4VB) in the set.
Each manual comes in three formats:
The MGC_4VB Programmer's language specific (Visual Basic) manual and provides information needed to install and compile example programs in a Visual Basic environment. Read this manual first.
The MGC User's Manual (MGC_USR) discusses GPS in general as well as language independent programming issues such as application notes, purchasing and licensing. Read this manual second.
The MGC Reference Manual (MGC_REF) contains details on each individual MGC function.
Use Microsoft Word or Microsoft WordPad to print the document files. The online documentation can be accessed on the MarshallSoft GPS Component for Visual Basic product page at:
http://www.marshallsoft.com/vb-gps-toolkit.htm
The following example code segment demonstrates the use of some of the MarshallSoft GPS Component library toolkit functions:
Code = mgcAttach(MGC_KEY_CODE)
If Code < 0 Then
MsgBox "ERROR: Cannot attach. Check MGC_KEY_CODE."
End
End If
' open port
Code = mgcOpen(ThePort)
If Code < 0 Then
MsgBox "ERROR: Cannot open port."
Exit Sub
End If
' port successfully opened, set sentence type (GPGGS) wanted
Code = mgcSetInteger(MGC_SET_SENTENCE_TYPE, MGC_SENTENCE_GPGGA)
While True
' lock data buffer
Code = mgcLockData(1)
' get GPGGA sentence
RefCount = mgcGetData(GPGGA_UTC_TIME, DataBuffer)
If (RefCount < 0) And (RefCount <> MGC_NO_DATA) Then
MsgBox "ERROR: " + Str$(RefCount)
Exit Sub
End If
' 1st time seen this data ?
If RefCount = 1 Then
' get (coded) latitude (assume North in this example)
iCoded = mgcLatitude()
' compute components
LatDeg = mgcDecodeDeg(iCoded)
LatMin = mgcDecodeMin(iCoded, LatDeg)
LatSec = mgcDecodeSec(iCoded, LatDeg, LatMin)
'
' display result as desired ...
'
End If
' unlock data buffer
Code = mgcLockData(0)
Wend
Code = mgcClose()
Code = mgcRelease()
In the example program above, the serial port is opened and latitude is continuously read. The latitude components (degrees, minutes, and thousands of a minute) are then computed for display. See the MGC User's Manual (MGC_USR) for details on the various latitude/longitude component descriptions.
This example code segment was taken from the LATLON example program.
Refer to the MGC Reference Manual (MGC_REF) for individual function details.
Note that the Windows registry is not modified.
Uninstalling MGC4VB is very easy. MGC does not modify the registry.
First, run UINSTALL.BAT, which will delete MGC32.DLL from your Windows directory, typically C:\WINDOWS for Windows 95/98/Me/XP/2003/Vista or C:\WINNT for Windows NT/2000.
Second, delete the MGC project directory created when installing MGC4VB.
A developer license for the MarshallSoft GPS Component library can be purchased for $115 (or $195 with source code [Ansi C] to the library DLL). Purchasing details can be found in Section 1.4, "How to Purchase", of the MGCC User's Manual (MGC_USR). (http://www.marshallsoft.com/mgc_usr.htm#Section_1.4)
Also see INVOICE.TXT or http://www.marshallsoft.com/order.htm
Registration includes one year of free downloadable updates.
After one year, the developer license must be updated to be able to download updates. The developer license can be updated for $30 if ordered within one year of the original purchase (or previous update). From one year to three years, licenses can be updated for $55. After 3 years, licenses can be updated for $75. These updates do not include source code. Source code can be updated for $50 in addition to the cost of the update ($30, $55 or $75).
Note that the registered DLL does not expire.
Also see file UPDATES.TXT.
The MarshallSoft GPS Component Library (CSC) is implemented as a Win32 dynamic link library (DLL). A DLL is characterized by the fact that it need not be loaded until required by an application program and that only one copy of the DLL is necessary regardless of the number of application programs that use it. Contrast this to the traditional static library that is bound to each and every application that uses it at link time.
An important advantage that DLL's have over other "popular" library formats such as VBX or OCX is that DLL's are callable by all Windows applications. Since DLL's are the building blocks of the Windows Operations System, they will not be replaced by a "newer technology".
MGC32.DLL has a keycode encoded within it. Your keycode is a 9 or 10-digit decimal number (unless it is 0), and will be found in the file KEYCODE.BAS and KEYCODE.VB. The keycode for the evaluation version is 0. You will receive a new key code when registering. During SETUP, the keycode is copied to the \APPS sub-directory.
If the error message (value -74) is received when calling mgcAttach, it means that the keycode in your application does not match the keycode in the DLL. After registering, it is best to remove the evaluation version of MGC32.DLL from the Windows search path.
The MarshallSoft GPS Component Library for Visual Basic has been tested on multiple computers running Windows 95/98/Me/XP/Vista/2003 and Windows NT/2000.
The MGC4VB library has also been tested with all versions of Microsoft Visual Basic and Microsoft Visual Studio .NET. MGC4VB can also be used with Visual Basic for Applications (VBA) such as Microsoft Office, Excel, and Access as well as with Power Builder.
The SETUP installation program will copy the Lib's and DLL to your Windows directory.
The MGC class "mgcClass" (mgcClass.cls) is a Visual Basic class wrapper for making calls to MGC32.DLL. The class name for each function is the same as the DLL function except the leading "mgc" is replaced by "f".
Those functions that return strings do so by use of the GetDataBuffer property. Instantiate mgcClass as any other class in Visual Basic:
Dim C As New mgcClass
Also refer to the MarshallSoft GPS Component Reference Manual (MGC_REF), the example project "HELLO" and the file mgcClass.cls.
The use of mgcClass is limited to Visual Basic 5.0 and above since previous versions of Visual Basic do not support classes.
The Visual Basic language uses a technique known as "garbage collection" to manage string space at runtime and may be called internally at any time by the Visual Basic runtime, asynchronous to what you may be doing in your code.
When passing a string buffer to a DLL function into which text will be copied, it is strongly recommended that the local string be allocated immediately before use. For example, a string buffer is passed to the user defined dllGetMessage function , which copies a text message into it. Note that SPACE$(80) is called immediately before dllGetMessage.
Dim Code As Integer
Dim Buffer As String * 80
' allocate buffer just before call to dllGetMessage
Buffer = SPACE$(80)
' copy message into 'Buffer'
Code = dllGetMessage(Buffer, 80)
' message text is now in 'Buffer'
This technique is not necessary for passing a string to a DLL function, only when passing a buffer to a DLL into which data is to be placed by the DLL function.
Copy MGC32.BAS (if running VB_4.0 /5/6), or MGC32.VB (if running VB.Net) into the same directory (folder) as the application program to which you want to add MGC code. You will find these files in the APPS sub-directory (folder) created when you ran SETUP, usually C:\MGC4VB\APPS.
Open your existing project with "File", "Open Project". Then choose "Insert", "Module", then add MGC32.BAS and KEYCODE.BAS to your project. If prompted to add "DAO 2.50 Object Library", choose "no".
MGC functions can now be called from your VB program.
Open your existing project with "File", "Open Project". Then choose "Project", "Add Module", then add MGC32.VB and KEYCODE.VB to your project. MGC functions can now be called from your VB.NET program.
The error message text associated with MGC error codes can be displayed by calling mgcErrorText.
Function GetErrorText(ByVal ErrorCode As Long) As String
Dim Code As Long
Dim Text As String * 128
Code = mgcErrorText(ErrorCode, Text)
If Code > 0 Then
GetErrorText = Text
Else
GetErrorText = "Error code " + LTrim$(Str$(ErrorCode))
End If
End Function
The Marshall GPS Component for Visual Basic component library supports and has been tested with all versions of Microsoft Visual Basic (VB3, VB 4, VB 5, VB 6 and VB.NET).
Project files for 32-bit Visual Basic end with ".VBP". Projects for VB.Net end with ".vbproj".
Choose "File", then "Open Project" from the main Visual Basic menu.
When saving the example programs in VB version 5.0 or VB 6.0 format, answer "no" if asked to add the "Microsoft DAO v2.5 library".
Compile and run MGCVER as the first example. MGCVER should display the version number from MGC32.DLL.
There are a few differences between VB 4/5/6 and VB.NET / Visual Studio that affect writing programs that use MGC.
Dim Buffer As String
Buffer = Space(80)
Code = mgcGetString(0, MGC_GET_REGISTRATION, Buffer, 80)
The MarshallSoft GPS library can be used with Microsoft VBA applications such as EXCEL, ACCESS, and Microsoft Office.
Start EXCEL (or other 32-bit Office VBA program such as WORD or ACCESS), then enter design mode. Enable the "Controls Toolbox", choose "Tools" on the menu bar, then "Customize", and then check "Control Toolbox". From the control toolbox, choose and position a "Command Button". This will create code that looks like
Private Sub CommandButton1_Click()
End Sub
Replace the generated code with MODULE32.BAS. The easiest way to do this is to paste from the clipboard.
Exit design mode and then press the command button to start the VBA example program.
MGC can also be used with 32 bit Power Builder applications. See PBUILDER.TXT in the \APPS subdirectory for more information.
CSC32.PBI : Power Builder declaration file.
Several example programs are included in MGC4VB. There is also an example program (HELLO), which uses the VB class "mgcClass", but requires VB 5 or VB 6 (which support classes).
Example programs are located in the \APPS sub-directory created by SETUP.
The first example program is the program MGCVER (MGC Version) that displays the MGC library version number and registration string. Its purpose is display the MGC version, build, and registration string as well as to verify that MGC32.DLL is being found and loaded by Windows.
The project files are:
MGCVER.VBP : for (32-bit) VB 4.0 and above.
MGCVER.VBPROJ : for VB.Net.
The HELLO example program is similar to MGCVER except that it uses the MGC class mgcClass.cls. See mgcClass.cls. Visual Basic 5 or above is required for programs using VB classes.
COMPUTE is a Visual Basic program that computes great circle distances and bearings from a pair of latitude/longitude values.
The project files are:
COMPUTE.VBP : for (32-bit) VB 4.0 and above.
COMPUTE.VBPROJ : for VB.Net.
CONVERT is a Visual Basic program that converts latitude (or longitude) between (deg, min, min/1000), (deg, min, sec), and single integer encoding.
The project files are:
CONVERT.VBP : for (32-bit) VB 4.0 and above.
LATLON is a VB example program that continuously displays latitude and longitude .
The project files are:
LATLON.VBP : for (32-bit) VB 4.0 and above.
LATLON.VBPROJ : for VB.Net.
GPGGA is a VB program that displays all NMEA GPGGA sentences.
The project files are:
GPGGA.VBP : for (32-bit) VB 4.0 and above.
GPGGA.VBPROJ : for VB.Net.
GPGLL is a VB program that displays all NMEA GPGLL sentences.
The project files are:
GPGGL.VBP : for (32-bit) VB 4.0 and above.
GPGSV is a VB program that displays all NMEA GPGSV sentences.
The project files are:
GPGSV.VBP : for (32-bit) VB 4.0 and above.
GPRMC is a VB program that displays all NMEA GPRMC sentences.
The project files are:
GPRMC.VBP : for (32-bit) VB 4.0 and above.
GPVTG is a VB program that displays all NMEA GPVTG sentences.
The project files are:
GPVTG.VBP : for (32-bit) VB 4.0 and above.
RAW is a VB program that displays all NMEA sentences.
The project files are:
RAW.VBP : for (32-bit) VB 4.0 and above.
RAW.VBPROJ : for VB.Net.
The MarshallSoft GPS Component DLL (MGC32.DLL) is written in ANSI C. All language versions of MGC (C/C++, Delphi, Visual Basic, PowerBASIC, etc) use the same identical DLL.
Version 1.2: February 7, 2003.
Version 1.3: August 9, 2004
Version 1.4 March 3, 2005
Version 2.0: July 26, 2007
The "Coded Integer" angles returned by MGC functions are now returned in units of hundred-thousandths of a degree rather than thousandths of a minute.