Page 1 of 4 1234 LastLast
Results 1 to 10 of 36

Thread: code wizards, help with some coding? (OBDII diagnostic codes)

  1. #1
    Low Bitrate
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    67

    code wizards, help with some coding? (OBDII diagnostic codes)

    while downloading the OBDMPG Roadrunner plugin, i decided to look into the feasibility of polling and storing diagnostic trouble codes.

    the information is pretty much out there, and here it is:

    http://en.wikipedia.org/wiki/OBD-II_PIDs

    and

    http://obddiagnostics.com/obdinfo/pwmmode1.TXT

    i'm confused when it comes to transferring data streams into usable DTCs.... anybody know how to do this?

    the code for a P0123 code (that i came up with) would look like this:

    00 00 00 01 00 10 00 11
    \_/ \_/ \__/ \__/ \__/
    P 0 1 2 3

    unfurtunately, noone has any logs with data codes for me to try

    also, the business with these A,B,C,D thingys is confusing me, especially for Mode1 PID1....using the first set of data entries and its definition, 00 would indicate no MIL lamp on (0=false) and 0 codes (because the light's not on, ignoring pending codes for a moment)

    BTW, here's the data im working with : Recd 0A 41 6B 10 41 01 00 07 E1 01 7B (the 00 07 E1 01 is what we need)

    the next bit "07" is supposed to represent something, according to the page, B7 i guess would be "reserved: incomplete"? (going on the possibly erroneous assumption that "b" just represents (or is a placeholder for) the 2nd set of data values, aka B7=07, on the 2nd byte)

    even if that's the case, the next data byte is E1?

  2. #2
    SuperMod - OBDII GPS Logger forum
    Auto Apps:loading...

    Join Date
    Mar 2009
    Location
    Los Angeles
    Posts
    924
    The ELM327 datasheet from elm electronics has a complete walkthrough to do exactly what you want [the walkthrough starts on page 28, but I strongly suggest starting at the beginning - as far as datasheets go, that one's surprisingly palatable].

    A,B,C,D are the four bytes returned by the device as actual values. Note that a lot of OBDII mode 1 PIDs return less than four bytes [so you'd just populate A and B, for example]. Also, some mode 1 PIDs return more [according to the spec], although you're unlikely to actually need that.

    Once you've decoded the trouble code, you'll need to look up what it means. You may find this gentleman's work to also be useful.

    Gary (-;
    OBDGPSLogger, for logging OBDII and/or GPS data
    OBDSim, an OBDII/ELM327 software simulator
    mp3car forums: obdgpslogger, obdsim

  3. #3
    Newbie
    Join Date
    Oct 2008
    Posts
    30
    I believe a mode 01 PID 01 request just gives the MIL status and number of codes.

    To get the actual codes, you need to do a mode 03 request.

    The datasheet for the ELM327 at elm electronics has some good info.

  4. #4
    VENDOR - ScanTool Vitaliy's Avatar
    Join Date
    Dec 2006
    Location
    Phoenix, AZ
    Posts
    624
    i'm confused when it comes to transferring data streams into usable DTCs.... anybody know how to do this?

    the code for a P0123 code (that i came up with) would look like this:

    00 00 00 01 00 10 00 11
    \_/ \_/ \__/ \__/ \__/
    P 0 1 2 3
    That's correct. In hex, "P0123" would be 0x0123. The cool thing is that you can easily just read the codes out of the raw OBD stream, I do it sometimes to impress the uninitiated.

    also, the business with these A,B,C,D thingys is confusing me, especially for Mode1 PID1....using the first set of data entries and its definition, 00 would indicate no MIL lamp on (0=false) and 0 codes (because the light's not on, ignoring pending codes for a moment)
    You are absolutely correct, so which part is confusing?

    BTW, here's the data im working with : Recd 0A 41 6B 10 41 01 00 07 E1 01 7B (the 00 07 E1 01 is what we need)
    This is a response to 01 01, which as you correctly said above, means that the MIL is off and there are no stored DTCs.

    Here's a log generated from the ECU Sim (hint: there are two CAN ECUs responding, 10 and 18):

    Code:
    >0101
    18 DA F1 18 06 41 01 81 00 00 00
    18 DA F1 10 06 41 01 86 07 EF 80
    18 DA F1 18 06 41 01 81 00 00 00
    
    >03
    18 DA F1 10 10 0E 43 06 01 00 02 00
    18 DA F1 10 21 03 00 43 00 82 00 C1
    18 DA F1 10 22 00 00 00 00 00 00 00
    18 DA F1 18 04 43 01 01 01
    
    >
    Can you make sense of it?

    Vitaliy
    OBDLink MX: world's smallest, fastest, most advanced OBD/Bluetooth adapter with SW and MS CAN support. Read the review to learn more.
    Need to look up a diagnostic trouble code? Try the most up-to-date, free DTCsearch.com!

    You cannot send me a private message using this forum. Use my email instead: vitaliy[@]scantool.net.

  5. #5
    Newbie mgile's Avatar
    Join Date
    Aug 2007
    Location
    Houston, TX, USA, Earth, Sol, Milky Way
    Posts
    7

    Python DTC decode snippet

    Here's a quick 5 lines of Python that will decode a given DTC. Note however there may be more than one DTC per response, with each DTC being 2 bytes long.

    Code:
    _SYSTEM             = ['P', 'C', 'B', 'U',]
    _DTC_SYS_MASK       = 0xC0
    _DTC_DIGIT_0_1_MASK = 0x3F
    _DTC_DIGIT_2_3_MASK = 0xFF
    
    
    dtc = "%s%02d%02d" % (_SYSTEM[data[0] & _DTC_SYS_MASK], data[0] & _DTC_DIGIT_0_1_MASK, data[1] & _DTC_DIGIT_2_3_MASK)
    -Mike

  6. #6
    Low Bitrate
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    67
    lol, some pathetic update, managed to find the source code written in ? language available here:

    http://www.apeirokalia.com/elm323/clsELM323.cls.txt

    i'm teaching myself how to read it, so maybe it can be reverse engineered to accomplish what i need.

    right off the bat i found this

    If bMode = 4 Then
    send_to_OBD = False
    updatestatus "Won't send mode 4 by design."
    Exit Function

    so that's gotta go.

    im guessing this would have to be rewritten as:

    If bMode = 4 Then
    updatestatus "Clear codes Y/N"
    If Private Sub CommandA_Click() Then
    send_to_OBD = True
    If Private Sub CommandB_Click()Then
    send_to_OBD = False
    Exit Function

    and the code to pull codes would be:

    send_to_obd "03"

    to read the response would be:

    i dunno, but i think it's under "Private Sub parse_obd_response(ByVal r$)"

    and to make sense out of it would be (stealing mgile's code a bit)

    If dtc = P0123 Then
    updatestatus "Throttle Position Sensor/Switch A Circuit High Input"

    If dtc = P0125 Then
    Updatestatus "Insufficient Coolant Temperature For Closed Loop Fuel Control"

    If dtc = P0126 Then
    Updatestatus "Insufficient Coolant Temperature for Stable Operation"


    IF someone can help me write the code for this (and what i wrote above is useful code), i'll do the monkey work and produce a txt file with every code imaginable and its description..... actually it was done already by aonther forum member, but i can still format it correctly

    let me know if im on the right track with this and i'll keep trying....

  7. #7
    SuperMod - OBDII GPS Logger forum
    Auto Apps:loading...

    Join Date
    Mar 2009
    Location
    Los Angeles
    Posts
    924
    clsELM323 - VB6 class to interface with ELM323 chip (OBD interface)
    Ugh. VB. Also, I'm not convinced it counts as "reverse engineering" if you have the source.

    Polling and storing trouble codes really is easy. Perhaps if you could flick through the ELM327 [note! ELM327, not elm323 as the code you linked was] datasheet as I suggested and point out exactly which bits you need help understanding, that might be easier. Other forum users have also pointed you in the right direction.

    Knowing full well that this will probably only make everything more opaque to you, I feel obliged to offer up my C implementation of mgile's code:

    http://svn.icculus.org/obdgpslogger/....c?view=markup
    Scroll down to obderrconvert_r. Looking at it, mgile's is probably a little bit faster, but I feel mine's a lot clearer; either one will compile down to not more than a handful of asm instructions, so I don't think it matters either way.

    And off the top of my head, formatting AntiBNI's text files as you desire:

    Code:
    perl -pei.orig 's/^([^\[].*)$/   Updatestatus \"\1\"/;s/\[(.*)\]/If dtc == \"\1\" Then/' *.txt
    Gary (-;
    OBDGPSLogger, for logging OBDII and/or GPS data
    OBDSim, an OBDII/ELM327 software simulator
    mp3car forums: obdgpslogger, obdsim

  8. #8
    Low Bitrate
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    67
    chunksys: thanks for your response. i know that that code was written for the 323, but "the plugin uses the ELM327 VB6 class posted on these boards a while back by member Erorus to communicate to the vehicle." that's the source code used by the original OBDMPG plugin that i'm just attempting to add functionality to. Also, Mezz64 (obdmpg's creator) used that code to create his plugin, so if i wanted to write it in some other programming language, i'd have to start all over.


    lol, i guess, by reverse engineer i meant to repurpose already written code to do a different job...

    i couldn't possibly write this code, but i started this thread in the hopes that someone else out there wanted the ability to pull OBD codes via their carpc for free, and in a seamless manner (which is why i'm trying to piggyback the hell out of already written code)

    if it's really that easy, i don't know why someone hasn't just whipped it up real quick. my only guess is those same people who could whip it up real quick already have their hand in the cookie jar (so to speak). and i'm not going to knock their hustle....

    i dunno, just my rambling thoughts this morning..... i think when i get out of class and work tonite i'll get back to work on creating the skins... seems i'm more adept with the gimp paintbrush than computer code....

    i think my final goal is to have everything written and ready to go, then just basically beg Mezz64 to implement it into the next release....

  9. #9
    SuperMod - OBDII GPS Logger forum
    Auto Apps:loading...

    Join Date
    Mar 2009
    Location
    Los Angeles
    Posts
    924
    my only guess is those same people who could whip it up real quick already have their hand in the cookie jar (so to speak). and i'm not going to knock their hustle....
    Or, perhaps, because it's not an itch they wish to scratch, or because they don't use RR, or because any of a number of less financially selfish motives.

    Gary (-;
    OBDGPSLogger, for logging OBDII and/or GPS data
    OBDSim, an OBDII/ELM327 software simulator
    mp3car forums: obdgpslogger, obdsim

  10. #10
    Low Bitrate
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    67
    hey hey, in my defense, i said that i wasn't trying to knock their hustle, and also, it's source code, it could be implemented in other ways than thru a RR plugin....

    also, i thought that someone else besides me cared enough, maybe not tho

Page 1 of 4 1234 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 06-11-2006, 06:49 PM
  2. How do I use the Base plugin sources ?
    By guino in forum RR FAQ
    Replies: 1
    Last Post: 04-24-2006, 04:43 PM
  3. wireless OBDII CAN code reader
    By autosvs in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 67
    Last Post: 02-09-2006, 09:10 AM
  4. Read OBDII Source Code?
    By Zharvek in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 6
    Last Post: 05-19-2005, 08:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •