开发者

Sending command to a device over Bluetooth by writing to DataOutputStream

I'm trying to send a command to a device over my Bluetooth RFCOMM socket Connection. -Connection is successful. -As soon as it gets connected i tried reading the DataInputStrea开发者_开发问答m and i continuously get data from the device. -My problem is i'm trying to send a Serial command to the device and on doing that my device doesn't respond to the command.

Is there something wrong in the way i'm sending commands ? Here is the code i used ...

 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);
    }


I figured it out that i have to have proper Escape Sequence while sending the command. It worked after correcting the Escape Sequence.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