Android establishing bluetooth connection to paired device using thread not working in some devices

StackOverflow https://stackoverflow.com/questions/19482131

سؤال

I am developing android app for OBD. I have written bluetooth connection with OBD device code in thread. This thread is working for some devices but the device whose processer is very good then it has problem.

Let me know how I can manage for those devices?

Thank you in advance.

هل كانت مفيدة؟

المحلول

So if I get you right, your code gets executed too fast? If you send 1 command and then nothing, it works right?

Only problem I could imagine, is that you are sending your commands too quickly. You will have to make a smart way of sending commands to the OBD-device, or just let the thread sleep after sending a command. The base problem is that your device can send multiple commands, while the obd-ii device didn't handle it first command and then it reads in multiple commands at a time, which makes it confusing for him.

Update:

When you send a command, the OBD protocols sends the command and a ECU reponds on the command, and the answer gets responded to you. During that time, the OBD-II device does not follow any other instructions. After the respsonse, it looks into the buffer and processes that command. Look at it as a single thread that can only hanlde 1 command at a time.

Standard, the time the OBD-ii device waits, is 200 ms. Then it sends a response back to you. You can alter this by setting the timeout lower. (Look into AT-commands for ELM-327), or by adding a 1 after your command, so the OBD-II device knows it should respond back when he found 1 possible answer.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top