android - 将原始数据写入 Android 串行端口 (USB)

标签 android android-ndk serial-port usb libusb

我需要为我的一个项目将一些“原始”数据写入 USB 端口(如果需要 root 则没有问题)。

我找到了一个 port of libusb for Android并设法用 NDK 编译它。我将库链接到我的可执行文件(以 root 身份执行),但函数“libusb_init”总是返回错误 (LIBUSB_ERROR_OTHER)。

我发现问题(到现在...)在文件“linux_usbfs.c”中,更准确地说是在这个函数中:

static const char *find_usbfs_path(void)
{
    const char *path = "/dev/bus/usb";
    const char *ret = NULL;

    if (check_usb_vfs(path)) {
        ret = path;
    } else {
        path = "/proc/bus/usb";
        if (check_usb_vfs(path))
            ret = path;
    }

    usbi_dbg("found usbfs at %s", ret);
    return ret;
}

/dev/bus/usb 显然在我的 N1 上不存在。

最佳答案

为什么不试试 pyserial? python 对我来说似乎更简单。您需要一个带有 usb 主机模式的内核,或者您的手机本身支持通过 ttyMSM0 串口,您需要了解这一点。确定手机上有串行端口后,请查看此 link这适用于 huawei ideos U8150,但我建议使用 python for android 完成的 pyserial 内容是替代方案。

关于android - 将原始数据写入 Android 串行端口 (USB),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5880622/

相关文章:

android - 不管怎样从时间上得到上午/下午?

android - 重新启动启动器 Activity 后的空白屏幕( Binder 交易失败)

android - SQLiteDatabase 表不是在 Android 中创建的

Android Gradle 避免 CMake 项目不必要的重建

android - LOCAL_SHARED_LIBRARIES 和 LOCAL_REQUIRED_MODULES 之间的区别?

android - 在 Android 上的 NDK 库中使用 Clang 地址清理程序

c# - 更改 system.io.port datareceived 事件输出类型

c# - CPU 高使用率和串口时间

android - 如何测量android wifi连接中的上传/下载速度和延迟

algorithm - 使用缓冲区对串行数据进行排序