Page 3 of 3 FirstFirst 123
Results 21 to 22 of 22

Thread: Skinnable OBD software

  1. #21
    Constant Bitrate joeyoravec's Avatar
    Join Date
    Oct 2005
    Location
    Livonia, MI
    Posts
    205
    With OBD-II you're allowed only one outstanding request. Try using a mutex to prevent your timers or threads from accessing the vehicle simultaneously. Also if there's more than one ECU on the vehicle, you should wait for all responses before submitting a second request.

    Typically it's easier to keep your code single threaded. I've created several .NET examples for Mongoose. Here's a snippet of how I make an OBD-II request on J1850VPW:

    Code:
    uint ProtocolID = J1850VPW;
    
    // Clear any messages received before this request
    PassThruIoctl(ChannelID, CLEAR_RX_BUFFER, NULL, NULL);
    
    // Mode 01: Request vehicle data
    numMsgs = 1;
    Msg[0].ProtocolID = ProtocolID;
    Msg[0].TxFlags = 0;
    Msg[0].Data[0] = 0x68;	// Header
    Msg[0].Data[1] = 0x6A;
    Msg[0].Data[2] = 0xF1;
    Msg[0].Data[3] = 0x01;	// Mode 01: Request vehicle data
    Msg[0].Data[4] = PID;	//   PID: 8-bit
    Msg[0].DataSize = 5;
    PassThruWriteMsgs(ChannelID, Msg, ref numMsgs, 100);
    
    // Wait P2_J1850_MAX (100ms) for a response from the ECU
    timestamp = (uint) Environment.TickCount;
    while (((uint) Environment.TickCount - timestamp) < 100)
    {
    	numMsgs = 3;
    	PassThruReadMsgs(ChannelID, InMsg, ref numMsgs, 100);
    	for (i=0; i < numMsgs; i++)
    	{
    		if ((InMsg[i].RxStatus & (ISO15765_PADDING_ERROR | TX_DONE | RX_BREAK | START_OF_MESSAGE | TX_MSG_TYPE)) == 0)
    		{
    			if ((InMsg[i].Data[3] == (mode + 0x40)) && (InMsg[i].Data[4] == PID))
    			{
    				// Valid response. Restart the P2_MAX timeout.
    				timestamp = (uint) Environment.TickCount;
    
    				// Should improve this code to wait for other ECUs instead of returning immediately.
    				switch (size)
    				{
    				case 1:
    					value = (UInt32) InMsg[i].Data[5];
    					return PASS;
    				case 2:
    					value = (UInt32) (InMsg[i].Data[5] << 8) | InMsg[i].Data[6];
    					return PASS;
    				case 4:
    					value = ((UInt32) InMsg[i].Data[5] << 24) | ((UInt32) InMsg[i].Data[6] << 16) | ((UInt32) InMsg[i].Data[7] << 8) | (UInt32) InMsg[i].Data[8];
    					return PASS;
    				default:
    					// This code handles only 1, 2, and 4 byte responses.
    					value = 0;
    					return FAIL;
    				}
    			}
    		}
    	}
    }
    
    // We exited the loop for a timeout. Indicate failure.
    value = 0;
    return FAIL;

  2. #22
    Low Bitrate
    Join Date
    Jun 2007
    Posts
    76
    Anyway of changing this code for VB^?
    I have not used .net and this is the issue I am running into, I need a way to hold second mscomm command until receiving reply from first (and holding third command until receiving reply from second etc etc)



    Quote Originally Posted by joeyoravec View Post
    With OBD-II you're allowed only one outstanding request. Try using a mutex to prevent your timers or threads from accessing the vehicle simultaneously. Also if there's more than one ECU on the vehicle, you should wait for all responses before submitting a second request.

    Typically it's easier to keep your code single threaded. I've created several .NET examples for Mongoose. Here's a snippet of how I make an OBD-II request on J1850VPW:

    Code:
    uint ProtocolID = J1850VPW;
    
    // Clear any messages received before this request
    PassThruIoctl(ChannelID, CLEAR_RX_BUFFER, NULL, NULL);
    
    // Mode 01: Request vehicle data
    numMsgs = 1;
    Msg[0].ProtocolID = ProtocolID;
    Msg[0].TxFlags = 0;
    Msg[0].Data[0] = 0x68;	// Header
    Msg[0].Data[1] = 0x6A;
    Msg[0].Data[2] = 0xF1;
    Msg[0].Data[3] = 0x01;	// Mode 01: Request vehicle data
    Msg[0].Data[4] = PID;	//   PID: 8-bit
    Msg[0].DataSize = 5;
    PassThruWriteMsgs(ChannelID, Msg, ref numMsgs, 100);
    
    // Wait P2_J1850_MAX (100ms) for a response from the ECU
    timestamp = (uint) Environment.TickCount;
    while (((uint) Environment.TickCount - timestamp) < 100)
    {
    	numMsgs = 3;
    	PassThruReadMsgs(ChannelID, InMsg, ref numMsgs, 100);
    	for (i=0; i < numMsgs; i++)
    	{
    		if ((InMsg[i].RxStatus & (ISO15765_PADDING_ERROR | TX_DONE | RX_BREAK | START_OF_MESSAGE | TX_MSG_TYPE)) == 0)
    		{
    			if ((InMsg[i].Data[3] == (mode + 0x40)) && (InMsg[i].Data[4] == PID))
    			{
    				// Valid response. Restart the P2_MAX timeout.
    				timestamp = (uint) Environment.TickCount;
    
    				// Should improve this code to wait for other ECUs instead of returning immediately.
    				switch (size)
    				{
    				case 1:
    					value = (UInt32) InMsg[i].Data[5];
    					return PASS;
    				case 2:
    					value = (UInt32) (InMsg[i].Data[5] << 8) | InMsg[i].Data[6];
    					return PASS;
    				case 4:
    					value = ((UInt32) InMsg[i].Data[5] << 24) | ((UInt32) InMsg[i].Data[6] << 16) | ((UInt32) InMsg[i].Data[7] << 8) | (UInt32) InMsg[i].Data[8];
    					return PASS;
    				default:
    					// This code handles only 1, 2, and 4 byte responses.
    					value = 0;
    					return FAIL;
    				}
    			}
    		}
    	}
    }
    
    // We exited the loop for a timeout. Indicate failure.
    value = 0;
    return FAIL;

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Confused about OBD II
    By tom2112 in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 30
    Last Post: 10-19-2007, 01:06 AM
  2. Skinnable OBD II Software
    By antimatter in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 374
    Last Post: 08-11-2006, 08:55 PM
  3. Looking for Non ELM software for OBD II
    By Refael Azi in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 13
    Last Post: 07-19-2006, 10:32 AM
  4. my OBD II Software
    By kocke in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 8
    Last Post: 04-06-2005, 02:53 PM
  5. obd II datalogger building and software
    By backpack09 in forum Off Topic
    Replies: 2
    Last Post: 08-22-2002, 08:03 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
  •