gpt4 book ai didi

android - 在 android 中与 ELM327 建立连接后无法向 ELM327 发送 AT 命令

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:27:07 63 4
gpt4 key购买 nike

我已经编写了一段代码,它能够成功找到配对的 OBD 并与 ELM327 建立连接,但是当我尝试发送 ATZ 命令时,应用程序崩溃了。

这是代码 fragment ,我可能做错了

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 ,这个要点包含 Activity 文件和蓝牙套接字监听器的另一个要点 https://gist.github.com/sankarganesh/6376039

最佳答案

问题可能是在提示符 > 之后,ELM 设备没有向计算机发送 CR。如果您的串行输入缓冲区配置为由 CR 终止,则会发生超时。

关于android - 在 android 中与 ELM327 建立连接后无法向 ELM327 发送 AT 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18528792/

63 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com