Send multiple OBD commands together and get response simultaneously
Asked Answered
W

2

11

I'm working on application which connects OBD2 adapter and getting the real time data like speed,rpm,throttle position etc..When I read one command at a time, it works fine like by sending command "010C\r", I get current RPM.

I think that sending multiple commands in one request is not possible.But in other applications like EngineLink HD ,Dashcommand, we found that multiple components are updated at a time like if we are driving the car and check the RPM,Sped and Throttle then they are updating at every 1 second. It looks like real time data.

I'm surprised that how is it possible ?

We have added code like if user wants to show 3 components, then for every component, one thread is generated and it handles request and response of that command. So in this case , 3 threads are generated and we get response but it takes too much time like if we are watching on Speed out of 3 PIDs then speed is updated after 3-4 seconds delay.

We also need to lock the code where it sends the request and get response bcoz OBD2 adapter handles one request and response at a time.

And if we don't lock the code then we get unpredicted results which might be due to common shared stream used by socket communication between the application and obd2 adapter.

But now I want to read multiple commands at a time. I mean at a point of time, I want to know speed,RPM and throttle position etc..So I want to send above commands in one request and get a response at a time.

How is it possible ? Someone can guide me.

Waadt answered 24/1, 2014 at 13:37 Comment(2)
Hello, i am also working on OBD. I am newbie to OBD. Can you please share your knowledge on OBD? How to connect to OBD device using wifi? How to communicate with OBD to execute its commands? Please help me to come out of this?Flexure
Hello, Would be really great if you can help me out on how to create an application to read the OBD data using elm327 wifi module? Would be really grateful if you can reach me out @ [email protected]. Waiting for your response. Thanks!Eyeglasses
L
5

First of all, I don't think you need 3 threads for this. As you said, OBD-II can only handle 1 command at a time, so you can do with 1 thread, that knows which requests it has to make every second.

Simply said, you cannot read multiple commands at a single time. As you've said, you experience some delay. The OBD-II default settings are responsible for this. The default waiting time, (as far as I can recognize) 200 ms. So you can only send 5 commands each second. This is somewhat slow, and some applications manage to get 20 request each second.

You can do this by sending an extra number (number x) at the end of your command. The OBD-II device will wait for x responses from devices in the car. So when you send '010D1', it will wait till 1 answer comes in, and it will directly send it back to you. Then it's easibly possible to handle a command in 50ms or maybe even less.

So that's how that application looks like it requests data 'at the same time'. They can also use some trick to wait till all data is collected, and then display it.

I hope I answered all your questions, otherwise ask some more.

EDIT:

Also for the succesfull commands, this standard time is taken. This is because some commands can have 2 sources which report the same data. For example, the speedometer, and a gps module can both measure the speed. If both are connected to the OBD-II bus, then you will get 2 answers.

With '010D', it will wait 200ms and then report all answers. With '010D1', it will send back the first answer directly when it has 1 answer.

Lipman answered 25/1, 2014 at 21:47 Comment(7)
Thanks Eric for the reply..I try it from my side and let u knowWaadt
My issue has been fixed as it was thread issue in one of our core function, thread is slept for 1 seconds to identify disconnection to server and it creates issue..But Now,my code is working fine. Thanks for suggestion ! We came to know one new way of getting OBD data at faster rateWaadt
Is the default waiting time used up on every command, even the successful ones? My understanding is that this timeout applies only when the OBD is unable to get a response to the PID (such as if it is not supported).Wilfredowilfrid
I was just wondering why the BMW sends 2 sets of responses to many PID commands (incl a 16 byte response to 0100 instead of the expected 8 bytes)!Wilfredowilfrid
I am trying to do the same, and when I send 010D2, it only receives one reply....Electrocautery
This is probably because your car only has 1 sensor for speed. Then 010D1 will be faster than 010D2.Lipman
@Wilfredowilfrid Chances are you have an automatic transmission device and the 2nd answer comes from your automatic transmission ECU.Merce
N
5

The ELM327 datasheet gives the following information on page 45:

Multiple PID Requests The SAE J1979 (ISO 15031-5) standard allows requesting multiple PIDs with one message, but only if you connect to the vehicle with CAN (ISO 15765-4). Up to six parameters may be requested at once, and the reply is one message that contains all of the responses. For example, let us say that you need to know engine load (04), engine coolant temperature (05), manifold pressure (0B), and engine rpm (0C) on a regular basis. You could send four separate requests for them (01 04, then 01 05, then 01 0B, etc.) or you could put them all into one message like this:

01 04 05 0B 0C

to which, a typical reply might be:

00A
0: 41 04 3F 05 44 0B
1: 21 0C 17 B8 00 00 00
Narcisanarcissism answered 10/2, 2015 at 16:31 Comment(2)
Are those PIDS requested from the ECU's in parallell or in series? A way to test this, is to request 0D for like 10 times, and then it should be all the same value if ELM327 chip allows this.Lipman
They're processed in serial. OBD2 is a serial interface, no way to change that behavior.Merce

© 2022 - 2024 — McMap. All rights reserved.