在Android中与ELM327建立连接后无法将ATZ命令发送到ELM 327 [英] Unable to send ATZ command to ELM 327 after establishing connection with ELM327 in android
问题描述
我编写了一个代码,该代码能够成功找到配对的OBD并建立与ELM327的连接,但是当我尝试发送ATZ命令时,应用程序崩溃了.
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;
}
我不确定我在哪里做错了,所以我以两个要点( https://)的身份共享了整个代码流gist.github.com/sankarganesh/6376031 ,此要点将保存活动文件,并为蓝牙套接字侦听器提供另一个要点 https://gist.github.com/sankarganesh/6376039
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
推荐答案
问题可能是提示符号>
之后没有任何CR从ELM设备发送到计算机.如果您的串行输入缓冲区配置有CR终止,则会发生超时.
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.
这篇关于在Android中与ELM327建立连接后无法将ATZ命令发送到ELM 327的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!