Example #1
0
        public List <Tuple <DiagnosticTroubleCode, string> > RequestAllDtcStatuses(OBD2.Cables.Cable cable)
        {
            List <Tuple <DiagnosticTroubleCode, string> > statuses = new List <Tuple <DiagnosticTroubleCode, string> >();

            string response = cable.Communicate(this, 5000);

            string[] responses = ParameterIdentification.PrepareResponseString(response);
            if (responses != null)
            {
                foreach (string individualResponse in responses)
                {
                    byte[] responseBytes = ParameterIdentification.ParseStringValues(individualResponse);
                    if (responseBytes != null)
                    {
                        if (responseBytes.Length == 4)
                        {
                            if (responseBytes[0] - 0x40 == this.Mode)
                            {
                                string firstByte  = responseBytes[1].ToString(Protocols.ToHexFormat);
                                string secondByte = responseBytes[2].ToString(Protocols.ToHexFormat);

                                // the code is still in elm327 encoded format, e.g. "4670" which would be DTC B0670
                                string elm327code          = firstByte + secondByte;
                                DiagnosticTroubleCode code = new DiagnosticTroubleCode(elm327code, DiagnosticTroubleCode.CodeType.StatusCheck);

                                string codeStatusDescription = GetStatusDescription(responseBytes[3]);

                                statuses.Add(new Tuple <DiagnosticTroubleCode, string>(code, codeStatusDescription));
                            }
                            else
                            {
                                Diagnostics.DiagnosticLogger.Log("Invalid mode for mode 19 response line \"" + individualResponse + "\"");
                            }
                        }
                        else
                        {
                            Diagnostics.DiagnosticLogger.Log("Received a mode 19 response line that did not have 4 bytes. Received \"" + individualResponse + "\"");
                        }
                    }
                    else
                    {
                        Diagnostics.DiagnosticLogger.Log("ParseStringValues() returned null for response \"" + individualResponse ?? string.Empty + "\"");
                    }
                }
            }
            else
            {
                Diagnostics.DiagnosticLogger.Log("PrepareResponseString() returned null for \"" + response ?? string.Empty + "\"");
            }

            return(statuses);
        }
Example #2
0
        public string RequestVIN(OBD2.Cables.Cable cable)
        {
            string dataStr = cable.Communicate(this);

            string[] dataLines = ParameterIdentification.PrepareResponseString(dataStr);
            string   vin       = string.Empty;

            try
            {
                if (dataLines != null && dataLines.Length > 0)
                {
                    dataLines = prepMarkedLines(dataLines);
                    foreach (String line in dataLines)
                    {
                        byte[] dataBytes = ParameterIdentification.ParseStringValues(line);
                        if (dataBytes.Length >= 7)
                        {
                            byte receivedMode = (byte)(dataBytes[0] - 0x40);
                            if (receivedMode == this.Mode)
                            {
                                for (int i = 3; i < dataBytes.Length; i++)
                                {
                                    if (dataBytes[i] != 0)
                                    {
                                        vin += Convert.ToChar(dataBytes[i]);
                                    }
                                }
                            }
                            else
                            {
                                Diagnostics.DiagnosticLogger.Log("Cannot decode VIN, expected mode " + this.Mode + " and received " + receivedMode);
                                return(null);
                            }
                        }
                        else
                        {
                            Diagnostics.DiagnosticLogger.Log("Cannot decode VIN, expected at least 7 characters in line \"" + line + "\" and received " + dataBytes.Length);
                            return(null);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Diagnostics.DiagnosticLogger.Log("Could not decode VIN, exception occurred", ex);
            }

            return(vin);
        }
        public List <DiagnosticTroubleCode> RequestTroubleCodes(OBD2.Cables.Cable cable)
        {
            // TODO: set frame headers for other protocols

            // set the frame header to the default PCM for the main engine codes
            if (cable.Protocol == Protocols.Protocol.HighSpeedCAN11 ||
                cable.Protocol == Protocols.Protocol.LowSpeedCAN11)
            {
                Protocols.Elm327.SetFrameHeader(Protocols.CAN.Headers.Default);
            }
            else if (cable.Protocol == Protocols.Protocol.VPW)
            {
                Protocols.Elm327.SetFrameHeader(Protocols.J1850.Headers.Default);
            }

            return(GetDtc(cable, this, CodeType));
        }