Example #1
0
        public bool ReadDTCCodes(out List<string> list)
        {
            list = new List<string>();
            LogDataString("ReadDTCCodes");
            KWPReply reply = new KWPReply();
            KWPResult result;
            byte[] data = new byte[2];
            data[0] = (byte)0xFF;
            data[1] = (byte)0xFF;
            //data[2] = (byte)0x00;
            // Status byte
            // 7 Warning lamp illuminated for this code
            // 6 Warning lamp pending for this code, not illuminate but malfunction was detected
            // 5 Warning lamp was previously illuminated for this code, malfunction not currently detected, code not yet erased
            // 4 Stored trouble code
            // 3 Manufacturer specific status
            // 2 Manufacturer specific status
            // 1 Current code - present at time of request
            // 0 Maturing/intermittent code - insufficient data to consider as a malfunction
            KWPRequest req = new KWPRequest(0x18 , 0x02); // Request Diagnostic Trouble Codes by Status
            Console.WriteLine(req.ToString());
            result = sendRequest(req, out reply);
            Console.WriteLine(reply.ToString());
            // J2190
            // Multiple Mode $58 response messages may be reported to a single request, depending on the number of diagnostic
            // trouble codes stored in the module. Each response message will report up to three DTCs for
            // which at least one of the requested status bits is set. If no codes are stored in the module that meet the
            // requested status, then the module will respond with the following:
            // Reply: 58,00
            if (reply.getMode() == 0x58)
            {
                if (reply.getPid() == 0x00)
                {
                    Console.WriteLine("No DTC's");
                    list.Add("No DTC's");
                    return true;
                }
                else
                {
                    //P0605
                    //P1231
                    //P1230
                    //P1530
                    //P1606
                    //P1460
                    //+		reply	{Reply:   14,58,
                    // 06,
                    // 06,05,E4,
                    // 12,31,48,
                    // 12,30,E8,
                    // 15,30,E1,
                    // 16,06,E8,
                    // 14,60,41}	TrionicCANLib.KWP.KWPReply
                    uint number = reply.getPid();
                    byte[] dtc = new byte[number*2];

                    byte[] read = reply.getData();
                    int j = 0;
                    int i = 0;
                    while(i < read.Length)
                    {
                        dtc[j++] = read[i++];
                        dtc[j++] = read[i++];
                        i++;
                    }

                    for (int n = 0; n < dtc.Length; n = n + 2)
                    {
                        list.Add("DTC: P" + dtc[n].ToString("X2") + dtc[n+1].ToString("X2"));
                    }
                }

            }

            return false;
        }
Example #2
0
        /// <summary>
        /// This method sets the E85 level.
        /// </summary>
        /// <param name="a_level">The E85 level.</param>
        /// <returns>KWPResult</returns>
        public KWPResult setE85Level(int a_level)
        {
            KWPReply reply = new KWPReply();
            KWPResult result;
            int sendlevel = a_level * 10;
            byte[] level = new byte[2];
            level[0] = (byte)(sendlevel >> 8);
            level[1] = (byte)sendlevel;
            result = sendRequest(new KWPRequest(0x3B, 0xA7, level), out reply);
            if(reply.getMode() == 0x7B && reply.getPid() == 0xA7)
            {
                return KWPResult.OK;
            }
            else if(reply.getMode() == 0x7F && reply.getPid() == 0x3B && reply.getLength() == 3)
            {
                Console.WriteLine(TranslateErrorCode(reply.getData()[0]));
            }

            return KWPResult.NOK;
        }
Example #3
0
        /// <summary>
        /// This method requests the E85 level.
        /// </summary>
        /// <param name="r_level">The requested E85 level.</param>
        /// <returns>KWPResult</returns>
        public KWPResult getE85Level(out float r_level)
        {
            KWPReply reply = new KWPReply();
            KWPResult result;
            float level;

            result = sendRequest(new KWPRequest(0x21, 0xA7), out reply); // Request Diagnostic Data Mode $21 - Offset (1 byte)
            if (reply.getMode() == 0x61 && reply.getPid() == 0xA7 && reply.getLength() == 4)
            {
                level = (reply.getData()[0] << 8) | reply.getData()[1];
                r_level = level / 10;
                return KWPResult.OK;
            }
            else if (reply.getMode() == 0x7F && reply.getPid() == 0x21 && reply.getLength() == 3)
            {
                Console.WriteLine(TranslateErrorCode(reply.getData()[0]));
            }
            r_level = 0;
            return KWPResult.NOK;
        }