我正在尝试通过USB串口使用Mike Wakerly的usb-serial-for-android库与Arduino Mega克隆进行通信(谢谢!)我已经挖掘了权限错误,但现在我得到了以下问题:
09-02 15:08:03.628 18694-18792/org.drivebuv.buvmonitor W/SerialInputOutputManager﹕ Run ending due to exception: Error queueing request.
java.io.IOException: Error queueing request.
at org.drivebuv.buvmonitor.CdcAcmSerialDriver$CdcAcmSerialPort.read(CdcAcmSerialDriver.java:168)
at org.drivebuv.buvmonitor.SerialInputOutputManager.step(SerialInputOutputManager.java:158)
at org.drivebuv.buvmonitor.SerialInputOutputManager.run(SerialInputOutputManager.java:140)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
方法如下。抛出错误的行是!request.queue(buf, dest.length)
public int read(byte[] dest, int timeoutMillis) throws IOException {
if (mEnableAsyncReads) {
final UsbRequest request = new UsbRequest();
try {
request.initialize(mConnection, mReadEndpoint);
final ByteBuffer buf = ByteBuffer.wrap(dest);
if (!request.queue(buf, dest.length)) {
throw new IOException("Error queueing request.");
}
final UsbRequest response = mConnection.requestWait();
if (response == null) {
throw new IOException("Null response");
}
final int nread = buf.position();
if (nread > 0) {
Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
return nread;
} else {
return 0;
}
} finally {
request.close();
}
}
final int numBytesRead;
synchronized (mReadBufferLock) {
int readAmt = Math.min(dest.length, mReadBuffer.length);
numBytesRead = mConnection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt,
timeoutMillis);
if (numBytesRead < 0) {
// This sucks: we get -1 on timeout, not 0 as preferred.
// We *should* use UsbRequest, except it has a bug/api oversight
// where there is no way to determine the number of bytes read
// in response :\ -- http://b.android.com/28023
if (timeoutMillis == Integer.MAX_VALUE) {
// Hack: Special case "~infinite timeout" as an error.
return -1;
}
return 0;
}
System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
}
return numBytesRead;
}
以前,他在第319行的CdcAcmSerialDriver.java中似乎有一个错误:
mDataInterface = mDevice.getInterface(1);
所以我将1更改为0,根据How to fix java.lang.ArrayIndexOutOfBoundsException: length=1; index=1修复了索引越界错误。结束将所有.java文件移动到我的包中以便编辑它们。甚至不确定这是否相关。
目前,我的应用程序在该异常后挂起。一句话:我在这里用低级代码游泳并且没有使用kludges。请你指点我的土地:)?