简体   繁体   English

使用open2(,int fd)的Android libusb

[英]libusb for Android using open2(, int fd)

I compiled the modified version of libusb to be used in Android devices from 我编译了libusb的修改后的版本,可用于以下版本的Android设备

https://github.com/martinmarinov/rtl_tcp_andro-/blob/master/jni/libusb-andro/README https://github.com/martinmarinov/rtl_tcp_andro-/blob/master/jni/libusb-andro/README

Is there any example on how to use this particular function in a C program? 有没有关于如何在C程序中使用此特定功能的示例?

  1. What headers need to be included in order for this library to work. 为了使该库起作用,需要包括哪些头。
  2. Any examples on how to use open2(, int fd) in a C program 有关如何在C程序中使用open2(,int fd)的任何示例

This is no new library. 这不是新图书馆。 Only a modified version of libusb. 仅libusb的修改版本。 So, all the libusb commands are applicable here. 因此,所有libusb命令都适用于此。 The only difference would be libusb_open2 which you would have to use in stead of libusb_open. 唯一的区别是libusb_open2,您必须使用它代替libusb_open。 From the libusb/libusb.h file, the prototype of libusb_open2 is visible. 从libusb / libusb.h文件中,可以看到libusb_open2的原型。

int LIBUSB_CALL libusb_open2(libusb_device *dev, libusb_device_handle **handle, int fd);

Now, for using libusb on android, the steps would be. 现在,要在Android上使用libusb,步骤将是正确的。

  1. First get permissions for the USB device you are interested in. The details are given here : http://developer.android.com/guide/topics/connectivity/usb/host.html 首先获取您感兴趣的USB设备的权限。详细信息在此处提供: http : //developer.android.com/guide/topics/connectivity/usb/host.html

  2. Then extract the file descriptor of the USB device using the method getFileDescriptor() 然后使用方法getFileDescriptor()提取USB设备的文件描述符。

  3. Use this file descriptor open connection to the usb device. 使用此文件描述符打开的连接到USB设备。 That is make a libusb_device. 那就是制作一个libusb_device。

Now you can use this libusb_device to do all the stuff that can be done on computer using libusb. 现在,您可以使用此libusb_device来完成可以使用libusb在计算机上完成的所有工作。 There are plenty of examples given on the libusb website . libusb网站上有很多示例。

For other queries you can hangout on #libusb on freenode. 对于其他查询,您可以在freenode上的#libusb上进行视频群聊。 For specific examples, go through the documentation. 有关特定示例,请阅读文档。 Try on your own. 自行尝试。 And if stuck somewhere ask here. 如果卡在某个地方,请问这里。 Do no expect spoonfeeding. 不要指望喂汤。

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

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