通过写入 DataOutputStream 通过蓝牙向设备发送命令
我正在尝试通过蓝牙 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);
}
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 DataInputStream 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现发送命令时必须有正确的转义序列。纠正转义序列后,它起作用了。
I figured it out that i have to have proper Escape Sequence while sending the command. It worked after correcting the Escape Sequence.