Example #1
0
        public bool buildO2Locations()
        {
            int iPID;

            if (isPIDSupported(1, 19))
            {
                iPID = 19;
            }
            else
            {
                if (!isPIDSupported(1, 29))
                {
                    return(false);
                }
                iPID = 29;
            }
            OBD2Response response = getResponse(new OBD2Request(1, iPID));

            if (response == null || (string.Compare(response.Request, "0113") != 0 && string.Compare(response.Request, "011D") != 0))
            {
                return(false);
            }

            int index = 7;

            do
            {
                m_bO2Locations[index] = ((int)Math.Pow(2.0, (double)index) & response.DataA) != 0;
                --index;
            }while (index >= 0);
            return(true);
        }
Example #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            double value = 0.0;
            int    valid = 0;

            if (!m_obd2Interface.Connected)
            {
                MessageBox.Show("A vehicle connection must first be established. \n\n" + "Please enable communications and check all wiring connections.", "Connection Required", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                int count = 0;
                do
                {
                    OBD2Response response1 = m_obd2Interface.getResponse(new OBD2Request("010D"));
                    OBD2Response response2 = m_obd2Interface.getResponse(new OBD2Request("010C"));
                    OBD2Response response3 = m_obd2Interface.getResponse(new OBD2Request("010D"));
                    if (response1 != null && response2 != null && response3 != null)
                    {
                        double   value1       = response1.getValue(0).MetricValue;
                        double   value2       = response3.getValue(0).MetricValue;
                        double   value3       = response2.getValue(0).MetricValue;
                        double   totalSeconds = response2.Date.Subtract(response1.Date).TotalSeconds;
                        TimeSpan timeSpan     = response3.Date.Subtract(response1.Date);
                        value = (totalSeconds / timeSpan.TotalSeconds * (value2 - value1) + value1) / value3 + value;
                        ++valid;
                    }
                    progressBar.Value = count;
                    count            += 5;
                }while (count < 100);
                lblRatio.Text = (value / (double)valid).ToString("0.000000");
            }
        }
Example #3
0
 public OBD2Response getResponse(OBD2Request obd2Request)
 {
     try
     {
         OnSent(obd2Request);
         m_commLog.Add(EventType.Transmit, "Tx: " + obd2Request.Request);
         string message = m_obd2Comm.getResponse(obd2Request.Request);
         Debug.WriteLine(obd2Request.Request);
         Debug.WriteLine(message);
         if (message.Length > 0)
         {
             string strData    = "Rx: " + message;
             bool   bATCommand = false;
             if (obd2Request.Request.IndexOf("AT") >= 0)
             {
                 bATCommand = true;
             }
             m_commLog.Add(EventType.Receive, strData);
             OBD2Response response = new OBD2Response(message, bATCommand, true, m_iProtocol);
             strData = string.Concat(strData, response.Data, "]", "  (", obd2Request.Request, ")");
             m_commLog.Add(EventType.Receive, strData);
             OnReceived(response);
             return(response);
         }
         m_commLog.Add(EventType.Timeout, "Rx: Request Timed Out.  (" + obd2Request.Request + ")");
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.ToString());
         m_commLog.Add(EventType.Message, "OBD2Interface Error. (" + exception.ToString() + ")");
     }
     return(null);
 }
Example #4
0
        public bool InitializeOBD2()
        {
            OBD2Response response = getResponse(new OBD2Request("ATDPN"));

            if (response == null)
            {
                return(false);
            }
            m_iProtocol = OBD2.Hex2Int(response.Response.Replace("A", ""));
            if (!buildPIDSupportStatusList(1))
            {
                return(false);
            }
            buildO2Locations();
            return(true);
        }
Example #5
0
 public void ReceiveResponse(OBD2Response obd2Response)
 {
 }
Example #6
0
 public void ReceiveResponse(OBD2Response obd2Response)
 {
 }
Example #7
0
 private void On_OBD2_Received(OBD2Response obd2Response)
 {
     panelRx.Text = "Rx: " + obd2Response.Response;
 }
Example #8
0
 private void BroadcastResponse(OBD2Response obd2Response)
 {
 }
