简体   繁体   English

libusb_open_device_with_vid_pid function 返回 0 即使我将 USB 设备连接到 android 手机

[英]libusb_open_device_with_vid_pid function returns 0 eventhough i connected a USB device to the android phone

I am new to android platform and libusb.我是 android 平台和 libusb 的新手。 I developed an android application which uses libusb in NDK.我开发了一个在 NDK 中使用 libusb 的 android 应用程序。 When I am connecting Pendrive into my android device libusb_open_device_with_vid_pid function returns 0(No device found) .当我将 Pendrive 连接到我的 android 设备libusb_open_device_with_vid_pid function returns 0(No device found) I gave full permission to USB.我完全同意 USB。 But still, I am not getting PID and VID of the USB device.但是,我仍然没有得到 USB 设备的 PID 和 VID。

I am execuing libusb_init(NULL) before executing libusb_open_device_with_vid_pid function.我在执行 libusb_open_device_with_vid_pid function 之前执行 libusb_init(NULL)。 I am getting 0 as return value for libusb_init.我得到 0 作为 libusb_init 的返回值。 So there is no issue with libusb initialization.所以libusb初始化没有问题。

I have another app that uses android host API.我有另一个使用 android 主机 API 的应用程序。 I can view PID and VID of the USB device.我可以查看 USB 设备的 PID 和 VID。 But I am unable to view it while i am using libusb.但是我在使用 libusb 时无法查看它。

I am using Samsung S20G android device, libusb version - 1.0.23, Android studio - 4.0.我正在使用三星 S20G android 设备,libusb 版本 - 1.0.23,Android studio - 4.0。

Does anyone have an idea about this?有人对此有任何想法吗?

Have you tried executing your application as root?您是否尝试过以 root 身份执行您的应用程序? In Linux, when you connect a device to the system it'll create a file (in the location /dev).在 Linux 中,当您将设备连接到系统时,它将创建一个文件(在位置 /dev 中)。 libusb need to access this file which usually requires root permission. libusb 需要访问这个文件,这通常需要 root 权限。

Thank you for your information.感谢您的信息。

I executed my application as root only.我仅以 root 身份执行我的应用程序。 But I didn't get VID and PID.但我没有得到 VID 和 PID。 After that I have changed the libusb version and Now I got the VID and PID, data as well.之后,我更改了 libusb 版本,现在我也获得了 VID 和 PID,以及数据。

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

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