问题
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?
- What headers need to be included in order for this library to work.
- 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.
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
Then extract the file descriptor of the USB device using the method getFileDescriptor()
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