蓝牙聊天应用回复我发送的相同文本

Bluetooth Chat App answering back same text I sent

我正在使用一个应用程序通过蓝牙将数据发送到 elm327,我正在尝试 AT Z 命令,但我从 OBD2 返回的所有内容也是 AT Z,我的代码丢失了一些东西或者它应该回答像那 ?我希望 AT Z 到 return elm327 文本(使用 Playstore 应用程序测试,这就是我得到的)

  // runs during a connection with a remote device
  private class ReadWriteThread extends Thread {
    private final BluetoothSocket bluetoothSocket;
    private final InputStream inputStream;
    private final OutputStream outputStream;

    public ReadWriteThread(BluetoothSocket socket) {
        this.bluetoothSocket = socket;
        InputStream tmpIn = null;
        OutputStream tmpOut = null;

        try {
            tmpIn = socket.getInputStream();
            tmpOut = socket.getOutputStream();
        } catch (IOException e) {
        }

        inputStream = tmpIn;
        outputStream = tmpOut;
    }

    public void run() {
        byte[] buffer = new byte[1024];
        int bytes;

        // Keep listening to the InputStream
        while (true) {
            try {
                // Read from the InputStream
                bytes = inputStream.read(buffer);

                // Send the obtained bytes to the UI Activity
                handler.obtainMessage(MainActivity.MESSAGE_READ, bytes, -1,
                        buffer).sendToTarget();
            } catch (IOException e) {
                connectionLost();
                // Start the service over to restart listening mode
                ChatController.this.start();
                break;
            }
        }
    }

    // write to OutputStream
    public void write(byte[] buffer) {
        try {
            outputStream.write(buffer);
            handler.obtainMessage(MainActivity.MESSAGE_WRITE, -1, -1,
                    buffer).sendToTarget();
        } catch (IOException e) {
        }
    }

    public void cancel() {
        try {
            bluetoothSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

也许您阅读的不够多 – 确保将阅读的所有片段串联起来,直到收到实际提示 \r>

ELM327 通常以 回声模式 开始,它回声你给它的每一个命令,这可以解释你为什么要读回它。使用 ATE0 关闭此行为。

一般来说,https://www.sparkfun.com/datasheets/Widgets/ELM327_AT_Commands.pdf 解释了所有这些。