The MP3car.com Store  

Welcome to the MP3Car.com forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Registering will also remove advertisements. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   MP3Car.com > Mp3Car Technical > Engine Management, OBD-II, Engine Diagnostics, etc.

Reply
 
Thread Tools Display Modes
Old 09-10-2004, 02:26 AM   #1
See me in my wet t-shirt.
 
stevieg's Avatar
 
Join Date: Aug 2003
Location: Warwickshire, UK
Vehicle: Ford Focus MP3
Posts: 1,909
My Photos: (0)
OBDII / Elm MPG meter for mediacar. Almost working but not quite!

I've been working on a instant/average MPG meter to fit into MediaCar.

I've got it almost working, I'm just having trouble on the last 1%

The application appears to work out the MPG (UK gallon) correctly. It also works in 'test' mode where it reads from a logfile.

I used jelm (http://www.sophonix.com/downloads/jelmemulator.asp) with some modifications to send back the pids I needs to test it while developing it.

But when I get it in the car it doesn't work very fast (I had to turn echo on, linefeeds on even though it worked without in the emulator) and crashes eventually with dive by zero.

I haven't found any VB code as a decent starting point really for the elm interface and now I seem to be going round in circles, developing it any further involves sitting in the car on the car pc with a keyboard so I can get live readings..

Does anyone have any dcenet VB source code (VB6 or dot net) they are willing to share or can tell me how to fix the code I have got?

I've attached the source code of what I have done so far. If anyone wants to use any of it by the way it is BSD license so basically you can do what you want with it.
Attached Files
File Type: zip CarData.zip (95.6 KB, 1532 views)
__________________
Ford Focus MP3 : www.stevieg.org/carpc
Car PC Status: COMPLETE
stevieg is offline   Reply With Quote
Sponsored Links
Old 09-10-2004, 08:28 AM   #2
Maximum Bitrate
 
owenjh's Avatar
 
Join Date: Nov 2003
Location: NC
Posts: 604
My Photos: (0)
I have an idea, if your using a com port use comfoolery and the port redirector and connect to it from your home PC if you have WiFi. That way you will have the luxury of your home PC with your live data.
To resolve the divide by zero, try putting an if statement in - its probably because your speed is zero.
How are you calculating your miles per gallon? When you finish it you should have an option for RPM's and have the user input how much gas there car uses at certain RPM's, or even better log the fuel (trim?) levels if its possible.
Not that good at OBD-II yet, so it might sound like im talking out of my arse, but I plan on getting my interface soon.

Im guessing I should buy one with the Elm interface since you have started some VB code :-P


Looked at your code, won't work on this computer because jet isn't installed I see how your calculating now.
__________________
CarComputer Status: New Car & Broken (Motherboard Fried)
Owen JH | My Linux Blog | The Tech Fellows

Last edited by owenjh : 09-10-2004 at 08:58 AM.
owenjh is offline   Reply With Quote
Old 09-10-2004, 08:37 AM   #3
Raw Wave
 
god_of_cpu's Avatar
 
Join Date: Jan 2004
Location: SilverSpring Maryland
Vehicle: 2003/Infiniti/G35 Sport Coupe
Posts: 2,951
My Photos: (0)
I wrote an OBD II plugin dll for the ELM that does all the hard work of talking to the COM port. You just tell it what PIDs you want to recieve, then you tell it to start polling. It will use overlapped I/O to contiously read in the values until you tell it to stop or want to change the PIDs its reading. Whenever you want a value for any of the PIDs you just call a function with the PID and it returns its last read in value. I'll try and post the plugin this weekend and how to use it.
__________________
StreetDeck.com Developer (I am Chuck)
Get StreetDeck at http://www.streetdeck.com
god_of_cpu is offline   Reply With Quote
Old 09-10-2004, 08:49 AM   #4
Maximum Bitrate
 
owenjh's Avatar
 
Join Date: Nov 2003
Location: NC
Posts: 604
My Photos: (0)
Quote: Originally Posted by god_of_cpu
I wrote an OBD II plugin dll for the ELM that does all the hard work of talking to the COM port. You just tell it what PIDs you want to recieve, then you tell it to start polling. It will use overlapped I/O to contiously read in the values until you tell it to stop or want to change the PIDs its reading. Whenever you want a value for any of the PIDs you just call a function with the PID and it returns its last read in value. I'll try and post the plugin this weekend and how to use it.

Which OBD-II reader are you using, so that I know the one I get will work with your pluggin? I will buy it A.S.A.P so I can get working with OBD-II and make some nifty little programs.


Function Die(UserMessage As String, DebugMessage As String)
Any reason why this ends the program when it can't communicate?
__________________
CarComputer Status: New Car & Broken (Motherboard Fried)
Owen JH | My Linux Blog | The Tech Fellows

Last edited by owenjh : 09-10-2004 at 08:51 AM.
owenjh is offline   Reply With Quote
Old 09-10-2004, 08:50 AM   #5
Raw Wave
 
god_of_cpu's Avatar
 
Join Date: Jan 2004
Location: SilverSpring Maryland
Vehicle: 2003/Infiniti/G35 Sport Coupe
Posts: 2,951
My Photos: (0)
Also, the ELM interface won't give you a better response then 2.5 updates a second regardless of how good your code is and what you turn off.
__________________
StreetDeck.com Developer (I am Chuck)
Get StreetDeck at http://www.streetdeck.com
god_of_cpu is offline   Reply With Quote
Old 09-10-2004, 08:54 AM   #6
Raw Wave
 
god_of_cpu's Avatar
 
Join Date: Jan 2004
Location: SilverSpring Maryland
Vehicle: 2003/Infiniti/G35 Sport Coupe
Posts: 2,951
My Photos: (0)
Quote: Originally Posted by owenjh
Which OBD-II reader are you using, so that I know the one I get will work with your pluggin? I will buy it A.S.A.P so I can get working with OBD-II and make some nifty little programs.

I'm currently using the scantool.net one, it should work with anything that uses the ELM chip though. However, the plugin interface is actually written so that the calling application writes to this single interface and multiple plugins can then be used. I've only written the one for the ELM interface, but ideally more plugins could be written for the different interfaces and the calling applications wouldn't have to change.

The ELM is proving too slow to be really usable for me though, I plan on eventually buying a CAN based one and writing the plugin for it.
__________________
StreetDeck.com Developer (I am Chuck)
Get StreetDeck at http://www.streetdeck.com
god_of_cpu is offline   Reply With Quote
Old 09-10-2004, 09:00 AM   #7
Maximum Bitrate
 
owenjh's Avatar
 
Join Date: Nov 2003
Location: NC
Posts: 604
My Photos: (0)
Quote: Originally Posted by god_of_cpu
I'm currently using the scantool.net one, it should work with anything that uses the ELM chip though. However, the plugin interface is actually written so that the calling application writes to this single interface and multiple plugins can then be used. I've only written the one for the ELM interface, but ideally more plugins could be written for the different interfaces and the calling applications wouldn't have to change.

The ELM is proving too slow to be really usable for me though, I plan on eventually buying a CAN based one and writing the plugin for it.

I do not believe I am advanced enough to write a plugin, although I may be able to figure it out if I could look at your source code. I might try to buy one with a different interface and write a module for it. It would be nice to have an application that can communicate to all types of OBD readers thru these plugins. I bet media player / mediacar would like that.

How about the one from obddiagnostics.com
I believe I might be able to write a plugin for that.
__________________
CarComputer Status: New Car & Broken (Motherboard Fried)
Owen JH | My Linux Blog | The Tech Fellows
owenjh is offline   Reply With Quote
Old 09-10-2004, 09:25 AM   #8
Raw Wave
 
god_of_cpu's Avatar
 
Join Date: Jan 2004
Location: SilverSpring Maryland
Vehicle: 2003/Infiniti/G35 Sport Coupe
Posts: 2,951
My Photos: (0)
This is the exposed interface of the dll, most of these should be semi-self explainatory, but they are explained completely in the code files I'll post later.

This code is in C++, you will have to covert the prototypes to VB.



Code:
INIT_DLL_FUNCTION(LPVOID, WINAPI, API_OBDII_Create,(HWND hWnd, IUnknown* lpUknown)); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_Release,(LPVOID lpUser)); INIT_DLL_FUNCTION_NAMED(VOID, WINAPI, GetModuleName,(CHAR* szName, INT iMaxLen), API_OBDII_GetModuleName) INIT_DLL_FUNCTION_NAMED(VOID, WINAPI, GetVersion,(CHAR* szVersion, INT iMaxLen), API_OBDII_GetVersion) INIT_DLL_FUNCTION_NAMED(VOID, WINAPI, GetGUID,(GUID* pguid), API_OBDII_GetGUID); INIT_DLL_FUNCTION_NAMED(INT, WINAPI, RequestedAPI,(INT iMaxAPI), API_OBDII_RequestedAPI); INIT_DLL_FUNCTION_NAMED(VOID, WINAPI, GetModuleComment,(CHAR* szComment, INT iMaxLen), API_OBDII_GetModuleComment); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_SetMode, (LPVOID lpUser, enumOBDModes eOBDMode)); INIT_DLL_FUNCTION(FLOAT, WINAPI, API_OBDII_Mode1_GetRefreshRate, (LPVOID lpUser)); INIT_DLL_FUNCTION(VOID, WINAPI, API_OBDII_Mode1_ResetData, (LPVOID lpUser)); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_Mode1_IsPIDSupported, (LPVOID lpUser, enumOBDMode1PIDs eOBDPID)); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_Mode1_AddOBDPID, (LPVOID lpUser, enumOBDMode1PIDs eOBDPID)); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_Mode1_RemoveAllOBDPIDs, (LPVOID lpUser)); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_Mode1_Start, (LPVOID lpUser)); INIT_DLL_FUNCTION(VOID, WINAPI, API_OBDII_Mode1_GetPacket, (LPVOID lpUser, enumOBDMode1PIDs eOBDPID, API_OBDII_MSGPACKET* lpMsgPacket)); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_Mode1_Stop, (LPVOID lpUser)); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_Mode3_IsMILLightOn, (LPVOID lpUser)); INIT_DLL_FUNCTION(INT, WINAPI, API_OBDII_Mode3_GetNumTroubleCodes, (LPVOID lpUser)); INIT_DLL_FUNCTION(VOID, WINAPI, API_OBDII_Mode3_GetTroubleCodes, (LPVOID lpUser, DWORD* lpTroubleCodes, INT iMaxNumTrobleCodes)); INIT_DLL_FUNCTION(BOOL, WINAPI, API_OBDII_Mode3_ClearTroubleCodes, (LPVOID lpUser)); //*** OPTIONAL FUNCTIONS *** INIT_DLL_FUNCTION(INT, WINAPI, API_OBDII_ConfigurationDialog, (LPVOID lpUser));