Example #9
0
        public bool buildPIDSupportStatusList(int iService)
        {
            bool[] flagArray;
            if (iService != 1)
            {
                if (iService != 2)
                {
                    return(false);
                }
                flagArray = m_bService02PIDSupport;
            }
            else
            {
                flagArray = m_bService01PIDSupport;
            }
            int index = 0;

            do
            {
                flagArray[index] = false;
                index++;
            }while (index < 256);

            int iPID = 0;

            do
            {
                Debug.WriteLine("BuildPIDSupportStatusList");
                OBD2Response response = getResponse(new OBD2Request(iService, iPID));
                Debug.Write(response.Response);
                if (response == null)
                {
                    return(false);
                }
                if (response.ResponseType != OBD2Response.ResponseTypes.HexData)
                {
                    return(false);
                }
                Debug.WriteLine("Hex Data");
                Debug.WriteLine(response.PID);
                Debug.WriteLine(OBD2.Int2HexString(iPID));
                if (string.Compare(response.PID, OBD2.Int2HexString(iPID)) != 0)
                {
                    return(false);
                }
                Debug.WriteLine("Correct PID");
                int iECU = 0;
                if (0 < response.getECUResponseCount())
                {
                    do
                    {
                        int iByte = 0;
                        int num4  = 0;
                        do
                        {
                            int num2 = 7;
                            do
                            {
                                if ((response.getDataByte(iECU, iByte) & ((int)Math.Pow(2.0, (double)num2))) != 0)
                                {
                                    flagArray[(iPID + (num4 - num2)) + 8] = true;
                                }
                                num2--;
                            }while (num2 >= 0);
                            iByte++;
                            num4 += 8;
                        }while (num4 <= 0x18);
                        iECU++;
                    }while (iECU < response.getECUResponseCount());
                }
                Debug.Write("PID SUPPORT FLAGS: ");

                int num3 = 0;
                do
                {
                    if (flagArray[num3])
                    {
                        Debug.Write("T");
                    }
                    else
                    {
                        Debug.Write("F");
                    }
                    num3++;
                }while (num3 < 33);

                iPID = iPID + 32;
                if (!flagArray[iPID])
                {
                    break;
                }
            }while (iPID < 0x100);
            return(true);
        }
Example #10
0
        public bool DetectAndOpenComPort()
        {
            m_commLog.Add(EventType.Message, "Using Automatic Hardware Detection");
            int iComPort = 0;

            do
            {
                if (isPortAvailable(iComPort))
                {
                    m_obd2Comm.setPort(iComPort);
                    m_commLog.Add(EventType.Message, "Trying 38400 baud...");
                    m_obd2Comm.setBaudRate(0x9600);
                    if (m_obd2Comm.Open())
                    {
                        string strData = string.Format("Comm Port {0} successfully opened.", iComPort);
                        m_commLog.Add(EventType.PortOpened, strData);
                        if (((getResponse(new OBD2Request("ATZ")) != null) && (getResponse(new OBD2Request("ATE0")) != null)) && ((getResponse(new OBD2Request("ATL0")) != null) && (getResponse(new OBD2Request("ATH1")) != null)))
                        {
                            OBD2Response response2 = getResponse(new OBD2Request("ATI"));
                            if ((response2.Response.Length >= 3) && (response2.Response.IndexOf("ELM") >= 0))
                            {
                                int index = response2.Response.IndexOf("ELM");
                                ChipInfo = response2.Response.Substring(index);
                                return(true);
                            }
                        }
                        m_obd2Comm.Close();
                    }
                    else
                    {
                        string str3 = string.Format("Comm Port {0} failed to open.", iComPort);
                        m_commLog.Add(EventType.PortFailed, str3);
                    }
                    m_commLog.Add(EventType.Message, "Trying 9600 baud...");
                    m_obd2Comm.setBaudRate(0x2580);
                    if (m_obd2Comm.Open())
                    {
                        string str2 = string.Format("Comm Port {0} successfully opened.", iComPort);
                        m_commLog.Add(EventType.PortOpened, str2);
                        if (((getResponse(new OBD2Request("ATZ")) != null) && (getResponse(new OBD2Request("ATE0")) != null)) && ((getResponse(new OBD2Request("ATL0")) != null) && (getResponse(new OBD2Request("ATH1")) != null)))
                        {
                            OBD2Response response = getResponse(new OBD2Request("ATI"));
                            if ((response.Response.Length >= 3) && (response.Response.IndexOf("ELM") >= 0))
                            {
                                int startIndex = response.Response.IndexOf("ELM");
                                ChipInfo = response.Response.Substring(startIndex);
                                return(true);
                            }
                        }
                        m_obd2Comm.Close();
                    }
                    else
                    {
                        string str = string.Format("Comm Port {0} failed to open.", iComPort);
                        m_commLog.Add(EventType.PortFailed, str);
                    }
                }
                iComPort++;
            }while (iComPort < 50);
            m_commLog.Add(EventType.Message, "Could not detect compatible OBD-II interface on any port.");
            return(false);
        }
Example #11
0
 public OBD2Response getResponse(OBD2Request obd2Request)
 {
     try
     {
         OnSent(obd2Request);
         m_commLog.Add(EventType.Transmit, "Tx: " + obd2Request.Request);
         string message = m_obd2Comm.getResponse(obd2Request.Request);
         Debug.WriteLine(obd2Request.Request);
         Debug.WriteLine(message);
         if (message.Length > 0)
         {
             string strData = "Rx: " + message;
             bool bATCommand = false;
             if (obd2Request.Request.IndexOf("AT") >= 0)
             {
                 bATCommand = true;
             }
             m_commLog.Add(EventType.Receive, strData);
             OBD2Response response = new OBD2Response(message, bATCommand, true, m_iProtocol);
             strData = string.Concat(strData, response.Data, "]", "  (", obd2Request.Request, ")");
             m_commLog.Add(EventType.Receive, strData);
             OnReceived(response);
             return response;
         }
         m_commLog.Add(EventType.Timeout, "Rx: Request Timed Out.  (" + obd2Request.Request + ")");
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.ToString());
         m_commLog.Add(EventType.Message, "OBD2Interface Error. (" + exception.ToString() + ")");
     }
     return null;
 }