libusb for Android using open2(, int fd)

▼魔方 西西 提交于 2019-12-23 03:34:12

问题


I compiled the modified version of libusb to be used in Android devices from

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?

  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

回答1:


This is no new library. Only a modified version of libusb. So, all the libusb commands are applicable here. The only difference would be libusb_open2 which you would have to use in stead of libusb_open. From the libusb/libusb.h file, the prototype of libusb_open2 is visible.

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

Now, for using libusb on android, the steps would be.

  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

  2. Then extract the file descriptor of the USB device using the method getFileDescriptor()

  3. Use this file descriptor open connection to the usb device. That is make a libusb_device.

Now you can use this libusb_device to do all the stuff that can be done on computer using libusb. There are plenty of examples given on the libusb website.

For other queries you can hangout on #libusb on freenode. For specific examples, go through the documentation. Try on your own. And if stuck somewhere ask here. Do no expect spoonfeeding.



来源:https://stackoverflow.com/questions/24112345/libusb-for-android-using-open2-int-fd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!