To read real time data after calling create, you would set the mode to read current data, then reset the PIDs to read and add only the PIDs you now want, then just start the plugin and it begins polling the COM port in a seperate thread, returning from the call immediatly.

i.e.
Code:
if (!m_lpAD->m_vdb.GetOBDIIPlugin()->SetMode(eOBDModeCurrentData)) TV_THROWMSGBOX("Could not set the OBD II mode to read current data!"); if (!m_lpAD->m_vdb.GetOBDIIPlugin()->Mode1_RemoveAllOBDPIDs()) TV_THROWMSGBOX("Could not remove PIDs from the OBD II module"); //Just monitor speed for now if (!m_lpAD->m_vdb.GetOBDIIPlugin()->Mode1_AddOBDPID(eOBDPIDVehicleSpeed)) TV_THROWMSGBOX("Could not add a PID to monitor the OBD II plug-in for!"); if (!m_lpAD->m_vdb.GetOBDIIPlugin()->Mode1_Start()) { TV_THROWMSGBOX("Could not start the OBD II plug-in!"); }

In a timer in your program you would call Mode1_GetPacket with the PID you want and it would return the data in the following structure:

Code:
//OBD message packet recieved from the vehicle typedef struct API_OBDII_MSGPACKET { DWORD m_dwTimeRecieved; BYTE m_iNumDataBytes; BYTE m_Header[API_OBDII_NUMHEADERBYTES]; BYTE m_Data[API_OBDII_NUMDATABYTES]; };

