Examples?

Aug 7, 2009 at 10:44 AM
Edited Aug 8, 2009 at 2:04 PM

Jon,

Thank you very much for allowing us mere mortals the use of this framework.

How does it work though? The only thing I could get to do anything was begindetect and that started complaing that some CS source code was missing.

Some Samples would be really nice.

Thanks

 

 

 

 

Coordinator
Aug 10, 2009 at 4:49 PM

You can download the [url:GPS Diagnostics|http://gpsdiagnostics.codeplex.com] utility which demonstrates much of the GPS3 features.  I'm honestly too sick of programming to even consider writing more code right now.  Maybe later.

Aug 11, 2009 at 12:34 PM

Thanks Jon, I found the diagnostics and have run it on my Pocket PC.

Unfortunately, the 2.0 version cannot find the GPS device either.

I am starting to think I will need to move up to 3.5.

Cheers anyway.

 

Aug 17, 2009 at 1:06 PM

Hi,
i'm trying to use this library to make a simple GPS coordinate reading application to use in conjunction with ordnance survey maps (UK / Ireland) for a hiking trip, just in case my map-reading skills let me down completely.  thanks for making this library available.  i got the diagnostics app up and running and i have set up the source code projects and it all compiles and runs fine.  however i can't find any sample code to actually get coordinates.  i have a 'hello world' type application set up, using an NmeaInterpreter component. i guess i'm missing some basic function calls to make it start working. any ideas?  many thanks in advance.

tim


public
partial class Form1 : Form { GpsIntermediateDriver gpsid = GpsIntermediateDriver.Current; public Form1() { InitializeComponent(); } private void InitGPS() { if (!Devices.IsDeviceDetected) { MessageBox.Show("No GPS Device Detected"); return; } if(Devices.GpsIntermediateDriver == null) { MessageBox.Show("GPS Intermediate driver not configured"); return; } if(!Devices.GpsIntermediateDriver.IsOpen) Devices.GpsIntermediateDriver.Open(); this.nmeaInterpreter1.Start(Devices.GpsIntermediateDriver); } private void Form1_Load(object sender, EventArgs e) { InitGPS(); this.textBox1.Text += "Started GPS\r\n";
  } private void nmeaInterpreter1_ConnectionLost(object sender, ExceptionEventArgs e) { this.textBox1.Text += "Connection lost\r\n"; } private void nmeaInterpreter1_FixAcquired(object sender, EventArgs e) { this.textBox1.Text += "Fix acquired\r\n"; } private void nmeaInterpreter1_PositionReceived(object sender, PositionEventArgs e) { this.textBox1.Text += String.Format("Position Received:{0}\r\n", e.Position.ToString()); } private void nmeaInterpreter1_PositionChanged(object sender, PositionEventArgs e) { this.textBox1.Text += String.Format("Position changed:{0}\r\n", e.Position.ToString()); } }

 

Aug 17, 2009 at 1:09 PM

sorry for my last post, i just realised i didn't implement the BeginDetection properly... please ignore the post.

Aug 17, 2009 at 6:01 PM
Edited Aug 17, 2009 at 6:26 PM

just in case anyone is looking for a basic example of using this library to get coordinates, here is something i put together today based on the Diagnostics app.  it assumes that you only want to use the built-in GPS driver, i.e. your GPS is managed by windows mobile. it reads out the latitude, longitude, last update time, satellite names, accuracy estimate, and the live/raw NMEA data (turn on/off via tick box).  i am extremely impressed with this library, i've never seen such thorough and well-written code.  many thanks again for making it public.

Form1.cs:

 

 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using GeoFramework;
using GeoFramework.Gps;
using GeoFramework.Gps.IO;
using GeoFramework.Gps.Nmea;

namespace Gps_Hiker
{
	public delegate void MethodInvoker();
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();

			Devices.DeviceDetected += new EventHandler<DeviceEventArgs>(Devices_DeviceDetected);
			this.nmeaInterpreter1.SatellitesChanged += new EventHandler<SatelliteListEventArgs>(nmeaInterpreter1_SatellitesChanged);
			this.nmeaInterpreter1.AllowAutomaticReconnection = true;
			this.nmeaInterpreter1.IsFixRequired = false;
			this.nmeaInterpreter1.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(nmeaInterpreter1_ExceptionOccurred);
			this.nmeaInterpreter1.SentenceReceived += new EventHandler<NmeaSentenceEventArgs>(nmeaInterpreter1_SentenceReceived);
			this.nmeaInterpreter1.FixQualityChanged += new EventHandler<FixQualityEventArgs>(nmeaInterpreter1_FixQualityChanged);
		}

		void nmeaInterpreter1_FixQualityChanged(object sender, FixQualityEventArgs e)
		{
			BeginInvoke(new MethodInvoker(delegate()
			{
				this.lblAccuracy.Text = String.Format("Accurate to {0} {1}", this.nmeaInterpreter1.FixPrecisionEstimate.Value.ToString("#.#"), this.nmeaInterpreter1.FixPrecisionEstimate.Units.ToString());
			}));
		}

		void nmeaInterpreter1_SatellitesChanged(object sender, SatelliteListEventArgs e)
		{
			BeginInvoke(new MethodInvoker(delegate()
			{				
				this.lblSat.Text = String.Format("Satellites: {0}\n", this.nmeaInterpreter1.FixedSatelliteCount);
				
				// display names of 5 strongest satellites (sometimes doesn't work?)	
				List<Satellite> activeSatellites = e.Satellites.Where(z => z.IsTracked).OrderByDescending(z => z.SignalToNoiseRatio.Value).Take(5).ToList();
				foreach (Satellite s in activeSatellites)
					this.lblSat.Text += String.Format("  {0} [{1}]\n", s.Name, s.SignalToNoiseRatio.Value);
			}));
		}

		void nmeaInterpreter1_SentenceReceived(object sender, NmeaSentenceEventArgs e)
		{
			BeginInvoke(new MethodInvoker(delegate()
			{
				this.lblLog.Text = e.Sentence.ToString();
			}));
		}

		void nmeaInterpreter1_ExceptionOccurred(object sender, ExceptionEventArgs e)
		{
			BeginInvoke(new MethodInvoker(delegate()
			{
				MessageBox.Show(e.Exception.Message, "NMEA Error");
			}));
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			this.lblStatus.Text = "Detecting Devices";
			Devices.BeginDetection();
		}

		private void Devices_DeviceDetected(object sender, DeviceEventArgs e)
		{
			BeginInvoke(new MethodInvoker(delegate()
			{
				if (e.Device.Name.StartsWith("GPS Intermediate Driver"))
				{
					this.nmeaInterpreter1.Start(e.Device);
					this.lblStatus.Text = "Acquiring Fix...";					
				}
			}));
		}

		private void nmeaInterpreter1_ConnectionLost(object sender, ExceptionEventArgs e)
		{
			BeginInvoke(new MethodInvoker(delegate()
			{
				this.lblStatus.Text = "Connection lost";
			}));
		}

		private void nmeaInterpreter1_FixAcquired(object sender, EventArgs e)
		{
			BeginInvoke(new MethodInvoker(delegate()
			{
				this.lblStatus.Text = "Fix acquired";
			}));
		}

		private void nmeaInterpreter1_PositionChanged(object sender, PositionEventArgs e)
		{
			BeginInvoke(new MethodInvoker(delegate()
			{
				this.lblUpdated.Text = "Updated: " + DateTime.Now.TimeOfDay.ToString();
				if (!e.Position.IsEmpty && !e.Position.IsInvalid)
				{
					this.lblLat.Text =  String.Format("Lat:  {0}°{1}' {2}", e.Position.Latitude.Hours, e.Position.Latitude.DecimalMinutes, e.Position.Latitude.Hemisphere.ToString().Substring(0,1));
					this.lblLong.Text = String.Format("Long: {0}°{1}' {2}", e.Position.Longitude.Hours, e.Position.Longitude.DecimalMinutes, e.Position.Longitude.Hemisphere.ToString().Substring(0, 1));					
				}
			}));
		}

		private void Form1_Closing(object sender, CancelEventArgs e)
		{
			this.nmeaInterpreter1.StopRecording();
			this.nmeaInterpreter1.Stop();
			this.nmeaInterpreter1.Dispose();
		}

		private void chkNmeaLog_CheckStateChanged(object sender, EventArgs e)
		{
			if(this.chkNmeaLog.Checked)
				this.nmeaInterpreter1.SentenceReceived += new EventHandler<NmeaSentenceEventArgs>(nmeaInterpreter1_SentenceReceived);
			else
				this.nmeaInterpreter1.SentenceReceived -= new EventHandler<NmeaSentenceEventArgs>(nmeaInterpreter1_SentenceReceived);
		}
	}
}

 

