【问题标题】:Official FTDI android drivers read() is not working官方 FTDI android 驱动程序 read() 不工作
【发布时间】:2013-03-20 08:04:19
【问题描述】:

我正在使用来自http://www.ftdichip.com/Android.htm的官方驱动程序

03-20 13:37:52.359:WARN/FTDI(4453):读取开始

03-20 13:37:52.359:WARN/FTDI(4453):6 个字节可用

03-20 13:37: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 的开发板。

【问题讨论】:

  • 任何代码你如何调用这个“读取”函数?什么是缓冲区?什么是设备?
  • 见上面的代码(byte[] buffer = new byte[1024] 所以看起来没问题)。它是三星 Galaxy Tab2 10.1(Android ICS),另一个 USB 库工作正常(包括 read())。但它没有所有必要的功能,所以我更喜欢官方驱动程序但可以工作

标签: android driver ftdi


【解决方案1】:

是的,我做到了..

必须遵循此操作才能读取传入数据:

  1. 打开后调用restartInTask()
  2. 在读取之前获取可用的输入字节
  3. 仅当可用字节数 > 0 时才读取

工作代码sn-p:

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

【讨论】:

  • 我意识到这是一个老问题,但我遇到了一个看起来相似的问题(请参阅我的问题:stackoverflow.com/questions/22985558/…)。但是,您的解决方案对我不起作用。
猜你喜欢
  • 2011-04-24
  • 2014-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多