On 20/08/13 05:44, Anton Smirnov wrote:
2013/8/19 Toby Gray <toby.g...@realvnc.com <mailto:toby.g...@realvnc.com>>
On 18/08/13 13:01, Anton Smirnov wrote:
Android can return file descriptor for native code:
http://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection.html#getFileDescriptor()
<http://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection.html#getFileDescriptor%28%29>
Does libusbx support it?
Not currently. It would be quite a change to be able to support it
as libusb would need to map the open file descriptor back to a bus
and device, which would be hard.
Not sure that it's true but anyway. Behind the scene libusb get's file
descriptor as int and holds it in internal structure. So android just
returns exactly the same int file descriptor, so there is no need to
open file using liusb_open() - we just need to inject ready file
descriptor.
For the Linux backend, which is the backend currently used on Android, a
libusb_device is not a file descriptor. Part of a libusb_device_handle
is a file descriptor, but a libusb_device_handle also includes a
reference to a libusb_device. A libusb_device accesses sysfs entries for
some libusb API calls, e.g. libusb_get_configuration:
https://github.com/libusbx/libusbx/blob/master/libusb/os/linux_usbfs.c#L564
An alternative choice would be to add an Android backend which
makes use of JNI to invoke the UsbDeviceConnection APIs, although
that would be equally tricky.
This is already done in this project (see introduced
voidusb_device_set_open_close_func(..)
https://github.com/keesj/librtlsdr-android/blob/android/include/libusb.h
While usb_device_set_open_close_func(..) is clearly suitable for the
librtlsdr-android project, I would feel that it isn't suitable as an API
for addition to libusb. I'm not a maintainer of libusb so my opinion
isn't important, but I would send strongly worded emails about it :)
In my mind the correct solution would be to add an Android backend which
invoked the appropriate APIs via JNI. In fact I've now added that to my
TODO list as it'll be an interesting thing to look into, but that
probably means many years before I actually get around to it!
What are you trying to do?
I'm trying to communicate with usb device that uses FTDI chip on Android.
Sorry, I should have been clearer in my question. It sounds to me like
you are writing native code to use libftdi to talk to an FTDI chip and
libftdi uses libusb. Is that correct?
If you want to get a list of devices for use with libusb you
should call the libusb API for it ( libusb_get_device_list). If
you want to use the android.hardware.usb.* APIs to access the
device you should use those APIs.
This already works for me using libusb_get_device_list().
The problem is that any request fails with -32 error even if request
data is exactly the same as required.
I didn't want to assume that this is the same issue you were talking
about on the libusb mailing list, but it sounds like it is. Do you have
access to a USB bus analyser to check if the request is ever making it
onto the bus? If not then is there any chance of you being able to put a
custom kernel on the Android device to get a usbmon trace?
The same code works great for CDC-devices so general approach is
working for me.
Does libftdi support CDC-devices? Or have you written your own code
which calls libusb APIs to talk to CDC-devices?
libftdi is a small lib to create vendor-specific usb requests (to set
baud rate, line controls, etc), so it does not make sense in general.
the problem is that it works over libusb for usb interaction and it's
libusb error, not libftdi.
Ok.
Regards,
Toby
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel