- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在通过 UART 在运行 Android Things 的 RPi 3 和 Arduino 之间进行通信。
按下 RPi 应用程序上的按钮后,一条命令将发送到 Arduino。那里没有问题。 Arduino 每 2 秒发送一个信息包。
在我按下一个将数据发送到 Arduino 的按钮之前,这一切都完美无缺。 Arduino 收到按钮命令,但 Android 应用程序崩溃。我什至可以在应用程序崩溃之前按两次按钮,Arduino 成功接收到两次按下。问题似乎出在按下按钮后 Arduino 发送下一个数据包时。
如果我断开 RPi UART RX 按钮不会导致崩溃。换句话说,只要没有传入数据,应用程序就可以正常工作,反之亦然。我无法理解错误:
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
函数:
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);
}
}
UART 回调:
private UartDeviceCallback mUartCallback = new UartDeviceCallback() {
@Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
// Read available data from the UART device
Log.i(TAG, "onUartDeviceDataAvailable");
try {
readUartBuffer(uart);
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}
// Continue listening for more interrupts
return true;
}
private void readUartBuffer(UartDevice uart) throws IOException {
// Maximum amount of data to read at one time
Log.i(TAG, "readUartBuffer");
final int maxCount = 64;
byte[] buffer = new byte[maxCount];
byte[] convertBuf = new byte[20];
boolean dataCompleteFlag = false;
uart.read(buffer, maxCount);
if (!dataCompleteFlag) {
for (int i = 0; i < maxCount; i++) {
if (buffer[i] == 36) {
dataCompleteFlag = true;
measureCount++;
dataCount = 0;
}
else if(dataCount > maxCount) {
dataCount = 0;
}
else if(buffer[i] != 0) {
finalDataBuffer[dataCount] = buffer[i];
dataCount++;
}
}
}
if (dataCompleteFlag) {
Log.i(TAG, Arrays.toString(finalDataBuffer));
int index = 0;
int offSet;
while (index < maxCount && finalDataBuffer[index] != 32) {
convertBuf[index] = finalDataBuffer[index];
index++;
}
index++;
offSet = index;
tankLevelString = new String(convertBuf);
Float tankFloat = parseFloat(tankLevelString);
tankLevelString += "cm";
while (index < maxCount && finalDataBuffer[index] != 32) {
convertBuf[index - offSet] = finalDataBuffer[index];
index++;
}
index++;
offSet = index;
airTempString = new String(convertBuf);
airTempString += "\u00b0C";
while (index < maxCount && finalDataBuffer[index] != 32) {
convertBuf[index - offSet] = finalDataBuffer[index];
index++;
}
index++;
offSet = index;
humidityString = new String(convertBuf);
humidityString += "%";
while (index < maxCount && finalDataBuffer[index] != 32) {
convertBuf[index - offSet] = finalDataBuffer[index];
index++;
}
index++;
offSet = index;
ecString = new String(convertBuf);
while (index < maxCount && finalDataBuffer[index] != 32) {
convertBuf[index - offSet] = finalDataBuffer[index];
index++;
}
index++;
offSet = index;
phString = new String(convertBuf);
while (index < maxCount && finalDataBuffer[index] != 0) {
convertBuf[index - offSet] = finalDataBuffer[index];
index++;
}
waterTempString = new String(convertBuf);
TextView airTemp = findViewById(R.id.airTemp);
airTemp.setText(airTempString);
TextView humidity = findViewById(R.id.humidity);
humidity.setText(humidityString);
TextView tankLevel1 = findViewById(R.id.tankLevel1);
tankLevel1.setText(tankLevelString);
TextView ec = findViewById(R.id.ec);
ec.setText(ecString);
TextView ph = findViewById(R.id.ph);
ph.setText(phString);
TextView wt = findViewById(R.id.waterTemp);
wt.setText(waterTempString);
}
}
@Override
public void onUartDeviceError(UartDevice uart, int error) {
Log.w(TAG, uart + ": Error event " + error);
}
};
最佳答案
parseFloat (tankLevelString)是你得到的线 NumberFormatException在。显然,tankLevelString
,即“pump”,无法解析为float
。我建议调查导致它的原因。
关于android - RPi 3 Android Things UART 双向通信崩溃应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52188425/
我不明白以下两个语句之间的区别: Thing thing; Thing thing = Thing(); 两者都创建了一个Thing对象,并把它放在变量thing中,对吧?如果是,两个问题: 1- 两
我将 RPi3 与 Android Things 0.5.1 一起使用。虽然我在我的 AndroidManifest.xml许可: 我得到了异常(exception): java.lang.Secu
我在使用 Microsoft Access 2003 时遇到问题,它提示以下声明: select cardnr from change where year(date)<2009 group by
如何使用预览版 2 更新我的 Android Things 预览版 1?是否有自动 OTA 可用,或者现在不可能,所以我必须刷新 SD 卡(来自我的 Raspberry Pi)? 最佳答案 编辑 1:
任何人都可以解释为什么这是真的 $a = Array('b' = > 'okokokok'); if ( isset( $a['b']['ok'] ) ) { echo $a['b
无法找到如何从相机拍摄单张照片的方法。 在使用图像阅读器并使用 TEMPLATE_STILL_CAPTURE 发送捕获请求时,应用程序只是停在这个位置,没有其他任何事情发生。 尝试使用我的代码,认为问
我知道错误的含义,但我无法修复它。我正在使用 mockers 来测试我的工作,但在尝试验证提供给模拟特征函数的结构参数时遇到了困难。简化代码: #[cfg(test)] extern crate mo
在官方 schema.org 文档中,我可以看到每个类都继承了 Thing 的属性。类,例如 Book类还有name , image等等(来自 Thing 的属性)。 我的问题是,我可以获得例如 im
假设 $thing 可以是任何类型,这两个语句的执行是否相同? if (!empty($thing)) { // do stuff } if ($thing) { // do stuf
代码: static const void *const uniquePtr = &uniquePtr; …将在编译单元中提供一个唯一的void指针。以这种方式为喜欢将名称作为 void* 的 API
我在github中有这段代码 https://github.com/neuberfran/sample-button-master 我有问题: java.lang.IncompatibleClassC
试图从 gpio 读取模拟数据,但只看到一种将信号强度返回为 LOW 或 HIGH( bool 值)的方式。 在文档和代码引用中找不到任何解决方案。 现在甚至可能吗? 最佳答案 树莓派 3 没有 an
在使用 Android Things 控制台创建另一个 Android Things 产品时,我再次想知道要选择什么 oem 分区大小。此设置的信息是“必须在 32 到 512 MB 之间”,这是一个
我在Raspberry Pi上安装了一个小屏幕,并根据屏幕的documentation: Write the image to a TF card and append the following l
我计划将 Raspberry PI 用于 Android Things 项目,我可以在其上闪烁默认图像 (androidthings_rpi3_devpreview_4_1.zip)。我已经安装了我的
我知道 Android Things 支持 NDK。我找不到以一种或另一种方式说明 Android Things 是否支持 RenderScript Compute 的引用。我的假设是否定的(因为并非
昨天我开始了一个 Android Things 项目,我正在使用 Android Studio 测试该应用程序。为了使用 adb.exe 连接到设备,我使用了我在默认操作系统的应用程序(起始屏幕)上看
我正在解决的问题是在所有页面(问题、标签等)上调用 Stack Exchange API (1.1)。但事实上,这似乎也可能是一个普遍问题,所以我在这里发帖,而不是在 StackApps 上。 因此,
哪些因素决定哪种方法更合适? 最佳答案 我认为两者都有自己的位置。 你不应该简单地使用 DoSomethingToThing(Thing n)只是因为你认为“函数式编程很好”。同样,您不应该简单地使用
这个问题已经有答案了: using brackets with javascript import syntax (2 个回答) 已关闭 5 年前。 我正在观看 Pluralsight 上的一些培训视
我是一名优秀的程序员,十分优秀!