togglebit / ArduinoDUE_OBD_FreeRunningCAN

These classes have been built with free-running CAN and OBDII data acq in mind
GNU Lesser General Public License v2.1
46 stars 20 forks source link

Other OBD2 Modes? (i.e. Mode 09 - Request vehicle information) #9

Closed rocketjosh closed 6 years ago

rocketjosh commented 6 years ago

Wondering how to get access to other modes? Specifically, looking for VIN, found at Mode 9: Request vehicle information.

According to Wikipedia, VIN is:

Mode 9 PID 02 Data bytes returned = 17-20 17-char VIN, ASCII-encoded and left-padded with null chars (0x00) if needed to.

Something like this in OBD2.h ?

enum OBD_PID
{

    ENGINE_LOAD  = 0x04,
    COOLANT_TEMP = 0x05,
    ENGINE_RPM   = 0x0C,
    SPEED        = 0x0D,
    ENGINE_IAT   = 0x0F,
    ENGINE_MAF   = 0x10,
    THROTTLE_POS = 0x11,
    FUEL_FLOW    = 0x5E,
    VIN          = 0x02
};

/**
 * 
 * This enum represents the size of the OBD2 signal in bits (8,16,32) per OBD2 protocol
 */
enum OBD_PID_SIZE
{
    _8BITS  = 1,
    _16BITS = 2,
    _32BITS = 4,
    _160BITS = 20
};

/**
 * 
 * This enum represents the desired mode of the signal requested from the OBD2 port
 */
enum OBD_MODE_REQ
{
    CURRENT  = 1,
    FREEZE   = 2,
    REQUEST  = 9

};

and this line in the sketch:

cOBDParameter OBD_VIN(        "VIN "          , " #"      ,  VIN         , _160BITS,   false ,  REQUEST,  1,    0,  &CANport0, false);
togglebit commented 6 years ago
  1. This code was really written with the intent of logging physical measurements from the vehicles black boxes...most of which are represented in 16 bits....so the above will not work (probably will run off in the weeds).
  2. CAN only supports 8 byte payloads. That PID is probably a multi-message payload meaning the PID will come back in two or more CAN messages, each of which will need to be parsed and merged to come up with the VIN.

Probably the place to do this is the next layer down in the CAN_Acquisition.cpp layer, here you can implement a receive handler for a specific message and do you parsing and merging there. See the CAN_Example_Gateway.ino for an example implementation.

On Mon, Nov 20, 2017 at 2:38 PM, Josh notifications@github.com wrote:

Wondering how to get access to other modes? Specifically, looking for VIN, found at Mode 9: Request vehicle information.

According to Wikipedia https://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_09, VIN is:

Mode 9 PID 02 Data bytes returned = 17-20 17-char VIN, ASCII-encoded and left-padded with null chars (0x00) if needed to.

Something like this in OBD2.h ?

enum OBD_PID {

ENGINE_LOAD = 0x04, COOLANT_TEMP = 0x05, ENGINE_RPM = 0x0C, SPEED = 0x0D, ENGINE_IAT = 0x0F, ENGINE_MAF = 0x10, THROTTLE_POS = 0x11, FUEL_FLOW = 0x5E, VIN = 0x02 }; /* This enum represents the size of the OBD2 signal in bits (8,16,32) per OBD2 protocol /enum OBD_PID_SIZE { _8BITS = 1, _16BITS = 2, _32BITS = 4, _160BITS = 20 }; /* This enum represents the desired mode of the signal requested from the OBD2 port /enum OBD_MODE_REQ { CURRENT = 1, FREEZE = 2, REQUEST = 9

};

and this line in the sketch:

cOBDParameter OBD_VIN( "VIN " , " #" , VIN , _160BITS, false , REQUEST, 1, 0, &CANport0, false);

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AD6Os-IEpy-aAGorjvaSODmrU5Zf9K5qks5s4dVHgaJpZM4QkyQJ .

rocketjosh commented 6 years ago

Cool, thanks! Just found this. Might be useful here:

https://community.carloop.io/t/how-to-request-vin/153

and repo with working code:

https://github.com/carloop/app-vin-reader