__________________
StreetDeck.com Developer (I am Chuck)
Get StreetDeck at http://www.streetdeck.com
god_of_cpu is offline   Reply With Quote
Old 09-10-2004, 11:12 AM   #9
See me in my wet t-shirt.
 
stevieg's Avatar
 
Join Date: Aug 2003
Location: Warwickshire, UK
Vehicle: Ford Focus MP3
Posts: 1,909
My Photos: (0)
Thanks, I can't wait for your DLL. 2.5 times a second will be OK for what I want to do.
__________________
Ford Focus MP3 : www.stevieg.org/carpc
Car PC Status: COMPLETE
stevieg is offline   Reply With Quote
Old 09-10-2004, 11:19 AM   #10
See me in my wet t-shirt.
 
stevieg's Avatar
 
Join Date: Aug 2003
Location: Warwickshire, UK
Vehicle: Ford Focus MP3
Posts: 1,909
My Photos: (0)
Quote: Originally Posted by owenjh
I have an idea, if your using a com port use comfoolery and the port redirector and connect to it from your home PC if you have WiFi.

Well to be honest I have been sitting in my house at my laptop wi-fi-ing into the car and using it from their. Simialr thing really, but a pain to have your car running with no-one in it.

Quote: Originally Posted by owenjh
To resolve the divide by zero, try putting an if statement in - its probably because your speed is zero.

Nope as if speed is zero it doesn't try to calculate but the thing is it worked fine in the emulator.
Quote: Originally Posted by owenjh
How are you calculating your miles per gallon? When you finish it you should have an option for RPM's and have the user input how much gas there car uses at certain RPM's, or even better log the fuel (trim?) levels if its possible.

