This project is read-only.

Toolbox.NETMF.Hardware.NmeaGps

Toolbox.NETMF.Hardware.NmeaGps(SerialPort = "COM2", BaudRate = 4800)
  • SerialPort The serial port the GPS receiver is connected to
  • BaudRate The speed of the GPS receiver

Methods

  • Start() Starts listening to the GPS module
  • Stop() Stops listening to the GPS module

Properties

  • Active Checks if we're listening to the GPS module
  • Fix True when we have a fix
  • Fix3D True when we have a 3D fix
  • Satellites The amount of fixed satellites
  • GPSTime Time according to the satellites
  • Knots Speed over the ground in knots
  • Kmh Speed over the ground in kilometers per hour
  • Latitude Latitude as floating point value
  • Longitude Longitude as floating point value
  • Altitude Altitude in meters as floating point value
  • SLatitude Latidude (in the format 4068.092,N)
  • SLongitude Longitude (in the format 04704.045,W)
  • SAltitude Altitude, Meters, above mean sea level (in the format 545.4,M)

Sample code in C#

public static NmeaGps Gps = new NmeaGps();
public static OutputPort Led = new OutputPort(Pins.ONBOARD_LED, false);

public static void Main()
{
    // Binds all events to the GPS device
    Gps.GotFix += new NativeEventHandler(Gps_GotFix);
    Gps.LostFix += new NativeEventHandler(Gps_LostFix);
    Gps.PositionChanged += new NativeEventHandler(Gps_PositionChanged);
    // Starts the GPS device
    Debug.Print("Trying to get a fix...");
    Gps.Start();

    // Nice blinking LED effect when we have a fix
    while (true)
    {
        Led.Write(Gps.Fix);
        Thread.Sleep(450);
        Led.Write(!Gps.Fix);
        Thread.Sleep(50);
    }
}

static void Gps_PositionChanged(uint Unused, uint FixType, DateTime GPSTime)
{
    string Outp = "";
    Outp += "3D-Fix: " + Gps.Fix3D.ToString();
    Outp += ", Sattellites: " + Gps.Satellites.ToString();
    Outp += ", Time: " + Gps.GPSTime.ToString();
    Outp += ", Latitude: " + Gps.SLatitude;
    Outp += ", Longitude: " + Gps.SLongitude;
    Outp += ", Altitude: " + Gps.SAltitude;
    Outp += ", Knots: " + Gps.Knots.ToString() + " (" + Gps.Kmh.ToString() + " km/h)";
    Debug.Print(Outp);

    // If you want to translate this to a Bing Maps URL, try this:
    Debug.Print("http://www.bing.com/maps/?q=" + Tools.RawUrlEncode(Gps.Latitude.ToString() + " " + Gps.Longitude.ToString()));
}

static void Gps_GotFix(uint Unused, uint FixType, DateTime GPSTime)
{
    Debug.Print("We got a fix, yay!!");
}

static void Gps_LostFix(uint Unused, uint FixType, DateTime GPSTime)
{
    Debug.Print("We lost our GPS fix :(");
}

Sample code in VB

Dim WithEvents Gps As NmeaGps = New NmeaGps()
Dim Led As OutputPort = New OutputPort(Pins.ONBOARD_LED, False)

Sub Main()
    ' Starts the GPS device
    Debug.Print("Trying to get a fix...")
    Gps.Start()

    ' Nice blinking LED effect when we have a fix
    Do
        Led.Write(Gps.Fix)
        Thread.Sleep(450)
        Led.Write(Not Gps.Fix)
        Thread.Sleep(50)
    Loop
End Sub

Private Sub Gps_GotFix(Unused As UInteger, FixType As UInteger, GPSTime As Date) Handles Gps.GotFix
    Debug.Print("We got a fix, yay!!")
End Sub

Private Sub Gps_LostFix(Unused As UInteger, FixType As UInteger, GPSTime As Date) Handles Gps.LostFix
    Debug.Print("We lost our GPS fix :(")
End Sub

Private Sub Gps_PositionChanged(Unused As UInteger, FixType As UInteger, GPSTime As Date) Handles Gps.PositionChanged
    Dim Outp As String = ""
    Outp += "3D-Fix: " + Gps.Fix3D.ToString()
    Outp += ", Sattellites: " + Gps.Satellites.ToString()
    Outp += ", Time: " + Gps.GPSTime.ToString()
    Outp += ", Latitude: " + Gps.SLatitude
    Outp += ", Longitude: " + Gps.SLongitude
    Outp += ", Altitude: " + Gps.SAltitude
    Outp += ", Knots: " + Gps.Knots.ToString() + " (" + Gps.Kmh.ToString() + " km/h)"
    Debug.Print(Outp)

    ' If you want to translate this to a Bing Maps URL, try this:
    Debug.Print("http://www.bing.com/maps/?q=" + Tools.RawUrlEncode(Gps.Latitude.ToString() + " " + Gps.Longitude.ToString()))
End Sub

Related documents

Last edited Jan 1, 2013 at 9:15 PM by Garrcomm, version 3