SerialGPS object

Supported hardware

PocketBuilder applications can interface with global positioning system (GPS) devices through nonvisual user objects. The SerialGPS object provides an interface to the Bluetooth unit GPS devices manufactured by Pharos and TomTom, and to Windows Mobile 5 or later devices that use a COM port. The SerialGPS object inherits from a GPS base class.

NoteWindows Mobile 5 devices You can instantiate the GPS base class, instead of the SerialGPS object, to interface directly with GPS devices using a WM 5 platform. To use the GPS base class, you must set the ConfigParams property to “driver=WMNative”.

In addition to the GPS and SerialGPS classes, the PocketBuilder GPS interface uses several structure objects to store information.

For information about the properties, events, and functions of the SerialGPS object, and the properties of the related GPSCoordinate, GPSFix, GPSHeading, GPSSatellitePosition, and GPSSatellitesInView structure objects, see Objects and Controls in the online Help.

For more information on the supported GPS devices, see the Pharos Web site and the TomTom Web site. For information about the NMEA-0183 specification used by the supported GPS devices, see the NMEA Web site.

GPS Example

The following example captures the time, latitude, longitude, and altitude of a GPS reading in SingleLineEdit text boxes:

GPSFix myFix
GPSCoordinate myCoord
Integer fixMinutes
Real fixSeconds
Integer rc
gps_1.SerialPort = "COM5:" //override default com8 port
gps_1.ConfigParams = "buffersize=2000,refresh=2000,"& 		 + "timeout=5000,multithread=0"
rc = gps_1.Open()
IF rc = 1 THEN
 rc = gps_1.GetFix(myFix)
 IF rc = 1 THEN
 //Data received, test if valid
  IF myFix.isFixValid THEN
   //Display current fix
    sle_time.text = string(myFix.FixTime, "h:mm:ss") &
       + " UTC"
    myCoord = myFix.Longitude
   fixMinutes = INTEGER (myCoord.minute)
   fixSeconds =(myCoord.minute &       
     - INTEGER(myCoord.minute))*60.0
   sle_long.text = "Longitude: " &
     + string(myCoord.degree) + " degrees " &
     + string(fixMinutes) + " minutes " &
     + string(fixSeconds) + " seconds " &
     + string(myCoord.hemisphere)

   myCoord = myFix.Latitude
   fixMinutes = INTEGER (myCoord.minute)
   fixSeconds =(myCoord.minute &
     - INTEGER(myCoord.minute))*60.0
   sle_lat.text = "Latitude: " &
    + string(myCoord.degree) + " degrees " &
    + string(fixMinutes) + " minutes " &
    + string(fixSeconds) + " seconds " &
    + string(myCoord.hemisphere)

   sle_height.text ="Altitude: " + &
    string(myFix.Altitude) + " meters"
  ELSE
   sle_message.text = "Fix is not valid"
  END IF
 ELSE
  //Call user function to display error
  sle_message.text = uf_display_error("GetFix", rc)
 END IF
ELSE
 sle_message.text = uf_display_error("Open Serial " + &   "GPS", rc)
END IF
rc = gps_1.Close()

The previous example uses the user function, uf_display_error, which provides a convenient way to interpret error codes from GPS objects. The following code defines the user function:

public function string uf_display_error (string msg_prefix, long errcode);

string	errmsg, err_description
err_description = " RC=" + string(errcode)

choose case errcode
	case 1
		err_description += " Success		"
	case 100
		err_description += " End of Buffer"
	case -1
		err_description += " General Error"
	case -10
		err_description += " GPS Object Error"
	case -11
		err_description += " No Raw Data. Set " + &         "configparams before Open"
	case -12
		err_description += " Open Failure. " + &
        "Check filename argument on Open"	case -13
		err_description += " Open object before " + &
        "calling other methods."
	case -14
		err_description += " Read timeout. " + &
        "SerialGPS reciever may not be sending data."
	case -15
		err_description += " Read Failure. "
	case -16
		err_description += " Parser Error. " + &
         "Unexpected data recieved."
	case -17
		err_description += " Checksum incorrect. " + &
         "Possible data corruption in this sentence."
	case -100
		err_description += " Method not implemented."
end choose
errmsg = msg_prefix + err_description + EOL
return errmsg
end function

For more information

For more information on the supported GPS devices, see the Pharos Web site and the TomTom Web site. For information about the NMEA-0183 specification, see the NMEA Web site.