【问题标题】:Sending command to a device over Bluetooth by writing to DataOutputStream通过写入 DataOutputStream 通过蓝牙向设备发送命令
【发布时间】:2011-03-18 05:25:43
【问题描述】:

我正在尝试通过我的蓝牙 RFCOMM 套接字连接向设备发送命令。 - 连接成功。 - 连接后,我尝试读取 DataInputStream 并不断从设备获取数据。 - 我的问题是我正在尝试向设备发送串行命令,但这样做我的设备没有响应命令。

我发送命令的方式有问题吗?这是我使用的代码...

 DataOutputStream Dos = new DataOutputStream(BTsocket.getOutputStream());
 ...........

String message = "SET TIME XXX";
    byte[] msgBuffer = message.getBytes();
    try {

        Dos.writeInt(msgBuffer.length);
        Dos.write(msgBuffer); 
        Dos.flush();

   } 
   catch (IOException e) {
        Log.e(TAG, "Exception during write.", e);
    }

【问题讨论】:

  • 在 DataInputStream 中设备不断地发送数据。因此,如果我通过 DataOutputStream 发送命令,我如何知道命令的返回状态。
  • 能否提供您的代码。

标签: java android bluetooth serial-port dataoutputstream


【解决方案1】:

我发现在发送命令时我必须有正确的转义序列。它在更正 Escape Sequence 后起作用。

【讨论】:

    猜你喜欢
    • 2014-07-12
    • 2016-05-08
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    相关资源
    最近更新 更多