Sybase Mobile Evangelist

Ian Thain

Subscribe to Ian Thain: eMailAlertsEmail Alerts
Get Ian Thain: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

PowerBuilder: Article

Where Am I and Can I Take a Picture of It?

Pocket PowerBuilder, GPS, and photography

Ever since the dawn of time, man has strived to find out his exact position on the face of the earth, and since the invention of the camera, man has recorded that location, event, or person in a photograph. Even in modern times these two things are still of great interest and I'm sure you would agree that both would provide excellent data input for applications.

Let's consider creating a small but cool Pocket PowerBuilder application that can locate the application user's exact position and let him take a picture of where he is. This data could then be stored within an ASA database on the Pocket PC device. Then, later, extending this to allow for the synchronization of that data (latitude, longitude, and image) back to a consolidated database would be excellent.

We already know that Pocket PowerBuilder can interface with hardware such as the Biometric Fingerprint Scanner in HP's 5500 series iPAQs and barcode scanners such as those from Symbol. It should be no surprise that other hardware such as Bluetooth GPS receivers and cameras are no problem for the best RAD 4GL Mobile Development tool around.

Where Am I?
Let me take a moment to explain some of the terminology used for GPS - the technology that's involved in finding your exact location.

What Is Global Positioning System (GPS)?
During the 1960s the U.S. Navy and Air Force worked on a number of systems that would provide navigational capabilities for a variety of applications. In 1973 the Department of Defense unified these systems into the NAVSTAR Global Positioning System, which was operated by the Air Force. Core to this system were atomic clocks carried on the satellites. In 1983 President Ronald Reagan directed that the NAVSTAR GPS be made available for international commercial use, setting the scene for today.

Today GPS consists of a series of 24 geosynchronous satellites that continuously transmit a time-tagged signal from the onboard atomic clocks. The GPS receiver calculates its geographic position by determining its position relative to a set of at least three of the satellites, and it's accurate within 10 feet. The receiver receives these time-tagged signals and performs the four-dimensional triangulation functions (using algebra) within the receiver. That positional data is available in NMEA format.

What Is NMEA?
The National Marine Electronics Association developed a specification that defined the interface between various pieces of marine electronic equipment, and the GPS receiver communication is a part of this specification.

NMEA-formatted data includes the complete PVT (position, velocity, time) calculated by the GPS receiver. This is sent in a line of data called a sentence, which is self-contained and independent from other NMEA sentences. Standard sentences have a two-letter prefix that defines the device that uses that sentence type, e.g., GP for GPS. Three letters that define the sentence content follow this. Each sentence is ASCII text, begins with a "$", ends with a carriage return/line feed sequence, and can't be any longer than 80 characters. Each data item within it is comma-separated.

I include a few NMEA sentence definitions in Table 1, but check out the Internet for a full list.

What GPS Hardware Is Available?
GPS Hardware manufacturers Pharos, (see Figure 1), TomTom, and HP, to name a few, are now supplying Bluetooth GPS Receivers. Along with the receivers most of these manufacturers supply navigational software with street-level data. Check it out...I'll never get lost again and my wife is happy she's not the navigator while on family trips! (So am I...LOL.)

Bluetooth is an excellent feature for any external device when using it with a Pocket PC - no wires! That's something else that we'll discuss indirectly...programmatically communicating with a Bluetooth device.

Communicating with a Bluetooth device is pretty simple via API calls. What we need to do is detect the device, usually on COM8, connect to it, and then read the data from it. This will be "baked into the VM" in a later version of Pocket PowerBuilder as Direct File reads and writes. Note: PowerBuilder and Pocket PowerBuilder file access is buffered, which is something we don't want in this case.

In Listing 1 we are coding the connect logic to the Bluetooth GPS device and the reading of a stream of data from the device. The FileRead returns a number of NMEA sentences from the GPS receiver; there is an example of one such NMEA sentence in Listing 2.

Pocket PowerBuilder Object
What we need is an NMEA service object (see Figure 2) that can read the data, understand it, and populate an NMEA structure. The service object makes use of an external source DataStore so that the sentences can be imported into it. Once imported the different sentences can be searched for using the DataStore Find function, such as:

li_row = ds_parse.Find("f1 = '$GPGGA'", 1, li_rc)

Once found the sentence can be parsed and specific data elements used to populate a standard NMEA structure (see Listing 3).

Can I Take a Picture of It?

You can certainly say that photography (derived from the Greek words photos meaning light and graphein meaning to draw) has come a long way since the Daguerreotype cameras of 1839 and even from the early days of digital photography. Who would believe that even portable computing with a Pocket PC would be able to partake of cameras as well?

What camera hardware is available? There are some devices that have cameras built in and some that are external accessories but, unfortunately, each seems to have a totally different API. Oh well, standards...who needs them? : )

We'll concentrate on the first Pocket PC SDIO 1.3 MP External Camera from HP (see Figure 3) ( The same camera is also available from VEO ( Both cameras have a maximum resolution of 1280x1024 pixels and 4x digital zoom, enough for any user who is seeking a mobile solution that weighs only 0.7 oz. How excellent is that?

As its name suggests, this camera plugs into the SDIO slot of the iPAQ and comes with a photographic application to use as you would a standard camera. The driver, SDIOCam.dll, is part of the install and this is where we gain interest as application developers.

What we would like to do is integrate the usage of the camera into a Pocket PowerBuilder application. We're lucky that HP and VEO are very good at publishing their APIs, which can be downloaded from their Web sites (see Listing 4).  Using the SDIOCam.DLL we can change settings on the camera, preview the picture to be taken, and then take the picture.

From there we can look into integration, but as with other hardware, the story of integration isn't that straightforward. Don't worry, PPB engineering, in the form of Reed Shilts, to the rescue with a wrapper DLL.

Why the Wrapper DLL?
Ninety-nine percent of the reason why the wrapper DLL is needed for SDIOCam.DLL is because the preview window needs to perform low-level window painting. The camera preview API provides only a byte array, which represents the image (updated around 10 times a second) that needs to be transformed into a bitmap to be plastered onto the window. This is easiest to perform in C++ using low-level window API calls for both performance and a "natural fit" to the problem. The wrapper DLL is available from the Special Hardware section of CodeXchange.

Pocket PowerBuilder Object
Again a service object would be good to encapsulate and simplify the usage of the camera (see Figure 4). As always we need to declare the external functions that we'll call (see Listing 5).

The steps for using the Camera API are:

1.  Initiate camera
2.  Start preview mode
3.  Change zoom if needed

  • Pause preview mode
  • Change settings
  • Resume preview mode
4.  Snap picture

More Stories By Ian Thain

As one of the Sybase Technical Evangelists, Ian regularly addresses technical audiences all over the world and his sessions are always very well attended. He also writes education classes, whitepapers, demos and articles for various Sybase products and publishes regularly in Journals such as SYS-CON's PBDJ and International Developer Magazine. He is also the Sybase Unwired Platform & PocketBuilder Evangelist and works closely with the team in Dublin, CA and Concord, MA on new features and demonstrations for the products. In his customer-facing Evangelist role, Ian is very involved with the design, production and testing of Enterprise class Unwired Solutions, that have been implemented using Sybase's Unwired tools for Sybase customers around the globe. In addition, Ian is a dedicated technical expert continually working with Sybase's key partners and clients to enhance the capabilities of the Unwired solutions that Sybase can offer to its customers. Ian can also be found on Twitter @ithain

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.