Form1.Designer.cs:

 

namespace Gps_Hiker
{
	partial class Form1
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
		private System.Windows.Forms.MainMenu mainMenu1;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.nmeaInterpreter1 = new GeoFramework.Gps.Nmea.NmeaInterpreter();
			this.lblLat = new System.Windows.Forms.Label();
			this.lblLong = new System.Windows.Forms.Label();
			this.lblSat = new System.Windows.Forms.Label();
			this.lblUpdated = new System.Windows.Forms.Label();
			this.chkNmeaLog = new System.Windows.Forms.CheckBox();
			this.lblStatus = new System.Windows.Forms.Label();
			this.lblLog = new System.Windows.Forms.Label();
			this.lblAccuracy = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// nmeaInterpreter1
			// 
			this.nmeaInterpreter1.PositionChanged += new System.EventHandler<GeoFramework.PositionEventArgs>(this.nmeaInterpreter1_PositionChanged);
			this.nmeaInterpreter1.FixAcquired += new System.EventHandler(this.nmeaInterpreter1_FixAcquired);
			this.nmeaInterpreter1.ConnectionLost += new System.EventHandler<GeoFramework.ExceptionEventArgs>(this.nmeaInterpreter1_ConnectionLost);
			// 
			// lblLat
			// 
			this.lblLat.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
						| System.Windows.Forms.AnchorStyles.Right)));
			this.lblLat.Location = new System.Drawing.Point(4, 24);
			this.lblLat.Name = "lblLat";
			this.lblLat.Size = new System.Drawing.Size(233, 20);
			this.lblLat.Text = "Lat:";
			// 
			// lblLong
			// 
			this.lblLong.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
						| System.Windows.Forms.AnchorStyles.Right)));
			this.lblLong.Location = new System.Drawing.Point(4, 44);
			this.lblLong.Name = "lblLong";
			this.lblLong.Size = new System.Drawing.Size(233, 20);
			this.lblLong.Text = "Long:";
			// 
			// lblSat
			// 
			this.lblSat.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
						| System.Windows.Forms.AnchorStyles.Right)));
			this.lblSat.Location = new System.Drawing.Point(4, 84);
			this.lblSat.Name = "lblSat";
			this.lblSat.Size = new System.Drawing.Size(233, 104);
			this.lblSat.Text = "Satellites: ";
			// 
			// lblUpdated
			// 
			this.lblUpdated.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
						| System.Windows.Forms.AnchorStyles.Right)));
			this.lblUpdated.Location = new System.Drawing.Point(4, 64);
			this.lblUpdated.Name = "lblUpdated";
			this.lblUpdated.Size = new System.Drawing.Size(233, 20);
			this.lblUpdated.Text = "Last Updated:";
			// 
			// chkNmeaLog
			// 
			this.chkNmeaLog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.chkNmeaLog.Checked = true;
			this.chkNmeaLog.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chkNmeaLog.Location = new System.Drawing.Point(186, 191);
			this.chkNmeaLog.Name = "chkNmeaLog";
			this.chkNmeaLog.Size = new System.Drawing.Size(51, 20);
			this.chkNmeaLog.TabIndex = 4;
			this.chkNmeaLog.Text = "Log";
			this.chkNmeaLog.CheckStateChanged += new System.EventHandler(this.chkNmeaLog_CheckStateChanged);
			// 
			// lblStatus
			// 
			this.lblStatus.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
			this.lblStatus.Dock = System.Windows.Forms.DockStyle.Top;
			this.lblStatus.Location = new System.Drawing.Point(0, 0);
			this.lblStatus.Name = "lblStatus";
			this.lblStatus.Size = new System.Drawing.Size(240, 20);
			this.lblStatus.Text = "Status:";
			// 
			// lblLog
			// 
			this.lblLog.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
			this.lblLog.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.lblLog.Location = new System.Drawing.Point(0, 214);
			this.lblLog.Name = "lblLog";
			this.lblLog.Size = new System.Drawing.Size(240, 54);
			this.lblLog.Text = "NMEA";
			// 
			// lblAccuracy
			// 
			this.lblAccuracy.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
						| System.Windows.Forms.AnchorStyles.Right)));
			this.lblAccuracy.Location = new System.Drawing.Point(4, 191);
			this.lblAccuracy.Name = "lblAccuracy";
			this.lblAccuracy.Size = new System.Drawing.Size(176, 20);
			this.lblAccuracy.Text = "Accuracy:";
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
			this.AutoScroll = true;
			this.ClientSize = new System.Drawing.Size(240, 268);
			this.Controls.Add(this.lblAccuracy);
			this.Controls.Add(this.chkNmeaLog);
			this.Controls.Add(this.lblLog);
			this.Controls.Add(this.lblStatus);
			this.Controls.Add(this.lblUpdated);
			this.Controls.Add(this.lblSat);
			this.Controls.Add(this.lblLong);
			this.Controls.Add(this.lblLat);
			this.Menu = this.mainMenu1;
			this.Name = "Form1";
			this.Text = "GPS Hiker";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
			this.ResumeLayout(false);

		}

		#endregion

		private GeoFramework.Gps.Nmea.NmeaInterpreter nmeaInterpreter1;
		private System.Windows.Forms.Label lblLat;
		private System.Windows.Forms.Label lblLong;
		private System.Windows.Forms.Label lblSat;
		private System.Windows.Forms.Label lblUpdated;
		private System.Windows.Forms.CheckBox chkNmeaLog;
		private System.Windows.Forms.Label lblStatus;
		private System.Windows.Forms.Label lblLog;
		private System.Windows.Forms.Label lblAccuracy;
	}
}



 

