简体   繁体   English

如何在 Qt 中的 Android 上使用 USB OTG 串行接口?

[英]How can one use an USB OTG serial interface on Android, in Qt?

I intend to port a Qt desktop application to Android.我打算将 Qt 桌面应用程序移植到 Android。 It uses QSerialPort to communicate with an external device (which has a built-in CP210x)它使用 QSerialPort 与外部设备(具有内置 CP210x)进行通信

The application, although written purely in Qt and C++, runs fine on Android, but it doesn't see the device.该应用程序虽然纯粹用 Qt 和 C++ 编写,但在 Android 上运行良好,但看不到设备。 The CP210x official driver download page recommends to compile the kernel on Android from source, which is not feasible to expect from the average customer. CP210x官方驱动下载页面建议从源码编译Android上的kernel,这对于普通客户来说是不可行的。 Other recommendations I found online recommend jailbraking the phone, which also isn't something we could expect end users to do.我在网上找到的其他建议建议越狱手机,这也不是我们期望最终用户做的事情。

There are scant few questions in this topic on the Qt forums, most saying that QSerialPort's Android support is quite limited. Qt 论坛上关于这个主题的问题很少,大多数人说 QSerialPort 的 Android 支持非常有限。 However, these topics are often at least 6-7 years old.但是,这些主题通常至少有 6-7 年的历史。

An Android developer forum/wiki/tutorial? Android 开发者论坛/wiki/教程? recommends to use "Android Things", whatever it is.建议使用“Android Things”,无论它是什么。 I couldn't find any apps fitting that description.我找不到任何符合该描述的应用程序。

I know that it's physically possible to use serial-usb on an non-jailbroken Android, as I tried out a serial console app and it worked, I could successfully exchange data with my device.我知道在非越狱 Android 上使用串行 USB 在物理上是可能的,因为我尝试了一个串行控制台应用程序并且它工作正常,我可以成功地与我的设备交换数据。

Does this mean that the only was is to develop my own wrapper in Java, and use JNIEXPORT?这是否意味着唯一的方法是在 Java 中开发我自己的包装器,并使用 JNIEXPORT? That would break the easy multi-platform compilation I used before (just selecting a different kit from Qt Creator) Are there any simpler ways to accomplish this?那会破坏我之前使用的简单的多平台编译(只需从 Qt Creator 中选择不同的套件)有没有更简单的方法来完成这个? Is USB OTG usage so low that no one else thought to implement anything in this regard? USB OTG 的使用率是否如此之低以至于没有人想到在这方面实施任何事情?

QSerialPort has only a non-official partial Android Support (see https://wiki.qt.io/Qt_Serial_Port ). QSerialPort 只有非官方的部分 Android 支持(参见https://wiki.qt.io/Qt_Serial_Port )。

(... Use on own risk, only for rooted devices, in which is it possible to get/set a permissions to the /dev/ttyXYZ nodes) (......使用风险自负,仅用于有根设备,其中可以获取/设置 /dev/ttyXYZ 节点的权限)

You can use JNI to get a FileDescriptor with permission and then use the libusb library in C++ to communicate with device.您可以使用 JNI 获取具有权限的 FileDescriptor,然后使用 C++ 中的 libusb 库与设备通信。 But yes, it would break the easy multi-platform compilation.但是,是的,它会破坏简单的多平台编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM