我正在通过 UART 在运行 Android Things 的 RPi 3 和 Arduino 之间进行通信。
在 RPi 应用程序上按下按钮后,命令将发送到 Arduino 。那里没有问题。 Arduino 每2秒发送一次信息包。
这非常有效,直到我按下将数据发送到 Arduino 的按钮。 Arduino 接收到按钮命令,但 Android 应用程序崩溃。我什至可以在应用程序崩溃之前按两次按钮,然后 Arduino 成功接收两次按下。问题似乎出在 Arduino 在按下按钮后发送下一个数据包时。
如果我断开 RPi UART RX ,则该按钮不会导致崩溃。换句话说,只要没有传入数据,应用程序就可以正常运行,反之亦然。我无法理解错误:
...
for %%f in (test.txt) do (
(
<nul set /p ".= %%~nxf,%%~zf Bytes,"
certutil -hashfile "%%f" MD5 | find /V ":"
) >>%OUTFILE%
)
...
接收到的数据示例:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: za.co.leafbox.boxcontrol, PID: 8817
java.lang.NumberFormatException: For input string: "pump"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.lang.Float.parseFloat(Float.java:452)
at za.co.leafbox.boxcontrol.MainActivity$2.readUartBuffer(MainActivity.java:284)
at za.co.leafbox.boxcontrol.MainActivity$2.onUartDeviceDataAvailable(MainActivity.java:234)
at com.google.android.things.pio.UartDeviceImpl$UartDeviceCallbackDispatch.dispatchInterruptEvent(UartDeviceImpl.java:250)
at com.google.android.things.pio.CallbackDispatch.onFileDescriptorEvents(CallbackDispatch.java:149)
at android.os.MessageQueue.dispatchEvents(MessageQueue.java:284)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I/MainActivity: [45, 49, 46, 48, 48, 32, 49, 56, 46, 53, 48, 32, 54, 53, 46, 49, 48, 32, 45, 48, 46, 48, 56, 32, 48, 46, 48, 48, 32, 49, 54, 46, 51, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
功能:
OnClick
UART 回调:
public void pumpToggle(View view){
try{
if (((ToggleButton) view).isChecked()) {
byte[] buffer = {'g', 'g', '\n'};
writeUartData(aNano, buffer);
}
else{
byte[] buffer = {'g', 's', '\n'};
writeUartData(aNano, buffer);
}
} catch (IOException e) {
Log.e(TAG, "Data not Sent", e);
}
}
答案 0 :(得分:1)
parseFloat (tankLevelString)是您获得NumberFormatException的那一行。显然,不能将tankLevelString
解析为“ pump” 。我建议调查原因。