从 Android 发送的 PC 上的 RFCOMM 接收字符串
我试图从手机(Android 2.3.3)获取一个字符串,发送到PC(Windows 7),我使用RFCOMM基本连接,类似这样的东西
BluetoothSocket tmp = null;
try {
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);
} catch (Exception e) {
Log.i("bluetooth", e.getMessage());
}
mmSocket = tmp;
try {
mmSocket.connect();
,对于输出字符串,类似这样的东西
String message = "TEST";
try {
mmOutStream.write(mensaje.getBytes());
} catch (IOException e) {
Log.e("bluetooth", "ERROR: "+e);
}
它基本上可以工作(尝试使用超级终端)。我想做的只是在我的 PC 上接收字符串“TEST”,但使用 java 应用程序,稍后将控制微控制器。
谢谢。
Im trying to get one string from phone (Android 2.3.3), sent to PC (Windows 7), im using RFCOMM basic connection, something like this
BluetoothSocket tmp = null;
try {
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);
} catch (Exception e) {
Log.i("bluetooth", e.getMessage());
}
mmSocket = tmp;
try {
mmSocket.connect();
and for output strings, something like this
String message = "TEST";
try {
mmOutStream.write(mensaje.getBytes());
} catch (IOException e) {
Log.e("bluetooth", "ERROR: "+e);
}
And it basically works (Tried using HyperTerminal). What I would like to do is simply receive the string "TEST" on my PC, but with an java application, that later will control an microcontroller.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的问题是如何开始使用 Java 蓝牙应用程序:我在 BlueCove 方面取得了巨大成功 对于 Windows。
If your question is how to start with a Java Bluetooth application: I've had great success with BlueCove for Windows.