java - android studio 通过 USB 与 arduino 进行串行通信
问题描述
我正在尝试通过 USB 在我的 arduino nano 和我的应用程序之间传递数据。我正在使用https://github.com/felHR85/UsbSerial/库。
经过几次尝试使用提供的示例代码后,我尝试测试我的测试代码的问题:
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
if (usbDevices.isEmpty()) {
Log.d(TAG, "findSerialPortDevice() usbManager returned empty device list." );
}
在我的清单中:
<uses-feature android:name="android.hardware.usb.host" android:required="true"/>
问题是 UsbManager 总是空的,我认为手机没有检测到 USB 设备。
我将我的 arduino 和计算机都用作 USB 设备,并尝试使用我的 pocophone、三星平板电脑和另一部三星手机。我使用了 2 根不同的电缆。
我读到问题可能出在我的设备上(即使我使用了 3 个设备)我使用了 USB 主机诊断应用程序,结果如下:
我第一次尝试在android中使用任何类型的通信。谢谢你。
解决方案
推荐阅读
- python - 如何在核心用户下在 CoreOS 上安装 Python?
- scala - 为什么`xs reverse_::: ys`有效?
- xquery - 错误 - '/' 的第一个操作数的必需项类型是 node();提供的值具有项目类型 xs:untypedAtomic
- c - 为什么这会造成无限循环?
- javascript - 如何在没有样式滑块的光滑滑块中设置点的样式
- docker - Docker:无法准备上下文:无法评估上下文路径中的符号链接:readlink C:\Users\fred.blogs\My Documents:访问被拒绝
- python - 使用正则表达式在python中删除与句点或句号连接的单词
- jquery - 如何在ajax中添加一个新变量
- llvm - LLVM 正则表达式
- spring - NoSuchMethodError Couchbase 2.5.8 Spring Boot 启动错误