Aug 18, 2009 at 11:42 PM

I developed a GPS management software based on GPS.net. Please check it out if you are intersected.

http://navsgo.codeplex.com/

 

Oct 5, 2009 at 2:57 PM

Hello everyone!

I'm also trying to create a simple application which should detect the gps device. The problem is that none of the posted applications detects the GPS device. I deployed the applications on the windows Mobile 5.0 Pocket PC device emulator and on a MIO p550 device but the gps device is not recognized. It detects the intermediate driver i get the following error: "A connection was opened to the GPS Intermediate Driver but no data was found. The "Hardware Port" settings are incorrect, or the GPS device is not responding." . For the emulator, i used the Fake GPS application to emulate a GPS device. If i click the ananlyze button it throws a Win32 Exception.

Can anyone of you please help me because i really don't know why no sample works and i've got stuck at this moment.

Thanks a lot,

Alex

Oct 5, 2009 at 9:56 PM

Go to some open place to get fix for your GPS device.

Oct 6, 2009 at 9:03 AM

what type of emulator do you use for testing the code?

 

Nov 9, 2009 at 11:42 AM

 

Hello all,
I tried to run the code that timmer3 posted on a Samsung Omnia. It detects the GPS device (GPS intermediate driver), 
but after that, it fails to read the data from the serial port.
It blocks while running the NmeaInterpreter thread; precisely, on method SerialStream.Read(), while
calling NativeMethods.ReadFile(). I get to this point during debugging and it does not proceed, as if it were waiting
for some data to be available.
This is the stack trace:
GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.IO.SerialStream.Read(byte[] buffer = {byte[128]}, int offset = 0, int count = 128) Line 234 C#
  mscorlib.dll!System.IO.StreamReader.ReadBuffer() + 0x2b bytes
  mscorlib.dll!System.IO.StreamReader.ReadLine() + 0x1b bytes
  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Nmea.NmeaReader.ReadSentence() Line 130 + 0x6 bytes C#
  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Nmea.NmeaReader.ReadValidSentence() Line 178 C#
  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Nmea.NmeaReader.ReadTypedSentence() Line 193 C#
  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Nmea.NmeaInterpreter.OnReadPacket() Line 227 + 0x6 bytes C#
  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Interpreter.ParsingThreadProc() Line 1914 + 0x6 bytes C#
