| By Deanne M. Chance | Article Rating: |
|
| February 19, 2006 12:30 PM EST | Reads: |
20,321 |
We begin this article by asking the question: Why would you want to integrate real-time GPS data into your PowerBuilder applications anyway? After all, it's not likely you are going to connect a GPS receiver to your desktop computer and ask yourself where you are currently located. (At least I hope not!)
More likely, you will be utilizing some sort of field service application where you need to know how to get from point A to point B, for example, an insurance assessor who needs to know how to get to the next accident site. For this, the user might use a tablet PC connected to a GPS receiver with some sort of integrated mapping solution. However, as PowerBuilder programmers, how are we to write such applications? Currently, unlike PocketBuilder, there is no built-in support for hardware devices such as GPS receivers. That being said, we will go about the task of "rolling our own" and integrating it with Microsoft MapPoint 2004 to create an application that can plot your location on a map as a function of your current position.
In order to complete this exercise you will need the following:
- A GPS receiver (the Pharos Bluetooth GPS receiver is used in this example)
- Microsoft MapPoint 2004
- PowerBuilder 9.x
- Ian Thain's NMEA parser (look on CodeExchange in the special hardware section)
- Some time to learn!
- Write the serial communications necessary to communicate with your Bluetooth GPS receiver
- Understand the basics of the NMEA protocol and the primary sentence returned by the receiver
- Parse the NMEA messages returned by the GPS receiver
- Convert the latitude and longitude returned by the receiver to decimal degrees (this is necessary for interfacing with MapPoint.)
- Use Microsoft MapPoint 2004 to plot your current latitude and longitude on a map
Now, how to create it!
Step 1: Make sure you, your computer, and GPS receiver are in an area where you can get decent satellite coverage. Outside is best, but probably not practical, so try near a window. If you are using Bluetooth, you have about 30 feet to play with in regards to the location of your GPS receiver and computer.
Note, for an excellent explanation of how GPS receivers work, see http://electronics.howstuffworks.com/gps.htm.
Step 2: Create a main window and drop a Microsoft MapPoint control on it. Add a button for the purpose of retrieving the GPS data and plotting your position on the map as a function of your current coordinates. Initialize the control with the following code:
ioo_Map = ole_MapControl.Object.NewMap(1)
ole_MapControl.Object.Units = 1
The first statement assigns an instance variable to a new occurrence of the map. In this case, we are specifying the map of North America. We will use the instance variable later as a "pointer" to perform more operations on the control. The second line specifies that we would like our units to be interpreted as kilometers. This is necessary since the GPS receiver will return the current altitude in meters.
Step 3: Declare the global external function prototypes for performing the serial I/O necessary to "talk to" your GPS receiver. You might be wondering why not just use the built-in PowerBuilder I/O functions, for example, FileOpen and FileRead? The underlying reason is that PowerBuilder will buffer the data for you (on top of the native buffering that the OS provides). That can be problematic for serial I/O devices. That is why we are using the kernel calls. Here are their prototypes.
- Function Long CreateFile(ref string lpszName, long fdwAccess, long fdwShareMode, long lpsa, long fdwCreate, long fdwAttrsAndFlags, long hTemplateFile) Library "Kernel32.dll"
- Function Long CloseHandle(Long hObject) Library "Kernel32.dll"
- Function Long ReadFile(Long hFile, ref string lpBuffer, long nBytesToRead, ref Long & nBytesRead, Long lNull) Library "Kernel32.dll"
- Function Long WriteFile(Long hFile, ref string lpBuffer, long nBytesToWrite, ref Long & nBytesWritten, LONG lNull) Library "Kernel32.dll"
- Boolean wf_detect_bt() (see Listing 1)
- Boolean wf_close_bt() (see Listing 2)
- Boolean wf_write_gps() (see Listing 3)
- Boolean wf_read_gps (see Listing 4)
- String wf_get_token(ref string as_string, string as_token) (see Listing 5)
The next order of business is to see how Ian Thain wrote his object to go about parsing a particular NMEA stream. For that, all we have to do is look at the format of an example sentence. Since our code picks off GGA, essential fix data that provide 3D location and accuracy data, we will look at that. Here is a sample:
$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
Where:
GGA Global Positioning System Fix Data
123519 Fix taken at 12:35:19 UTC
4807.038,N Latitude 48 deg 07.038' N
01131.000,E Longitude 11 deg 31.000' E
1 Fix quality: 0 = invalid
1 = GPS fix (SPS)
2 = DGPS fix
3 = PPS fix
4 = Real Time Kinematic
5 = Float RTK
6 = estimated (dead reckoning) (2.3 feature)
7 = Manual input mode
8 = Simulation mode
08 Number of satellites being tracked
0.9 Horizontal dilution of position
45.4,M Altitude, Meters, above mean sea level
46.9,M Height of geoid (mean sea level) above WGS84
ellipsoid
(empty field) time in seconds since last DGPS update
(empty field) DGPS station ID number
What you can see from this example is that the data is comma-delimited. This makes it a prime candidate for easy parsing by storing it in an external DataWindow using the ImportString function. To get at the individual elements, we only need to index them by their position within the DataWindow.
Published February 19, 2006 Reads 20,321
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Deanne M. Chance
Ms. Chance graduated in 1996 with a degree in computer science from the University of Illinois. She has been a frequent contributor to the PowerBuilder Developer's Journal and gave a key presentation at Sybase TechWave 2005 entitled "A Real-Time Physical Inventory Solution Using PocketBuilder ASA and a WiFi Connection." She has held several engineering positions, starting a career at Motorola where she focused on mobile I.P. by doing real-time embedded programming for the base radio controller group as part of the iDEN/Nextel project.
![]() |
josen30308 05/06/09 07:38:00 PM EDT | |||
I just got a simple question. wich is the code NMEA and where am I supposed to put this code? sincerely Jose |
||||
![]() |
SYS-CON Belgium News Desk 02/19/06 01:43:54 PM EST | |||
We begin this article by asking the question: Why would you want to integrate real-time GPS data into your PowerBuilder applications anyway? After all, it's not likely you are going to connect a GPS receiver to your desktop computer and ask yourself where you are currently located. (At least I hope not!) |
||||
![]() |
news desk 02/18/06 02:49:34 PM EST | |||
We begin this article by asking the question: Why would you want to integrate real-time GPS data into your PowerBuilder applications anyway? After all, it's not likely you are going to connect a GPS receiver to your desktop computer and ask yourself where you are currently located. (At least I hope not!) |
||||
![]() |
SYS-CON Belgium News Desk 02/18/06 01:20:55 PM EST | |||
We begin this article by asking the question: Why would you want to integrate real-time GPS data into your PowerBuilder applications anyway? After all, it's not likely you are going to connect a GPS receiver to your desktop computer and ask yourself where you are currently located. (At least I hope not!) |
||||
- SQL Anywhere Server and AJAX
- PowerBuilder Top Feature Picks
- The Difference Between Web Hosting and Cloud Computing
- PowerBuilder 12 and .NET
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Migrating Legacy Client/Server PowerBuilder Apps
- Why SOA Needs Cloud Computing - Part 1
- PowerDesigner 15: Expanding Data Modeling into Your Enterprise
- Five Reasons to Choose a Private Cloud
- PowerBuilder and .NET: Development Strategy
- SQL Anywhere Server and AJAX
- PowerBuilder Top Feature Picks
- The Difference Between Web Hosting and Cloud Computing
- PowerBuilder 12 and .NET
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- SYS-CON's iPhone Developer Summit Day One ROCKS
- A Review of Key PDF and Font Concepts
- Migrating Legacy Client/Server PowerBuilder Apps
- New Features in PowerBuilder 11.5
- New Features in PowerBuilder 11.5
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App





































