おそらく私はここで質問を誤解しています。レベル 12 以降の API パッケージの一部であるサンプル ミサイルランチャー アプリは、 メソッドqueue()
とrequestWait()
メソッドを使用して、割り込みタイプのエンドポイントを処理します。リクエストは In または Out のいずれかであり、EndPoint の方向によって異なります。
かなりノリノリな request->reply のコードは次のようになります。実際のコードを別の方法で構造化したいと思うでしょうが、これにより、何が起こる必要があるのか の要点が得られます(願っています)
public void run() {
int bufferMaxLength=mEndpointOut.getMaxPacketSize();
ByteBuffer buffer = ByteBuffer.allocate(bufferMaxLength);
UsbRequest request = new UsbRequest(); // create an URB
request.initialize(mConnection, mEndpointOut);
buffer.put(/* your payload here */;
// queue the outbound request
boolean retval = request.queue(buffer, 1);
if (mConnection.requestWait() == request) {
// wait for confirmation (request was sent)
UsbRequest inRequest = new UsbRequest();
// URB for the incoming data
inRequest.initialize(mConnection, mEndpointIn);
// the direction is dictated by this initialisation to the incoming endpoint.
if(inRequest.queue(buffer, bufferMaxLength) == true){
mConnection.requestWait();
// wait for this request to be completed
// at this point buffer contains the data received
}
}
}
スレッドをバインドせずに、この IO を非同期で実行する方法を実際に探している場合は、DeviceConnection.getFilehandle()
メソッドを使用して、理論的には標準のファイル ハンドルを返すことを検討する必要があると思います。その他のファイル タイプのリソース。ただし、これを試していないことに注意してください。
これらのいずれも問題に対処しない場合は、質問を修正して、例を見つけるのに苦労していることを明確にしてください。これが役立つことを願っています。