Unable to send ATZ command to ELM 327 after establishing connection with ELM327 in android
Asked Answered
F

1

6

I have written a code which is successfully able to find the paired OBD and establish the connection with ELM327 but when i am trying to send ATZ command the application gets crash.

Here's the code snippet, I may have done wrong

public HashMap<String, String> startOBDCommunicator(
            BluetoothSocket btSocketConnected, String paramClassName,
            String methodName) {

        HashMap<String, String> dataRetriever = new HashMap<String, String>();
        sendDataToOBD(btSocketConnected, "ATZ\r");
        dataRetriever.put("Reset", readDataFromOBD(btSocketConnected));

        sendDataToOBD(btSocketConnected, "ATS0\r");
        dataRetriever.put("Space Control", readDataFromOBD(btSocketConnected));

        sendDataToOBD(btSocketConnected, "ATE0\r");
        dataRetriever.put("Echo control", readDataFromOBD(btSocketConnected));

        sendDataToOBD(btSocketConnected, "ATL0\r");
        dataRetriever.put("Line feed", readDataFromOBD(btSocketConnected));

        sendDataToOBD(btSocketConnected, "ATAT0\r");
        dataRetriever
                .put("Adaptive Timing", readDataFromOBD(btSocketConnected));

        sendDataToOBD(btSocketConnected, "ATST10\r");
        dataRetriever.put("Time Out", readDataFromOBD(btSocketConnected));

        sendDataToOBD(btSocketConnected, "ATI\r");
        dataRetriever.put("Device Description",
                readDataFromOBD(btSocketConnected));

        sendDataToOBD(btSocketConnected, "ATDP\r");
        dataRetriever.put("Protocol Information1",
                readDataFromOBD(btSocketConnected));

        sendDataToOBD(btSocketConnected, "ATSPA0\r");
        dataRetriever
                .put("Auto Protocol",
                        readBytesFromOBD(btSocketConnected, paramClassName,
                                methodName));

        sendDataToOBD(btSocketConnected, "010C\r");

        dataRetriever
                .put("RPM param",
                        readBytesFromOBD(btSocketConnected, paramClassName,
                                methodName));

        sendDataToOBD(btSocketConnected, "010D\r");

        dataRetriever
                .put("Speed parameters",
                        readBytesFromOBD(btSocketConnected, paramClassName,
                                methodName));

        sendDataToOBD(btSocketConnected, "0104\r");

        dataRetriever
                .put("engine load value parameters",
                        readBytesFromOBD(btSocketConnected, paramClassName,
                                methodName));

        sendDataToOBD(btSocketConnected, "0105\r");

        dataRetriever
                .put("Engine coolant temperature parameters",
                        readBytesFromOBD(btSocketConnected, paramClassName,
                                methodName));

        sendDataToOBD(btSocketConnected, "012F\r");

        dataRetriever
                .put("Fuel Level Input",
                        readBytesFromOBD(btSocketConnected, paramClassName,
                                methodName));

        return dataRetriever;

    }

I m not sure where i have done mistakes , so i m sharing the flow of the entire code as two gist , https://gist.github.com/sankarganesh/6376031, this gist holds the Activity file and one more gist for Bluetooth Socket Listener https://gist.github.com/sankarganesh/6376039

Ferriferous answered 30/8, 2013 at 8:54 Comment(12)
Application crash -> can we have a stacktrace ?Nervous
@Skaard-Solo:Even though I have written the try catch block and try to recored the stack trace in a file which is under test folder in sd card,I was not able to capture the stack trace while testing with my car.Ferriferous
@Skaard-Solo:: I request you to go through the gist which I shared in the Question and convey me whether i have wrongly used the commandsFerriferous
My first view: The commands you are sending seems good to me. Don't have time to get a deep-down investigation, will do that later this day, I hope. Does it work with another OBD-II scanner, like Torque?Advert
@EricSmekens: yes , the OBD II Scanner works well with other Applications like Torque and elm327 android applicationFerriferous
@EricSmekens: My first doubt is , after sending ATZ commands,I am invoking the read funtion straight away without setting any time delay, is there any time delay required after sending the ATZ command, the next Question as i read in the document , ATZ commands clears(reset) data in the ELM 327 and send "OK" if it successful , is it true? , or ELM 327 does not replay any data for this command, really confused where's the problem?Ferriferous
I believe, if you have an ELM-327, it should put the commands in a buffer. Normally, the default time that the device waits for another command, is 200 ms. (You can set this to a lower time, you can find it in the ELM327 documentation. But this is for later, as you need a working connection first.) But maybe your writing part goes too fast, and sticks the commands together before they are sent. Just try it with a time of 1 second between the commands.Advert
The response of an ATZ command, in the documentation it says: That should cause the leds to flash again, and the identification string to be printed. If you see strange looking characters, then check your baud rate - you have likely set it incorrectly.Advert
@EricSmekens: will do this change and test it in vehicle and try to trigger out or capture any errorsFerriferous
@EricSmekens: I have tried to send the AT command the app is crashed , i have tried with two programs one just establish pairing with device and other sending the AT CommandsFerriferous
Can't you try to pair manually with the OS first, so you can assume that goes fine?Advert
yes I have test it today by both manually and through the application , it is able to pair and connect with odb, the problem occurs when we send the AT commandsFerriferous
S
0

The problem might be that after the prompt sign > no CR is sent from the ELM-device to the computer. If your serial input buffer is configured with termination by a CR, a timeout will happen.

Shawndashawnee answered 12/1, 2017 at 22:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.