我正在使用来自 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
这个的源代码很简单:
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 的开发板。
最佳答案
是的,我做到了..
您必须遵循此以读取传入数据:
- 打开后调用restartInTask()
- 在读取之前获取可用的输入字节
- 只读可用字节数> 0
工作代码 fragment :
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");
}
}
关于android - 官方 FTDI android 驱动程序 read() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15518214/