androidserial-portusbioctlftdi

Reading USB with ioctl fails for "value too large for defined data type"


I am trying to read USB using with an ioctl and USBDEVFS_BULK (in native on Android). The USB cable I am using contains an FTDI chip and sends data over from an Arduino UNO, which writes Serial.

The write on Android seems to always succeed but the read either always fail, or succeeds for a few entries then constantly fail with "Value too large for defined data type" (75). I am using this setup a simple ping test: write one byte, a sequence number on Android; Arduino reads the byte and replies with the same sequence number.

I am not completely sure what this error is saying. The way I understood it is that the device sent more data than the buffer I pass to the ioctl can accommodate. I've made sure that my Arduino sends only 1 byte back, and I expect to see 2 more for the FTDI, for a total of 3 bytes. Even increasing the buffer size does not seem to fix the issue.

char mReadData[3];
struct usbdevfs_bulktransfer bulkTransferRead = {
    mReadEndpoint,  // Endpoint
    3,              // Length in bytes
    0,              // Timeout (ms)
    mReadData,     // Data
};

ret = ioctl(mFd, USBDEVFS_BULK, &bulkTransferRead);

This is the code I am using natively. If I try to use Android/Java code for the read and write (using bulkTransfer()) I am seeing the same intermittent issue with the read. In Java on Android, I've made sure to do the following before any write/read:

1) Reset pin 2) Set baud rate 3) 8N1

Can anyone please help me describe what I am misunderstanding about FTDI/USB or explain this errno about "value too large for defined data type" please?


Solution

  • I found a solution. It seems this error, EOVERFLOW, can be fixed just by specifying a buffer size that is equal to the max packet size of the endpoint. This solved my issue.