The strange thing is that, before that, while detecting the device, it reads from the serial stream normally.
Does anyone has any hint of what might be causing the block on the SerialStream?
Thanks,
Angela

Hello all,

 

I tried to run the code that timmer3 posted on a Samsung Omnia. It detects the GPS device (GPS intermediate driver), but after that, it fails to read the data from the serial port.

 

It blocks while running the NmeaInterpreter thread; precisely, on method SerialStream.Read(), while calling NativeMethods.ReadFile(). I get to this point during debugging and it does not proceed, as if it were waiting for some data to be available.

 

This is the stack trace:

GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.IO.SerialStream.Read(byte[] buffer = {byte[128]}, int offset = 0, int count = 128) Line 234 C#

  mscorlib.dll!System.IO.StreamReader.ReadBuffer() + 0x2b bytes

  mscorlib.dll!System.IO.StreamReader.ReadLine() + 0x1b bytes

  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Nmea.NmeaReader.ReadSentence() Line 130 + 0x6 bytes C#

  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Nmea.NmeaReader.ReadValidSentence() Line 178 C#

  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Nmea.NmeaReader.ReadTypedSentence() Line 193 C#

  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Nmea.NmeaInterpreter.OnReadPacket() Line 227 + 0x6 bytes C#

  GeoFramework.Gps.PocketPC.dll!GeoFramework.Gps.Interpreter.ParsingThreadProc() Line 1914 + 0x6 bytes C#

 

The strange thing is that, before that, while detecting the device, it reads from the serial stream normally.

Does anyone has any hint of what might be causing the block on the SerialStream?

Thanks,

Angela

 

Nov 24, 2009 at 10:50 AM

Has anyone managed to use the GPS_Hiker example running with the FakeGPS?

When I start the GPS_Hiker it stays to "Status: Detective Devices"

Please note that I have tested the FakeGPS with other applications and I am able to see data coming through.
Any ideas?