public void ReadGPVTG(string[] strGPS, GPVTG gpvtg) { gpvtg.TNGroundAzimuth = string.IsNullOrEmpty(strGPS[1]) ? 0 : Convert.ToDouble(strGPS[1]); gpvtg.MNGroundAzimuth = string.IsNullOrEmpty(strGPS[3]) ? 0 : Convert.ToDouble(strGPS[3]); gpvtg.GroundSpeed = string.IsNullOrEmpty(strGPS[5]) ? 0 : Convert.ToDouble(strGPS[5]); gpvtg.GroundSpeedKilometer = string.IsNullOrEmpty(strGPS[7]) ? 0 : Convert.ToDouble(strGPS[7]); gpvtg.ModeIndication = string.IsNullOrEmpty(strGPS[9]) ? ' ' : Convert.ToChar(strGPS[9]); }
//private static GpsTranslation; private void DataReceived(object sender, SerialDataReceivedEventArgs e) { string strRecv; string[] strGPS; strRecv = serialPort.ReadLine(); int index = strRecv.IndexOf('$'); if (index == -1) { return; } else { strRecv.Remove(0, index); } strGPS = strRecv.Replace('*', ',').Split(','); GpsProcess gpsProcess = new GpsProcess(); switch (strGPS[0]) { case "$GPGGA": { //GPS定位信息 if (strGPS.Length < 13) { return; } GPGGA gpgga = new GPGGA(); gpsProcess.ReadGPGGA(strGPS, gpgga); BeginInvoke(new MethodInvoker(delegate() { gpsProcess.WriteGPGGA(gpgga); xy = GpsTranslation.wgs2bd(gpsProcess.Latitude, gpsProcess.Longitude); Jd.Text = "经度:" + xy[0].ToString(); //lon Wd.Text = "纬度:" + xy[1].ToString(); //lat })); break; } case "$GPVTG": { //地面速度信息 if (strGPS.Length < 10) { return; } GPVTG gpvtg = new GPVTG(); gpsProcess.ReadGPVTG(strGPS, gpvtg); BeginInvoke(new MethodInvoker(delegate() { speed.Text = "速度:" + gpsProcess.WriteGPVTG(gpvtg); })); break; } default: break; } }
/* * public void WriteGPRMC(GPRMC gprmc) * { * label_wd.Text = gprmc.Longitude.ToString() + gprmc.LongitudeEW; * label_jd.Text = gprmc.Latitude.ToString() + gprmc.LatitudeNS; * * label_dmhx.Text = gprmc.GroundAzimuth.ToString(); * label_dmsl.Text = gprmc.GroundSpeed.ToString(); * label_cpj.Text = gprmc.DeclinationAngle.ToString(); * label_utcrq.Text = gprmc.UTCDate.ToLongDateString(); * label_mszs.Text = gprmc.ModeIndication.ToString(); * * if (gprmc.DeclinationDirection.ToString() == "E")//E(东)或W(西) * label_cpjfx.Text = "东"; * else if (gprmc.DeclinationDirection.ToString() == "W") * label_cpjfx.Text = "西"; * else * label_cpjfx.Text = ""; * * if (gprmc.ModeIndication.ToString() == "A")//(仅NMEA0183 3.00版本输出,A=自主定位,D=差分,E=估算,N=数据无效) * label_mszs.Text = "自主定位"; * else if (gprmc.ModeIndication.ToString() == "D") * label_mszs.Text = "差分"; * else if (gprmc.ModeIndication.ToString() == "E") * label_mszs.Text = "估算"; * else if (gprmc.ModeIndication.ToString() == "N") * label_mszs.Text = "数据无效"; * else * label_mszs.Text = ""; * * if (gprmc.LocationStatus.ToString() == "A")//A=有效定位,V=无效定位 * label_dwzt.Text = "有效定位"; * else if (gprmc.LocationStatus.ToString() == "V") * label_dwzt.Text = "无效定位"; * else * label_dwzt.Text = ""; * } * public void WriteGPGSA(GPGSA gpgsa) * { * * label_sywxbh.Text = gpgsa.PRN1.ToString() + "|" + gpgsa.PRN2.ToString() + "|" + * gpgsa.PRN3.ToString() + "|" + gpgsa.PRN4.ToString() + "|" + * gpgsa.PRN5.ToString() + "|" + gpgsa.PRN6.ToString() + "|" + * gpgsa.PRN7.ToString() + "|" + gpgsa.PRN8.ToString() + "|" + * gpgsa.PRN9.ToString() + "|" + gpgsa.PRN10.ToString() + "|" + * gpgsa.PRN11.ToString() + "|" + gpgsa.PRN12.ToString(); * * label_vdop_yz.Text = gpgsa.VDOP.ToString(); * label_hdop_yz.Text = gpgsa.HDOP.ToString(); * label_pdop_yz.Text = gpgsa.PDOP.ToString(); * //label_sywxbh.Text = gpgsa; * * if (gpgsa.Location == '1') * labe_dwxs.Text = "未定位"; * else if (gpgsa.Location == '2') * labe_dwxs.Text = "二维定位"; * else if (gpgsa.Location == '3') * labe_dwxs.Text = "三维定位"; * else * labe_dwxs.Text = ""; * * if (gpgsa.Mode == 'M') * label_ms.Text = "手动"; * else if (gpgsa.Mode == 'M') * label_ms.Text = "自动"; * else * label_ms.Text = ""; * * }*/ public string WriteGPVTG(GPVTG gpvtg) {/* * if (gpvtg.ModeIndication.ToString() == "A") * label_mszs1.Text = "自主定位"; * else if (gpvtg.ModeIndication.ToString() == "D") * label_mszs1.Text = "差分"; * else if (gpvtg.ModeIndication.ToString() == "E") * label_mszs1.Text = "估算"; * else if (gpvtg.ModeIndication.ToString() == "N") * label_mszs1.Text = "数据无效"; * else * label_mszs1.Text = ""; * * label_dmsl2.Text = gpvtg.GroundSpeedKilometer.ToString(); * label_dmsl1.Text = gpvtg.GroundSpeed.ToString(); * label_dmhx2.Text = gpvtg.MNGroundAzimuth.ToString(); * label_dmhx1.Text = gpvtg.TNGroundAzimuth.ToString(); */ return(gpvtg.GroundSpeed.ToString()); }/*