the code is in the program. It gives in instant MPG for any given moment. It would be possible to log RPM along with the MPG data, and the debug mode already logs fuel trim to the DB, I just want something working first!

Quote: Originally Posted by owenjh
Function Die(UserMessage As String, DebugMessage As String)
Any reason why this ends the program when it can't communicate?

it should always be communnicating and although there is a rally crap routine to reset it and try again if it loses communication, if it still has trouble I wanted it to just die and log the error. Once I get it working I need to get it to sort itself out on resume from standby, and find the PID for my ford's fuel level as the whole point of it to me is so I can see almost exactly how many miles are left in the tank, as well as when I'm being economical.
__________________
Ford Focus MP3 : www.stevieg.org/carpc
Car PC Status: COMPLETE
stevieg is offline   Reply With Quote
Sponsored Links
Old 09-11-2004, 05:00 PM   #11
See me in my wet t-shirt.
 
stevieg's Avatar
 
Join Date: Aug 2003
Location: Warwickshire, UK
Vehicle: Ford Focus MP3
Posts: 1,909
My Photos: (0)
god_of_cpu - any news on the DLL - would love to try it out sometime! not wanting to bug you about it or anything
__________________
Ford Focus MP3 : www.stevieg.org/carpc
Car PC Status: COMPLETE
stevieg is offline   Reply With Quote
Old 09-11-2004, 05:41 PM   #12
Raw Wave
 
god_of_cpu's Avatar
 
Join Date: Jan 2004
Location: SilverSpring Maryland
Vehicle: 2003/Infiniti/G35 Sport Coupe
Posts: 2,951
My Photos: (0)
It's going to be posted to my website with some documentation etc. I still have some other things to do for the website though which I'm working on currently. It will be up there before sunday night. I'll try and post a C++ header file with the DLLs exposed functions and structures tonight. Before you can use the dll, you will need to convert this header file to VB's various declare statements just like you do to call functions from the Win32 API so it can be used in VB.
__________________
StreetDeck.com Developer (I am Chuck)
Get StreetDeck at http://www.streetdeck.com
god_of_cpu is offline   Reply With Quote
Old 09-11-2004, 09:59 PM   #13
Raw Wave
 
god_of_cpu's Avatar
 
Join Date: Jan 2004
Location: SilverSpring Maryland
Vehicle: 2003/Infiniti/G35 Sport Coupe
Posts: 2,951
My Photos: (0)
It was easy enought for me to just convert all the C code to VB declarations.

Heres the VB declarations for all the functions.

I don't have VB and havent used it in years so I don't know if everythings syntactically correct, correct and repost if necessary.

I'll be posting the types and enumerations needed soon.
Attached Files
File Type: zip OBDIIPlugin.zip (2.8 KB, 808 views)
__________________
StreetDeck.com Developer (I am Chuck)
Get StreetDeck at http://www.streetdeck.com
god_of_cpu is offline   Reply With Quote
Old 09-11-2004, 11:22 PM   #14
Low Bitrate
 
Join Date: Feb 2004
Posts: 60
My Photos: (0)
stevieg- i have a working vb6 code that i wrote for the elm interface, not sure if you saw my post awhile back. It can send out the requested PIDs and receive them by clicking on what item you want (RPM, Speed...) The code has a few bugs in it that i never finished working out, but for the most part works as it is suppose to. Only thing i never finished was looping the codes so they are all displayed realtime, right now you have to click on the option and that value is displayed. I have to dig up the code for it, i have so many different versions i was working with at the time i dont know what one was the most complete. If you want to work together on this let me know, ill be happy to get something together.


infinkc is offline   Reply With Quote
Old 09-12-2004, 11:43 AM   #15
See me in my wet t-shirt.
 
stevieg's Avatar
 
Join Date: Aug 2003
Location: Warwickshire, UK
Vehicle: Ford Focus MP3
Posts: 1,909
My Photos: (0)
Thanks both of you. infinkc, I'll have a go with god_of_cpu's plug in first, and see if the DLL does what we are both looking to do.
__________________
Ford Focus MP3 : www.stevieg.org/carpc
Car PC Status: COMPLETE
stevieg is offline   Reply With Quote
Sponsored Links
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone have workign VB code for elm scan? infinkc Engine Management, OBD-II, Engine Diagnostics, etc. 12 06-11-2005 06:16 AM


All times are GMT -5. The time now is 09:11 AM.


Sponsored Links
The MP3car.com Store

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0
Copyright © 1999 - 2008 Mp3Car.com Inc.
Ad Management by RedTyger
Message Board Statistics