cdempster
asked on
Please help capturing string information from GPS attached to serial port to a textbox.
Please help capturing string information from GPS attached to serial port to a textbox.
Can capture to file but not sure how to stop the feed to the file???
input from serial port looks like this;
$GPGGA,032742,2727.2016,S, 15306.4371 ,E,0,00,,0 0018.6,M,0 39.4,M,,*4 4
$GPGSA,A,1,,,,,,,,,,,,,,,* 1E
$GPGSV,1,1,04,08,60,087,00 ,11,23,113 ,00,17,72, 326,00,29, 40,248,00* 7B
$GPRMC,032742,V,2727.2016, S,15306.43 71,E,000.0 ,114.3,280 307,,,N*79
$GPGGA,032743,2727.2016,S, 15306.4371 ,E,0,00,,0 0018.6,M,0 39.4,M,,*4 5
$GPGSA,A,1,,,,,,,,,,,,,,,* 1E
$GPGSV,1,1,04,08,60,087,00 ,11,23,113 ,00,17,72, 326,00,29, 40,248,00* 7B
$GPRMC,032743,V,2727.2016, S,15306.43 71,E,000.0 ,114.3,280 307,,,N*78
$GPGGA,032744,2727.2016,S, 15306.4371 ,E,0,00,,0 0018.6,M,0 39.4,M,,*4 2
$GPGSA,A,1,,,,,,,,,,,,,,,* 1E
$GPGSV,1,1,04,08,60,087,00 ,11,23,113 ,00,17,72, 326,00,29, 40,248,00* 7B
$GPRMC,032744,V,2727.2016, S,15306.43 71,E,000.0 ,114.3,280 307,,,N*7F
$GPGGA,032745,2727.2016,S, 15306.4371 ,E,0,00,,0 0018.6,M,0 39.4,M,,*4 3
$GPGSA,A,1,,,,,,,,,,,,,,,* 1E
$GPGSV,1,1,04,08,60,087,00 ,11,23,113 ,00,17,72, 326,00,29, 40,248,00* 7B
$GPRMC,032745,V,2727.2016, S,15306.43 71,E,000.0 ,114.3,280 307,,,N*
$GPGGA,032746,2727.2016,S, 15306.4371 ,E,0,00,,0 0018.6,M,0 39.4,M,,*4 0
$GPGSA,A,1,,,,,,,,,,,,,,,* 1E
$GPGSV,1,1,04,08,60,087,00 ,11,23,113 ,00,17,72, 326,00,29, 40,248,00* 7B
My Code reads as follows;
private void btnReadGPS_Click(object sender, EventArgs e)
{
SP = new SerialPort("COM3", 4800, Parity.None, 8, StopBits.One);
SP.DataReceived += new SerialDataReceivedEventHan dler(Async hronousRea der);
SP.Open();
SP.Write("AT+CAD?\r");
}
private void AsynchronousReader(object sender, SerialDataReceivedEventArg s e)
{
// txtGPSRawDataFeed.Text = txtGPSRawDataFeed.Text + SP.ReadExisting();
//reads all the bytes available in the SerialPort, Encodes them , and puts it on a string
string inbuffer = SP.ReadExisting();
FileStream file = new FileStream("c:/path.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write(inbuffer);
sw.Close();
}
Can capture to file but not sure how to stop the feed to the file???
input from serial port looks like this;
$GPGGA,032742,2727.2016,S,
$GPGSA,A,1,,,,,,,,,,,,,,,*
$GPGSV,1,1,04,08,60,087,00
$GPRMC,032742,V,2727.2016,
$GPGGA,032743,2727.2016,S,
$GPGSA,A,1,,,,,,,,,,,,,,,*
$GPGSV,1,1,04,08,60,087,00
$GPRMC,032743,V,2727.2016,
$GPGGA,032744,2727.2016,S,
$GPGSA,A,1,,,,,,,,,,,,,,,*
$GPGSV,1,1,04,08,60,087,00
$GPRMC,032744,V,2727.2016,
$GPGGA,032745,2727.2016,S,
$GPGSA,A,1,,,,,,,,,,,,,,,*
$GPGSV,1,1,04,08,60,087,00
$GPRMC,032745,V,2727.2016,
$GPGGA,032746,2727.2016,S,
$GPGSA,A,1,,,,,,,,,,,,,,,*
$GPGSV,1,1,04,08,60,087,00
My Code reads as follows;
private void btnReadGPS_Click(object sender, EventArgs e)
{
SP = new SerialPort("COM3", 4800, Parity.None, 8, StopBits.One);
SP.DataReceived += new SerialDataReceivedEventHan
SP.Open();
SP.Write("AT+CAD?\r");
}
private void AsynchronousReader(object sender, SerialDataReceivedEventArg
{
// txtGPSRawDataFeed.Text = txtGPSRawDataFeed.Text + SP.ReadExisting();
//reads all the bytes available in the SerialPort, Encodes them , and puts it on a string
string inbuffer = SP.ReadExisting();
FileStream file = new FileStream("c:/path.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write(inbuffer);
sw.Close();
}
Also, it looks like you initiate reading the gps with a button click, you could also have another button to stop reading the gps and end the requests. I do not know what your command to send for that would be though. It is probably in the documentation for your gps device.
ASKER
using System;
using System.Collections.Generic ;
using System.Text;
using System.Globalization;
namespace GPS_Interface
{
public class NmeaInterpreter
{
// Represents the EN-US culture, used for numers in NMEA sentences
public static CultureInfo NmeaCultureInfo = new CultureInfo("en-US");
// Used to convert knots into miles per hour
public static double MPHPerKnot = double.Parse("1.150779", NmeaCultureInfo);
#region Delegates
public delegate void PositionReceivedEventHandl er(string latitude, string longitude,bool PositionReceived);
public delegate void DateTimeChangedEventHandle r(System.D ateTime dateTime);
public delegate void BearingReceivedEventHandle r(double bearing);
public delegate void SpeedReceivedEventHandler( double speed);
public delegate void QualityReceivedEventHandle r(int Quality);
public delegate void SpeedLimitReachedEventHand ler();
public delegate void FixObtainedEventHandler();
public delegate void FixLostEventHandler();
public delegate void SatelliteReceivedEventHand ler(int pseudoRandomCode, int azimuth, int elevation, int signalToNoiseRatio);
public delegate void HDOPReceivedEventHandler(d ouble value);
public delegate void VDOPReceivedEventHandler(d ouble value);
public delegate void PDOPReceivedEventHandler(d ouble value);
#endregion
#region Events
public event PositionReceivedEventHandl er PositionReceived;
public event DateTimeChangedEventHandle r DateTimeChanged;
public event BearingReceivedEventHandle r BearingReceived;
public event SpeedReceivedEventHandler SpeedReceived;
public event QualityReceivedEventHandle r QualityReceived;
public event SpeedLimitReachedEventHand ler SpeedLimitReached;
public event FixObtainedEventHandler FixObtained;
public event FixLostEventHandler FixLost;
public event SatelliteReceivedEventHand ler SatelliteReceived;
public event HDOPReceivedEventHandler HDOPReceived;
public event VDOPReceivedEventHandler VDOPReceived;
public event PDOPReceivedEventHandler PDOPReceived;
#endregion
public int intParseCount = 0;
// Processes information from the GPS receiver
public bool Parse(string sentence)
{
// Discard the sentence if its checksum does not match our calculated checksum
if (!IsValid(sentence)) return false;
// Look at the first word to decide where to go next
switch (GetWords(sentence)[0])
{
case "$GPRMC":
// A "Recommended Minimum" sentence was found!
//if (intParseCount == 0)
//{
// intParseCount = 1;
return ParseGPRMC(sentence);
//}
//else
//{
// return false;
//}
case "$GPGSV":
// A "Satellites in View" sentence was recieved
//if (intParseCount == 0)
//{
// intParseCount = 1;
return ParseGPGSV(sentence);
//}
//else
//{
// return false;
//}
case "$GPGSA":
//if (intParseCount == 0)
//{
// intParseCount = 1;
return ParseGPGSA(sentence);
//}
//else
//{
// return false;
//}
case "$GPGGA":
//if (intParseCount == 0)
//{
// intParseCount = 1;
return ParseGPGGA(sentence);
//}
//else
//{
// return false;
//}
default:
// Indicate that the sentence was not recognized
return false;
}
}
// Divides a sentence into individual words
public string[] GetWords(string sentence)
{
return sentence.Split(',');
}
// Interprets a $GPRMC message
public bool ParseGPRMC(string sentence)
{
// Divide the sentence into words
string[] Words = GetWords(sentence);
// Do we have enough values to describe our location?
if (Words[3] != "" & Words[4] != "" & Words[5] != "" & Words[6] != "")
{
// Yes. Extract latitude and longitude
string Latitude = Words[3].Substring(0, 2) + "°"; // Append degrees
Latitude = Latitude + Words[3].Substring(2) + "' "; // Append minutes
Latitude = Latitude + Words[4]; // Append the hemisphere
string Longitude = Words[5].Substring(0, 3) + "°"; // Append degrees
Longitude = Longitude + Words[5].Substring(3) + "' "; // Append minutes
Longitude = Longitude + Words[6]; // Append the hemisphere
// Notify the calling application of the change
if (PositionReceived != null)
{
PositionReceived(Latitude, Longitude,true);
}
else
{
PositionReceived(Latitude, Longitude,false);
}
}
// Do we have enough values to parse satellite-derived time?
if (Words[1] != "")
{
// Yes. Extract hours, minutes, seconds and milliseconds
int UtcHours = Convert.ToInt32(Words[1].S ubstring(0 , 2));
int UtcMinutes = Convert.ToInt32(Words[1].S ubstring(2 , 2));
int UtcSeconds = Convert.ToInt32(Words[1].S ubstring(4 , 2));
int UtcMilliseconds = 0;
// Extract milliseconds if it is available
if (Words[1].Length > 7)
{
UtcMilliseconds = Convert.ToInt32(Words[1].S ubstring(7 ));
}
// Now build a DateTime object with all values
System.DateTime Today = System.DateTime.Now.ToUniv ersalTime( );
System.DateTime SatelliteTime = new System.DateTime(Today.Year , Today.Month, Today.Day, UtcHours, UtcMinutes, UtcSeconds, UtcMilliseconds);
// Notify of the new time, adjusted to the local time zone
if (DateTimeChanged != null)
DateTimeChanged(SatelliteT ime.ToLoca lTime());
}
// Do we have enough information to extract the current speed?
if (Words[7] != "")
{
// Yes. Parse the speed and convert it to MPH
double Speed = double.Parse(Words[7], NmeaCultureInfo) * MPHPerKnot;
// Notify of the new speed
if (SpeedReceived != null)
SpeedReceived(Speed);
// Are we over the highway speed limit?
if (Speed > 55)
if (SpeedLimitReached != null)
SpeedLimitReached();
}
// Do we have enough information to extract bearing?
if (Words[8] != "")
{
// Indicate that the sentence was recognized
double Bearing = double.Parse(Words[8], NmeaCultureInfo);
if (BearingReceived != null)
BearingReceived(Bearing);
}
// Does the device currently have a satellite fix?
if (Words[2] != "")
{
switch (Words[2])
{
case "A":
if (FixObtained != null)
FixObtained();
break;
case "V":
if (FixLost != null)
FixLost();
break;
}
}
// Indicate that the sentence was recognized
return true;
}
public bool ParseGPGGA(string sentence)
{
// Divide the sentence into words
string[] Words = GetWords(sentence);
// Do we have enough values to describe our location?
if (Words[2] != "" & Words[3] != "" & Words[4] != "" & Words[5] != "")
{
// Yes. Extract latitude and longitude
string Latitude = Words[2].Substring(0, 2) + "°"; // Append degrees
Latitude = Latitude + Words[2].Substring(2) + "' "; // Append minutes
Latitude = Latitude + Words[3]; // Append the hemisphere
string Longitude = Words[4].Substring(0, 3) + "°"; // Append degrees
Longitude = Longitude + Words[4].Substring(3) + "' "; // Append minutes
Longitude = Longitude + Words[5] + " "; // Append the hemisphere
// Notify the calling application of the change
if (PositionReceived != null)
{
PositionReceived(Latitude, Longitude, true);
}
else
{
PositionReceived(Latitude, Longitude, false);
}
}
// Do we have enough values to parse satellite-derived time?
if (Words[1] != "")
{
// Yes. Extract hours, minutes, seconds and milliseconds
int UtcHours = Convert.ToInt32(Words[1].S ubstring(0 , 2));
int UtcMinutes = Convert.ToInt32(Words[1].S ubstring(2 , 2));
int UtcSeconds = Convert.ToInt32(Words[1].S ubstring(4 , 2));
int UtcMilliseconds = 0;
// Extract milliseconds if it is available
if (Words[1].Length > 7)
{
UtcMilliseconds = Convert.ToInt32(Words[1].S ubstring(7 ));
}
// Now build a DateTime object with all values
System.DateTime Today = System.DateTime.Now.ToUniv ersalTime( );
System.DateTime SatelliteTime = new System.DateTime(Today.Year , Today.Month, Today.Day, UtcHours, UtcMinutes, UtcSeconds, UtcMilliseconds);
// Notify of the new time, adjusted to the local time zone
if (DateTimeChanged != null)
DateTimeChanged(SatelliteT ime.ToLoca lTime());
}
// Do we have enough information to extract the current speed?
if (Words[6] != "")
{
// Yes. Parse the Quality of Signal
int Quality = int.Parse(Words[7], NmeaCultureInfo);
// Notify of the new Signal
if (QualityReceived != null)
QualityReceived(Quality);
// Check the Quality?
// if (Quality = 0)
// if (QualityNotReached != null)
// QualityNotReached();
}
// Indicate that the sentence was recognized
return true;
}
// Interprets a "Satellites in View" NMEA sentence
public bool ParseGPGSV(string sentence)
{
int PseudoRandomCode = 0;
int Azimuth = 0;
int Elevation = 0;
int SignalToNoiseRatio = 0;
// Divide the sentence into words
string[] Words = GetWords(sentence);
// Each sentence contains four blocks of satellite information. Read each block
// and report each satellite's information
int Count = 0;
for (Count = 1; Count <= 4; Count++)
{
// Does the sentence have enough words to analyze?
if ((Words.Length - 1) >= (Count * 4 + 3))
{
// Yes. Proceed with analyzing the block. Does it contain any information?
if (Words[Count * 4] != "" & Words[Count * 4 + 1] != "" & Words[Count * 4 + 2] != "" & Words[Count * 4 + 3] != "")
{
// Yes. Extract satellite information and report it
PseudoRandomCode = System.Convert.ToInt32(Wor ds[Count * 4]);
Elevation = Convert.ToInt32(Words[Coun t * 4 + 1]);
Azimuth = Convert.ToInt32(Words[Coun t * 4 + 2]);
SignalToNoiseRatio = Convert.ToInt32(Words[Coun t * 4 + 2]);
// Notify of this satellite's information
if (SatelliteReceived != null)
SatelliteReceived(PseudoRa ndomCode, Azimuth, Elevation, SignalToNoiseRatio);
}
}
}
// Indicate that the sentence was recognized
return true;
}
// Interprets a "Fixed Satellites and DOP" NMEA sentence
public bool ParseGPGSA(string sentence)
{
// Divide the sentence into words
string[] Words = GetWords(sentence);
// Update the DOP values
if (Words[15] != "")
{
if (PDOPReceived != null)
PDOPReceived(double.Parse( Words[15], NmeaCultureInfo));
}
if (Words[16] != "")
{
if (HDOPReceived != null)
HDOPReceived(double.Parse( Words[16], NmeaCultureInfo));
}
if (Words[17] != "")
{
if (VDOPReceived != null)
VDOPReceived(double.Parse( Words[17], NmeaCultureInfo));
}
return true;
}
// Returns True if a sentence's checksum matches the calculated checksum
public bool IsValid(string sentence)
{
// Compare the characters after the asterisk to the calculation
return sentence.Substring(sentenc e.IndexOf( "*") + 1) == GetChecksum(sentence);
}
// Calculates the checksum for a sentence
public string GetChecksum(string sentence)
{
// Loop through all chars to get a checksum
//INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C#
// char Character = '\0';
int Checksum = 0;
foreach (char Character in sentence)
{
if (Character == '$')
{
// Ignore the dollar sign
}
else if (Character == '*')
{
// Stop processing before the asterisk
break;
}
else
{
// Is this the first value for the checksum?
if (Checksum == 0)
{
// Yes. Set the checksum to the value
Checksum = Convert.ToByte(Character);
}
else
{
// No. XOR the checksum with this character's value
Checksum = Checksum ^ Convert.ToByte(Character);
}
}
}
// Return the checksum formatted as a two-character hexadecimal
return Checksum.ToString("X2");
}
}
}
using System.Collections.Generic
using System.Text;
using System.Globalization;
namespace GPS_Interface
{
public class NmeaInterpreter
{
// Represents the EN-US culture, used for numers in NMEA sentences
public static CultureInfo NmeaCultureInfo = new CultureInfo("en-US");
// Used to convert knots into miles per hour
public static double MPHPerKnot = double.Parse("1.150779", NmeaCultureInfo);
#region Delegates
public delegate void PositionReceivedEventHandl
public delegate void DateTimeChangedEventHandle
public delegate void BearingReceivedEventHandle
public delegate void SpeedReceivedEventHandler(
public delegate void QualityReceivedEventHandle
public delegate void SpeedLimitReachedEventHand
public delegate void FixObtainedEventHandler();
public delegate void FixLostEventHandler();
public delegate void SatelliteReceivedEventHand
public delegate void HDOPReceivedEventHandler(d
public delegate void VDOPReceivedEventHandler(d
public delegate void PDOPReceivedEventHandler(d
#endregion
#region Events
public event PositionReceivedEventHandl
public event DateTimeChangedEventHandle
public event BearingReceivedEventHandle
public event SpeedReceivedEventHandler SpeedReceived;
public event QualityReceivedEventHandle
public event SpeedLimitReachedEventHand
public event FixObtainedEventHandler FixObtained;
public event FixLostEventHandler FixLost;
public event SatelliteReceivedEventHand
public event HDOPReceivedEventHandler HDOPReceived;
public event VDOPReceivedEventHandler VDOPReceived;
public event PDOPReceivedEventHandler PDOPReceived;
#endregion
public int intParseCount = 0;
// Processes information from the GPS receiver
public bool Parse(string sentence)
{
// Discard the sentence if its checksum does not match our calculated checksum
if (!IsValid(sentence)) return false;
// Look at the first word to decide where to go next
switch (GetWords(sentence)[0])
{
case "$GPRMC":
// A "Recommended Minimum" sentence was found!
//if (intParseCount == 0)
//{
// intParseCount = 1;
return ParseGPRMC(sentence);
//}
//else
//{
// return false;
//}
case "$GPGSV":
// A "Satellites in View" sentence was recieved
//if (intParseCount == 0)
//{
// intParseCount = 1;
return ParseGPGSV(sentence);
//}
//else
//{
// return false;
//}
case "$GPGSA":
//if (intParseCount == 0)
//{
// intParseCount = 1;
return ParseGPGSA(sentence);
//}
//else
//{
// return false;
//}
case "$GPGGA":
//if (intParseCount == 0)
//{
// intParseCount = 1;
return ParseGPGGA(sentence);
//}
//else
//{
// return false;
//}
default:
// Indicate that the sentence was not recognized
return false;
}
}
// Divides a sentence into individual words
public string[] GetWords(string sentence)
{
return sentence.Split(',');
}
// Interprets a $GPRMC message
public bool ParseGPRMC(string sentence)
{
// Divide the sentence into words
string[] Words = GetWords(sentence);
// Do we have enough values to describe our location?
if (Words[3] != "" & Words[4] != "" & Words[5] != "" & Words[6] != "")
{
// Yes. Extract latitude and longitude
string Latitude = Words[3].Substring(0, 2) + "°"; // Append degrees
Latitude = Latitude + Words[3].Substring(2) + "' "; // Append minutes
Latitude = Latitude + Words[4]; // Append the hemisphere
string Longitude = Words[5].Substring(0, 3) + "°"; // Append degrees
Longitude = Longitude + Words[5].Substring(3) + "' "; // Append minutes
Longitude = Longitude + Words[6]; // Append the hemisphere
// Notify the calling application of the change
if (PositionReceived != null)
{
PositionReceived(Latitude,
}
else
{
PositionReceived(Latitude,
}
}
// Do we have enough values to parse satellite-derived time?
if (Words[1] != "")
{
// Yes. Extract hours, minutes, seconds and milliseconds
int UtcHours = Convert.ToInt32(Words[1].S
int UtcMinutes = Convert.ToInt32(Words[1].S
int UtcSeconds = Convert.ToInt32(Words[1].S
int UtcMilliseconds = 0;
// Extract milliseconds if it is available
if (Words[1].Length > 7)
{
UtcMilliseconds = Convert.ToInt32(Words[1].S
}
// Now build a DateTime object with all values
System.DateTime Today = System.DateTime.Now.ToUniv
System.DateTime SatelliteTime = new System.DateTime(Today.Year
// Notify of the new time, adjusted to the local time zone
if (DateTimeChanged != null)
DateTimeChanged(SatelliteT
}
// Do we have enough information to extract the current speed?
if (Words[7] != "")
{
// Yes. Parse the speed and convert it to MPH
double Speed = double.Parse(Words[7], NmeaCultureInfo) * MPHPerKnot;
// Notify of the new speed
if (SpeedReceived != null)
SpeedReceived(Speed);
// Are we over the highway speed limit?
if (Speed > 55)
if (SpeedLimitReached != null)
SpeedLimitReached();
}
// Do we have enough information to extract bearing?
if (Words[8] != "")
{
// Indicate that the sentence was recognized
double Bearing = double.Parse(Words[8], NmeaCultureInfo);
if (BearingReceived != null)
BearingReceived(Bearing);
}
// Does the device currently have a satellite fix?
if (Words[2] != "")
{
switch (Words[2])
{
case "A":
if (FixObtained != null)
FixObtained();
break;
case "V":
if (FixLost != null)
FixLost();
break;
}
}
// Indicate that the sentence was recognized
return true;
}
public bool ParseGPGGA(string sentence)
{
// Divide the sentence into words
string[] Words = GetWords(sentence);
// Do we have enough values to describe our location?
if (Words[2] != "" & Words[3] != "" & Words[4] != "" & Words[5] != "")
{
// Yes. Extract latitude and longitude
string Latitude = Words[2].Substring(0, 2) + "°"; // Append degrees
Latitude = Latitude + Words[2].Substring(2) + "' "; // Append minutes
Latitude = Latitude + Words[3]; // Append the hemisphere
string Longitude = Words[4].Substring(0, 3) + "°"; // Append degrees
Longitude = Longitude + Words[4].Substring(3) + "' "; // Append minutes
Longitude = Longitude + Words[5] + " "; // Append the hemisphere
// Notify the calling application of the change
if (PositionReceived != null)
{
PositionReceived(Latitude,
}
else
{
PositionReceived(Latitude,
}
}
// Do we have enough values to parse satellite-derived time?
if (Words[1] != "")
{
// Yes. Extract hours, minutes, seconds and milliseconds
int UtcHours = Convert.ToInt32(Words[1].S
int UtcMinutes = Convert.ToInt32(Words[1].S
int UtcSeconds = Convert.ToInt32(Words[1].S
int UtcMilliseconds = 0;
// Extract milliseconds if it is available
if (Words[1].Length > 7)
{
UtcMilliseconds = Convert.ToInt32(Words[1].S
}
// Now build a DateTime object with all values
System.DateTime Today = System.DateTime.Now.ToUniv
System.DateTime SatelliteTime = new System.DateTime(Today.Year
// Notify of the new time, adjusted to the local time zone
if (DateTimeChanged != null)
DateTimeChanged(SatelliteT
}
// Do we have enough information to extract the current speed?
if (Words[6] != "")
{
// Yes. Parse the Quality of Signal
int Quality = int.Parse(Words[7], NmeaCultureInfo);
// Notify of the new Signal
if (QualityReceived != null)
QualityReceived(Quality);
// Check the Quality?
// if (Quality = 0)
// if (QualityNotReached != null)
// QualityNotReached();
}
// Indicate that the sentence was recognized
return true;
}
// Interprets a "Satellites in View" NMEA sentence
public bool ParseGPGSV(string sentence)
{
int PseudoRandomCode = 0;
int Azimuth = 0;
int Elevation = 0;
int SignalToNoiseRatio = 0;
// Divide the sentence into words
string[] Words = GetWords(sentence);
// Each sentence contains four blocks of satellite information. Read each block
// and report each satellite's information
int Count = 0;
for (Count = 1; Count <= 4; Count++)
{
// Does the sentence have enough words to analyze?
if ((Words.Length - 1) >= (Count * 4 + 3))
{
// Yes. Proceed with analyzing the block. Does it contain any information?
if (Words[Count * 4] != "" & Words[Count * 4 + 1] != "" & Words[Count * 4 + 2] != "" & Words[Count * 4 + 3] != "")
{
// Yes. Extract satellite information and report it
PseudoRandomCode = System.Convert.ToInt32(Wor
Elevation = Convert.ToInt32(Words[Coun
Azimuth = Convert.ToInt32(Words[Coun
SignalToNoiseRatio = Convert.ToInt32(Words[Coun
// Notify of this satellite's information
if (SatelliteReceived != null)
SatelliteReceived(PseudoRa
}
}
}
// Indicate that the sentence was recognized
return true;
}
// Interprets a "Fixed Satellites and DOP" NMEA sentence
public bool ParseGPGSA(string sentence)
{
// Divide the sentence into words
string[] Words = GetWords(sentence);
// Update the DOP values
if (Words[15] != "")
{
if (PDOPReceived != null)
PDOPReceived(double.Parse(
}
if (Words[16] != "")
{
if (HDOPReceived != null)
HDOPReceived(double.Parse(
}
if (Words[17] != "")
{
if (VDOPReceived != null)
VDOPReceived(double.Parse(
}
return true;
}
// Returns True if a sentence's checksum matches the calculated checksum
public bool IsValid(string sentence)
{
// Compare the characters after the asterisk to the calculation
return sentence.Substring(sentenc
}
// Calculates the checksum for a sentence
public string GetChecksum(string sentence)
{
// Loop through all chars to get a checksum
//INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C#
// char Character = '\0';
int Checksum = 0;
foreach (char Character in sentence)
{
if (Character == '$')
{
// Ignore the dollar sign
}
else if (Character == '*')
{
// Stop processing before the asterisk
break;
}
else
{
// Is this the first value for the checksum?
if (Checksum == 0)
{
// Yes. Set the checksum to the value
Checksum = Convert.ToByte(Character);
}
else
{
// No. XOR the checksum with this character's value
Checksum = Checksum ^ Convert.ToByte(Character);
}
}
}
// Return the checksum formatted as a two-character hexadecimal
return Checksum.ToString("X2");
}
}
}
ASKER
Solution Above
Hi cdempster,
I assume you have found solution, or maybe not? If the answer was a Yes, please close the question.
I assume you have found solution, or maybe not? If the answer was a Yes, please close the question.
ASKER
How do you close a question?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could Set a flag from a checkbox in your program that when set will mean to collect data.
Then in your AsynchronouseReader method, you can check that value and choose to write the input or to skip writing the input.