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); } }
public static void Main() { #if SD_ENABLED // If your Netduino can't execute the next line of code, make sure you got at least firmware 4.1.1 beta 1 // See also: http://forums.netduino.com/index.php?/topic/1592-netduino-firmware-v411-beta-1/ StorageDevice.MountSD("SD", SPI_Devices.SPI1, Pins.GPIO_PIN_D10); // Determines the filename string filename = ""; int index = 0; do { filename = @"\SD\LOGGER" + Tools.ZeroFill(index, 2) + ".CSV"; ++index; }while (File.Exists(filename)); // Starts writing to the file FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); // Writes file headers writer.WriteLine("ticks,datetime,fix,latitude,longitude,altitude,satellites,kmh"); #endif // The GPS unit is connected to COM2 NmeaGps gps = new NmeaGps("COM2"); // Lets power on the GPS unit (active: LOW) OutputPort gps_enable = new OutputPort(Pins.GPIO_PIN_D4, false); // LEDs are connected to pins 5 and 6 OutputPort led1 = new OutputPort(Pins.GPIO_PIN_D5, false); OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D6, false); // Starts the GPS unit gps.Start(); // Keeps on looping while (true) { // LED1 status ON led1.Write(true); // Builds the output string output = ""; output += DateTime.Now.Ticks.ToString() + ", "; output += gps.GPSTime.ToString() + ", "; if (!gps.Fix) { output += "0, 0, 0, 0, 0, 0"; } else { output += "1, "; output += gps.Latitude.ToString() + ", "; output += gps.Longitude.ToString() + ", "; output += gps.Altitude.ToString() + ", "; output += gps.Satellites.ToString() + ", "; output += gps.Kmh.ToString(); } // Prints the output to the debugger Debug.Print(output); #if SD_ENABLED // Writes the output to the SD buffer writer.WriteLine(output); #endif // LED1 status OFF, LED1 status ON led1.Write(false); led2.Write(true); #if SD_ENABLED // Flushes the buffers to the SD card writer.Flush(); stream.Flush(); #endif // LED2 status OFF led2.Write(false); // Sleeps for a second Thread.Sleep(1000); } }