2013-03-20 33 views
3

我使用官方驅動從http://www.ftdichip.com/Android.htm官方FTDI的Android驅動程序的read()不工作

03-20 13:37:52.359:WARN/FTDI(4453):閱讀開始

03 -20 13:37:52.359:WARN/FTDI(4453):37::可用

03-20 13 6個字節57.960:WARN/FTDI(4453):0字節讀

03-20 13: 37:57.960:WARN/FTDI(4453):閱讀完成

這樣做的源代碼很簡單:

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"); 
    } 
} 

他們的支持部門沒有回覆我,甚至一個星期後。我在Android 4.0.4上使用Arduino Duemilanove基於ftdi的電路板。

+0

任何代碼如何調用此'讀'功能?什麼是緩衝區?什麼是設備? – RvdK 2013-03-20 08:18:17

+0

看到上面的代碼(byte [] buffer = new byte [1024],所以它似乎沒問題)。它是三星galaxy tab2 10.1(android ICS),另一個usb lib工作正常(包括read())。但它沒有所有必要的功能,所以我更喜歡官方驅動程序,但工作 – 4ntoine 2013-03-20 08:20:15

回答

3

是的,我做到了..

遵循這一以讀取輸入數據:

  1. 開盤後調用restartInTask()
  2. 獲取可用輸入讀取字節前
  3. 只讀可用字節數> 0

工作代碼片段:

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"); 
     } 
    } 
+0

我意識到這是一個老問題,但我有一個類似的問題(請參閱我的問題:http://stackoverflow.com/questions/ 22985558/FTDI-D2XX-Android的Java的未讀)。但是,您的解決方案對我無效。 – Bovaz 2014-04-10 14:30:37

相關問題