3

I'm using official drivers from http://www.ftdichip.com/Android.htm

03-20 13:37:52.359: WARN/FTDI(4453): read starting

03-20 13:37:52.359: WARN/FTDI(4453): 6 bytes available

03-20 13:37:57.960:WARN/FTDI(4453): 0 bytes read

03-20 13:37:57.960: WARN/FTDI(4453): read finished

The source code for this is trivial:

public int read(byte[] buffer, int timeout) throws IOException {
    Log.w(TAG, "read starting");
    try {            
        Log.w(TAG, device.getQueueStatus() + " bytes available");
        int read = device.read(buffer);
        Log.w(TAG, read + " bytes read");
        return read;
    } finally {
        Log.w(TAG, "read finished");
    }
}

Their support department did not reply to me, even after a week. I'm on Android 4.0.4, with a Arduino Duemilanove ftdi-based board.

halfer
  • 19,824
  • 17
  • 99
  • 186
4ntoine
  • 19,816
  • 21
  • 96
  • 220
  • Any code how you call this 'read' function? What is buffer? what is device? – RvdK Mar 20 '13 at 08:18
  • See code above( byte[] buffer = new byte[1024] so it seems to be ok with it). It's samsung galaxy tab2 10.1 (android ICS) and another usb lib is working ok (including read()). But it does not have all necessary features so i'd prefer official drivers but working – 4ntoine Mar 20 '13 at 08:20

1 Answers1

3

Yes, i did it..

You have to follow this in order to read incoming data:

  1. invoke restartInTask() after opening
  2. get available input bytes before reading
  3. read only if available bytes count > 0

working code snippet:

public int read(byte[] buffer, int timeout) throws IOException {
        params.setReadTimeout(timeout);
        Log.w(TAG, "read starting");
        try {
            int available = device.getQueueStatus();
            Log.w(TAG, available + " bytes available");

            if (available <= 0)
                return 0;

            int read = device.read(buffer, available, timeout);
            Log.w(TAG, read + " bytes read");
            return read;
        } finally {
            Log.w(TAG, "read finished");
        }
    }
4ntoine
  • 19,816
  • 21
  • 96
  • 220
  • I realize this is an old question, but I am having a problem that looks similar (see my question: http://stackoverflow.com/questions/22985558/ftdi-d2xx-android-java-not-reading). However, your solution does not work for me. – Bovaz Apr 10 '14 at 14:30