Esempio n. 1
0
        public MainForm()
        {
            InitializeComponent();
            m_obdInterface               = new OBDInterface();
            m_obdInterface.OnConnect    += new OBDInterface.__Delegate_OnConnect(On_OBD_Connect);
            m_obdInterface.OnDisconnect += new OBDInterface.__Delegate_OnDisconnect(On_OBD_Disconnect);

            m_originFont = buttonDefaultFontStyle.Font;
            m_boldFont   = new Font(m_originFont, FontStyle.Bold);

            StatusLabelConnStatus.ForeColor = Color.Red;
            StatusLabelConnStatus.Text      = "OBD通讯接口未连接";
            StatusLabelDeviceName.Text      = "未获取到设备名";
            StatusLabelAppProtocol.Text     = "应用层协议待定";
            StatusLabelCommProtocol.Text    = m_obdInterface.GetProtocol().ToString();
            StatusLabelDeviceType.Text      = m_obdInterface.GetDevice().ToString();
            if (m_obdInterface.CommSettings != null)
            {
                if (m_obdInterface.CommSettings.AutoDetect)
                {
                    StatusLabelPort.Text = "自动探测";
                }
                else
                {
                    StatusLabelPort.Text = m_obdInterface.CommSettings.ComPortName;
                }
            }

            InitSubForm();
            this.Text = "SH_OBD - Ver " + MainFileVersion.AssemblyVersion;
        }
Esempio n. 2
0
        private void ToolStripBtnSettings_Click(object sender, EventArgs e)
        {
            Settings     commSettings = m_obdInterface.CommSettings;
            DBandMES     dbandMES     = m_obdInterface.DBandMES;
            SettingsForm settingsForm = new SettingsForm(commSettings, dbandMES);

            settingsForm.ShowDialog();
            m_obdInterface.SaveCommSettings(commSettings);
            m_obdInterface.SaveDBandMES(dbandMES);
            StatusLabelCommProtocol.Text = m_obdInterface.GetProtocol().ToString();
            StatusLabelDeviceType.Text   = m_obdInterface.GetDevice().ToString();
            if (commSettings.AutoDetect)
            {
                StatusLabelPort.Text = "自动探测";
            }
            else
            {
                StatusLabelPort.Text = commSettings.ComPortName;
            }
            settingsForm.Dispose();
        }
