private void DisplayRefresh(object sender, EventArgs e) { double TimeElapse = (DateTime.Now - TimeStart).TotalMilliseconds / 1000; label34.Text = DateTime.Now.ToLongTimeString() + "\r\n" + JY901.GetInstance().ChipTime[0].ToString() + "-" + JY901.GetInstance().ChipTime[1].ToString() + "-" + JY901.GetInstance().ChipTime[2].ToString() + "\r\n" + JY901.GetInstance().ChipTime[3].ToString() + ":" + JY901.GetInstance().ChipTime[4].ToString() + ":" + JY901.GetInstance().ChipTime[5].ToString() + "." + JY901.GetInstance().ChipTime[6].ToString() + "\r\n" + TimeElapse.ToString("f3") + "\r\n\r\n" + JY901.GetInstance().Acceleration[0].ToString("f2") + " g\r\n" + JY901.GetInstance().Acceleration[1].ToString("f2") + " g\r\n" + JY901.GetInstance().Acceleration[2].ToString("f2") + " g\r\n\r\n" + JY901.GetInstance().Palstance[0].ToString("f2") + " °/s\r\n" + JY901.GetInstance().Palstance[1].ToString("f2") + " °/s\r\n" + JY901.GetInstance().Palstance[2].ToString("f2") + " °/s\r\n\r\n" + JY901.GetInstance().Angle[0].ToString("f2") + " °\r\n" + JY901.GetInstance().Angle[1].ToString("f2") + " °\r\n" + JY901.GetInstance().Angle[2].ToString("f2") + " °\r\n\r\n" + JY901.GetInstance().Magnetic[0].ToString("f0") + " mG\r\n" + JY901.GetInstance().Magnetic[1].ToString("f0") + " mG\r\n" + JY901.GetInstance().Magnetic[2].ToString("f0") + " mG\r\n\r\n" + JY901.GetInstance().Temperature.ToString("f2") + " ℃\r\n" + JY901.GetInstance().Pressure.ToString("f0") + " Pa\r\n" + JY901.GetInstance().Altitude.ToString("f2") + " m\r\n\r\n" + (JY901.GetInstance().Longitude / 10000000).ToString("f0") + "°" + ((double)(JY901.GetInstance().Longitude % 10000000) / 1e5).ToString("f5") + "'\r\n" + (JY901.GetInstance().Latitude / 10000000).ToString("f0") + "°" + ((double)(JY901.GetInstance().Latitude % 10000000) / 1e5).ToString("f5") + "'\r\n" + JY901.GetInstance().GPSHeight.ToString("f1") + " m\r\n" + JY901.GetInstance().GPSYaw.ToString("f1") + " °\r\n" + JY901.GetInstance().GroundVelocity.ToString("f3") + " km/h"; }
/// <summary> /// 定义公有方法提供一个全局访问点,同时你也可以定义公有属性来提供全局访问点 /// </summary> /// <returns></returns> /// public static JY901 GetInstance() { // 如果类的实例不存在则创建,否则直接返回 if (_jy901 == null) { _jy901 = new JY901(); } return(_jy901); }
private void MPUNavigation(object sender, EventArgs e) { var mpuYaw = JY901.GetInstance().Angle[2]; LaneDepature laneDepature = new LaneDepature(); var d1Msg = laneDepature.MpuNavigation(mpuYaw)[0]; var d2Msg = laneDepature.MpuNavigation(mpuYaw)[1]; serialPort2.Write(d1Msg); WriteToSendTextBox(serialPort2.PortName + d1Msg + DateTime.Now); serialPort2.Write(d2Msg); WriteToSendTextBox(serialPort2.PortName + d2Msg + DateTime.Now); }
// 获取合适的解释器 protected LMBasePortResolver GetProperResolver(KeyPortData portData) { LMBasePortResolver retval = null; Debug.Log("Port Data Type: " + portData.type); if (portData.type == "jy901") { retval = new JY901(); } else if (portData.type == "m7b" || portData.type == "m7b2D") { retval = new Leadiy_M7B(); } else if (portData.type == "key" || portData.type == "key2D") { retval = new LMKeyResolver(); } return(retval); }
private void DecodeData(byte[] byteTemp) { double[] Data = new double[4]; double TimeElapse = (DateTime.Now - TimeStart).TotalMilliseconds / 1000; Data[0] = BitConverter.ToInt16(byteTemp, 2); Data[1] = BitConverter.ToInt16(byteTemp, 4); Data[2] = BitConverter.ToInt16(byteTemp, 6); Data[3] = BitConverter.ToInt16(byteTemp, 8); switch (byteTemp[1]) { case 0x50: //时间输出 JY901.GetInstance().ChipTime[0] = (short)(2000 + byteTemp[2]); //YY:年,20YY 年 JY901.GetInstance().ChipTime[1] = byteTemp[3]; //MM:月 JY901.GetInstance().ChipTime[2] = byteTemp[4]; //DD:日 JY901.GetInstance().ChipTime[3] = byteTemp[5]; //HH:时 JY901.GetInstance().ChipTime[4] = byteTemp[6]; //MM:分 JY901.GetInstance().ChipTime[5] = byteTemp[7]; //SS:秒 JY901.GetInstance().ChipTime[6] = BitConverter.ToInt16(byteTemp, 8); //MS:毫秒 break; case 0x51: //加速度输出 JY901.GetInstance().Temperature = Data[3] / 100.0; Data[0] = Data[0] / 32768.0 * 16; Data[1] = Data[1] / 32768.0 * 16; Data[2] = Data[2] / 32768.0 * 16; JY901.GetInstance().Acceleration[0] = Data[0]; JY901.GetInstance().Acceleration[1] = Data[1]; JY901.GetInstance().Acceleration[2] = Data[2]; JY901.GetInstance().Acceleration[3] = Data[3]; if ((TimeElapse - LastTime[1]) < 0.1) { return; } LastTime[1] = TimeElapse; break; case 0x52: //角速度输出 JY901.GetInstance().Temperature = Data[3] / 100.0; Data[0] = Data[0] / 32768.0 * 2000; Data[1] = Data[1] / 32768.0 * 2000; Data[2] = Data[2] / 32768.0 * 2000; JY901.GetInstance().Palstance[0] = Data[0]; JY901.GetInstance().Palstance[1] = Data[1]; JY901.GetInstance().Palstance[2] = Data[2]; JY901.GetInstance().Palstance[3] = Data[3]; if ((TimeElapse - LastTime[2]) < 0.1) { return; } LastTime[2] = TimeElapse; break; case 0x53: //角度输出 JY901.GetInstance().Temperature = Data[3] / 100.0; Data[0] = Data[0] / 32768.0 * 180; Data[1] = Data[1] / 32768.0 * 180; Data[2] = Data[2] / 32768.0 * 180; JY901.GetInstance().Angle[0] = Data[0]; JY901.GetInstance().Angle[1] = Data[1]; JY901.GetInstance().Angle[2] = Data[2]; JY901.GetInstance().Angle[3] = Data[3]; if ((TimeElapse - LastTime[3]) < 0.1) { return; } LastTime[3] = TimeElapse; break; case 0x54: //磁场输出 JY901.GetInstance().Temperature = Data[3] / 100.0; JY901.GetInstance().Magnetic[0] = Data[0]; JY901.GetInstance().Magnetic[1] = Data[1]; JY901.GetInstance().Magnetic[2] = Data[2]; JY901.GetInstance().Magnetic[3] = Data[3]; if ((TimeElapse - LastTime[4]) < 0.1) { return; } LastTime[4] = TimeElapse; break; case 0x55: //端口状态数据输出 JY901.GetInstance().Port[0] = Data[0]; JY901.GetInstance().Port[1] = Data[1]; JY901.GetInstance().Port[2] = Data[2]; JY901.GetInstance().Port[3] = Data[3]; break; case 0x56: //气压、高度输出 JY901.GetInstance().Pressure = BitConverter.ToInt32(byteTemp, 2); JY901.GetInstance().Altitude = (double)BitConverter.ToInt32(byteTemp, 6) / 100.0; break; case 0x57: //经纬度输出 JY901.GetInstance().Longitude = BitConverter.ToInt32(byteTemp, 2); JY901.GetInstance().Latitude = BitConverter.ToInt32(byteTemp, 6); break; case 0x58: //地速输出 JY901.GetInstance().GPSHeight = (double)BitConverter.ToInt16(byteTemp, 2) / 10.0; JY901.GetInstance().GPSYaw = (double)BitConverter.ToInt16(byteTemp, 4) / 10.0; JY901.GetInstance().GroundVelocity = BitConverter.ToInt16(byteTemp, 6) / 1e3; break; default: break; } }