我使用的是官方驱动程序http://www.ftdichip.com/Android.htm http://www.ftdichip.com/Android.htm
03-20 13:37:52.359:警告/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:警告/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 的开发板。
我做到了..
You have按照此顺序读取传入数据:
- 打开后调用restartInTask()
- 在读取之前获取可用的输入字节
- 仅当可用字节数 > 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");
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)