Esempio n. 3
0
        public void UpdateTests()
        {
            progressBar.Minimum = 0;
            progressBar.Maximum = 35;
            OBDParameterValue value;

            value             = m_obdInterface.GetValue("SAE.MISFIRE_SUPPORT");
            progressBar.Value = 1;
            TestStatus status = m_ListConTests[0];

            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.MISFIRE_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.FUEL_SUPPORT");
            progressBar.Value = 2;
            status            = m_ListConTests[1];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.FUEL_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.CCM_SUPPORT");
            progressBar.Value = 3;
            status            = m_ListConTests[2];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.CCM_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }
            gridConTests.Refresh();

            value             = m_obdInterface.GetValue("SAE.CAT_SUPPORT");
            progressBar.Value = 4;
            status            = m_ListNonConTests[0];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.CAT_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.HCAT_SUPPORT");
            progressBar.Value = 5;
            status            = m_ListNonConTests[1];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.HCAT_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.EVAP_SUPPORT");
            progressBar.Value = 6;
            status            = m_ListNonConTests[2];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.EVAP_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.AIR_SUPPORT");
            progressBar.Value = 7;
            status            = m_ListNonConTests[3];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.AIR_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.AC_SUPPORT");
            progressBar.Value = 8;
            status            = m_ListNonConTests[4];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.AC_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.O2_SUPPORT");
            progressBar.Value = 9;
            status            = m_ListNonConTests[5];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.O2_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.O2HTR_SUPPORT");
            progressBar.Value = 10;
            status            = m_ListNonConTests[6];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.O2HTR_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }

            value             = m_obdInterface.GetValue("SAE.EGR_SUPPORT");
            progressBar.Value = 11;
            status            = m_ListNonConTests[7];
            if (!value.ErrorDetected)
            {
                if (!value.BoolValue)
                {
                    status.Status = "不适用";
                }
                else
                {
                    value = m_obdInterface.GetValue("SAE.EGR_STATUS");
                    if (!value.ErrorDetected)
                    {
                        status.Status = value.BoolValue ? "完成" : "未完成";
                    }
                    else
                    {
                        status.Status = "出错";
                    }
                }
            }
            else
            {
                status.Status = "出错";
            }
            gridNonConTests.Refresh();

            if (m_obdInterface.IsParameterSupported("SAE.FUEL1_STATUS"))
            {
                value = m_obdInterface.GetValue("SAE.FUEL1_STATUS");
                progressBar.Value++;
                lblFuel1.Text = value.ErrorDetected ? "出错" : value.StringValue;
            }
            else
            {
                lblFuel1.Text = "不适用";
            }

            if (m_obdInterface.IsParameterSupported("SAE.FUEL2_STATUS"))
            {
                value = m_obdInterface.GetValue("SAE.FUEL2_STATUS");
                progressBar.Value++;
                lblFuel2.Text = value.ErrorDetected ? "出错" : value.StringValue;
            }
            else
            {
                lblFuel2.Text = "不适用";
            }

            if (m_obdInterface.IsParameterSupported("SAE.PTO_STATUS"))
            {
                value = m_obdInterface.GetValue("SAE.PTO_STATUS");
                progressBar.Value++;
                lblPTO.Text = value.ErrorDetected ? "出错" : value.StringValue;
            }
            else
            {
                lblPTO.Text = "不适用";
            }

            if (m_obdInterface.IsParameterSupported("SAE.SECAIR_STATUS"))
            {
                value = m_obdInterface.GetValue("SAE.SECAIR_STATUS");
                progressBar.Value++;
                lblAir.Text = value.ErrorDetected ? "出错" : value.StringValue;
            }
            else
            {
                lblAir.Text = "不适用";
            }

            if (m_obdInterface.IsParameterSupported("SAE.OBD_TYPE"))
            {
                value = m_obdInterface.GetValue("SAE.OBD_TYPE");
                progressBar.Value++;
                lblOBD.Text = value.ErrorDetected ? "出错" : value.StringValue;
            }
            else
            {
                lblOBD.Text = "不适用";
            }

            string       strContent = "";
            OBDParameter param      = new OBDParameter {
                OBDRequest = "0902",
                Service    = 9,
                Parameter  = 2,
                ValueTypes = (int)OBDParameter.EnumValueTypes.ListString
            };
            OBDParameterValue val = m_obdInterface.GetValue(param);

            progressBar.Value++;
            strContent += "VIN:";
            foreach (string item in val.ListStringValue)
            {
                strContent += "\n" + item;
            }

            param.OBDRequest = "0904";
            val = m_obdInterface.GetValue(param);
            progressBar.Value++;
            strContent += "\n\nCAL ID:";
            foreach (string item in val.ListStringValue)
            {
                strContent += "\n" + item;
            }

            param.OBDRequest = "0906";
            val = m_obdInterface.GetValue(param);
            progressBar.Value++;
            strContent += "\n\nCVN:";
            foreach (string item in val.ListStringValue)
            {
                strContent += "\n" + item;
            }

            //param.OBDRequest = "0908";
            //param.SubParameter = 0;
            //val = m_obdInterface.GetValue(param);
            //progressBar.Value++;
            //strContent += "\n\nIPT:";
            //strContent += "\n" + val.DoubleValue;
            ////foreach (string item in val.ListStringValue) {
            ////    strContent += "," + Utility.Hex2Int(item);
            ////}

            param.OBDRequest = "090A";
            val = m_obdInterface.GetValue(param);
            progressBar.Value++;
            strContent += "\n\nECU名称:";
            foreach (string item in val.ListStringValue)
            {
                strContent += "\n" + item;
            }

            lblVehicleInfo.Text = strContent;
            progressBar.Value++;

            /*string strContent = "";
             * string strHeader;
             * int counter;
             *
             * if (m_obd2Interface.IsParameterSupported("SAE.O2B1S1A_PRESENT")) {
             *  strHeader = "PID $13 Bank 1: ";
             *  strContent += strHeader;
             *  counter = 0;
             *  value = m_obd2Interface.GetValue("SAE.O2B1S1A_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 1, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B1S2A_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 2, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B1S3A_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 3, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B1S4A_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 4, ";
             ++counter;
             *  }
             *  if (counter == 0) {
             *      strContent = strContent.Substring(0, strContent.Length - strHeader.Length);
             *  } else {
             *      strContent = strContent.Substring(0, strContent.Length - 2);
             *  }
             *
             *  strHeader = "\n\r\nPID $13 Bank 2: ";
             *  strContent += strHeader;
             *  counter = 0;
             *  value = m_obd2Interface.GetValue("SAE.O2B2S1A_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 1, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B2S2A_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 2, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B2S3A_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 3, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B2S4A_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 4, ";
             ++counter;
             *  }
             *  if (counter == 0) {
             *      strContent = strContent.Substring(0, strContent.Length - strHeader.Length);
             *  } else {
             *      strContent = strContent.Substring(0, strContent.Length - 2);
             *  }
             * }
             *
             * if (m_obd2Interface.IsParameterSupported("SAE.O2B1S1B_PRESENT")) {
             *  strHeader = "\n\r\nPID $1D Bank 1: ";
             *  strContent += strHeader;
             *  counter = 0;
             *  value = m_obd2Interface.GetValue("SAE.O2B1S1B_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 1, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B1S2B_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 2, ";
             ++counter;
             *  }
             *  if (counter == 0) {
             *      strContent = strContent.Substring(0, strContent.Length - strHeader.Length);
             *  } else {
             *      strContent = strContent.Substring(0, strContent.Length - 2);
             *  }
             *
             *  strHeader = "\n\r\nPID $1D Bank 2: ";
             *  strContent += strHeader;
             *  counter = 0;
             *  value = m_obd2Interface.GetValue("SAE.O2B2S1B_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 1, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B2S2B_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 2, ";
             ++counter;
             *  }
             *  if (counter == 0) {
             *      strContent = strContent.Substring(0, strContent.Length - strHeader.Length);
             *  } else {
             *      strContent = strContent.Substring(0, strContent.Length - 2);
             *  }
             *
             *  strHeader = "\n\r\nPID $1D Bank 3: ";
             *  strContent += strHeader;
             *  counter = 0;
             *  value = m_obd2Interface.GetValue("SAE.O2B3S1B_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 1, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B3S2B_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 2, ";
             ++counter;
             *  }
             *  if (counter == 0) {
             *      strContent = strContent.Substring(0, strContent.Length - strHeader.Length);
             *  } else {
             *      strContent = strContent.Substring(0, strContent.Length - 2);
             *  }
             *
             *  strHeader = "\n\r\nPID $1D Bank 4: ";
             *  strContent += strHeader;
             *  counter = 0;
             *  value = m_obd2Interface.GetValue("SAE.O2B4S1B_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 1, ";
             ++counter;
             *  }
             *
             *  value = m_obd2Interface.GetValue("SAE.O2B4S2B_PRESENT");
             *  progressBar.Value++;
             *  if (!value.ErrorDetected && value.BoolValue) {
             *      strContent += "传感器 2, ";
             ++counter;
             *  }
             *  if (counter == 0) {
             *      strContent = strContent.Substring(0, strContent.Length - strHeader.Length);
             *  } else {
             *      strContent = strContent.Substring(0, strContent.Length - 2);
             *  }
             * }*/
            if (m_obdInterface.GetDevice() == HardwareType.ELM327)
            {
                value = m_obdInterface.GetValue("ELM.BATTERY_VOLTAGE");
                if (!value.ErrorDetected)
                {
                    lblBattery.Text = value.DoubleValue.ToString() + " V";
                }
            }
            else
            {
                lblBattery.Text = "不适用";
            }
            progressBar.Value = progressBar.Maximum;
        }