开发者

Sending command to a device over Bluetooth by writing to DataOutputStream

开发者 https://www.devze.com 2023-02-17 09:25 出处:网络
I\'m trying to send a command to a device over my Bluetooth RFCOMM socket Connection. -Connection is successful.

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

精彩评论

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