Example code

From PyGarmin

Jump to: navigation, search

OK. Here's a simple Python program. You may need to set suitable permissions on the serial port (e.g /dev/ttyS0) before running it.

#! /usr/local/bin/python
# Load the module
import garmin

# Create a 'physical layer' connection using serial port
phys = garmin.UnixSerialLink("/dev/ttyS0")

# Create a Garmin object using this connection
gps = garmin.Garmin(phys)


# Get the waypoints from the GPS
# (This may take a little while)
waypoints = gps.getWaypoints()

# Print the waypoints</pre>
for w in waypoints:
    print w.ident,
    lat = garmin.degrees(w.slat)
    lon = garmin.degrees(w.slon)
    print lat, lon, w.cmnt

Simple, eh? This should work for almost any model, because all waypoints will have an identity, a latitude & longitude, and a comment field. The latitude and longitude are stored in 'semicircle' coordinates (basically degrees, but scaled to fill a signed long integer), and so the fields are called 'slat' and 'slon'. The function garmin.degrees() converts these to degrees.

OK, now have a look at some More details...

Personal tools