I am writing software to communicate between tablet (Motorola Xoom with Android version 4.0.3 and Kernel version 2.6.39.4) and a peripheral device using USB Host API provided by Android. I use only two types of communication:
- control:
controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int length, int timeout)
- bulk:
bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int length, int timeout)
Control transfer works fine, but I have a problem with bulk transfer. I can use only 32768 as a size of the buffer for bulkTransfer function. It is not possible to use less or more. I know that I cannot use more because of the limit of the buffer pipe (size: 32769 bytes).
This peripheral device streams data which is not correctly read by bulkTranfer function. I suppose that some data is lost.
And based on that, my explanation of the problem is that some data is not written to pipe (buffer) because of blocking flag made by write(2) function. Am I correct? If this is true I could change pipe buffer.
- My first solution for this problem is greater buffer. For
kernel >= 2.6.35, you can change the size of a pipe with
fcntl(fd, F_SETPIPE_SZ, size)
but how can I findfd
(file descriptor) for USB pipes? - Second option is to use
ulimit -p SIZE
but parameterp
for my kernel is not for pipe but process.
Has anyone faced the same problem, any solutions?