我正在尝试通过蓝牙从我的android发送文本,以显示在arduino的串行监视器中。我有一个按钮,当我点击它时应该发送文本,但我不断收到此错误。有谁知道问题是什么?
01-12 01:53:10.849: E/BluetoothSocket(25004): java.io.IOException: Transport endpoint is not connected
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.bluetooth.BluetoothSocket.writeNative(Native Method)
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.bluetooth.BluetoothSocket.write(BluetoothSocket.java:372)
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.bluetooth.BluetoothOutputStream.write(BluetoothOutputStream.java:89)
01-12 01:53:10.849: E/BluetoothSocket(25004): at java.io.OutputStream.write(OutputStream.java:80)
01-12 01:53:10.849: E/BluetoothSocket(25004): at com.example.BluetoothExample.Send.stream(Send.java:120)
01-12 01:53:10.849: E/BluetoothSocket(25004): at com.example.BluetoothExample.Send$2.onClick(Send.java:57)
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.view.View.performClick(View.java:2579)
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.view.View$PerformClick.run(View.java:9246)
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.os.Handler.handleCallback(Handler.java:587)
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.os.Handler.dispatchMessage(Handler.java:92)
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.os.Looper.loop(Looper.java:130)
01-12 01:53:10.849: E/BluetoothSocket(25004): at android.app.ActivityThread.main(ActivityThread.java:3735)
01-12 01:53:10.849: E/BluetoothSocket(25004): at java.lang.reflect.Method.invokeNative(Native Method)
01-12 01:53:10.849: E/BluetoothSocket(25004): at java.lang.reflect.Method.invoke(Method.java:507)
01-12 01:53:10.849: E/BluetoothSocket(25004): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
01-12 01:53:10.849: E/BluetoothSocket(25004): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
01-12 01:53:10.849: E/BluetoothSocket(25004): at dalvik.system.NativeStart.main(Native Method)
我有一个非常简单的arduino代码。
int incomingByte;
char val;
void setup() {
pinMode(2, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
val = Serial.read();
Serial.println(val);
}
delay(100);
}
答案 0 :(得分:0)
您是否尝试将println()
更改为write()
?
如下所示:
if (Serial.available() > 0) {
val = Serial.read();
Serial.write(val);
}