Android的USB主机:异步中断传输 [英] Android usb host: asynchronous interrupt transfer

查看:2107
本文介绍了Android的USB主机:异步中断传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接一个USB设备(打造我自己)与我的开发板进行通信(ODROID-X) 不幸的是,这些例子非常少,至于异步通信。我倒是一些问题中断驱动的数据交换 - 如何建立使用异步中断模式的连接? 在一个方向上,传输是可能...但在这两种它不起作用。是否有这样一个例子:

I'm trying to connect a USB-Device ( build by myself ) to communicate with my development board ( ODROID-X ) Unfortunately, the examples are very little, as far as the asynchronous communication. I'd some problems with the interrupt driven data exchange - how to build the connection by using the asynchronous interrupt mode? In one direction, the transmission was possible ... but in both it doesn't work. Is there an example like this:

  • 发送的ByteBuffer与endpoint_OUT
  • 在得到消息德维克在endpoint_IN

无论是在中断模式。

非常感谢您的支持!

推荐答案

也许我在这里误解的问题。 样本导弹lanucher应用程序,从12级API包的一部分开始使用队列() requestWait()方法来处理中断类型的端点。 请求要么或缩小,取决于端点的方向。

Perhaps I am misunderstanding the question here. The sample missile lanucher app that is part of the API package from level 12 onwards uses the queue() and requestWait() methods to handle interrupt type endpoints. Requests are either In or Out and depend on the direction of the EndPoint.

在code为pretty的诺迪请求 - >应答看起来是这样的。你会希望以不同的结构现实code,但是这给你需要做些什么(我希望)

The code for a pretty noddy request->reply looks something like this. You would want to structure real code differently but this gives you the gist of what needs to happen (I hope)

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()方法返回一个标准的文件句柄,这在理论上就可以使用,就好像它是任何其他文件类型的资源。但是我要指出,我没有尝试过这一点。

If you are actually looking for a way to run this IO in an asynchronous manner without binding a thread to it, then I think you need to consider using the DeviceConnection.getFilehandle() method to return a standard file handle which in theory you can then use as if it were any other file type resource. I would note however that I have not tried this.

如果没有这些地址的问题,请修改的问题,以澄清你都在努力寻找的例子。 我希望这有助于。

If neither of these addresses the issue please revise the question to clarify what you are struggling to find examples of. I hope this helps.

这篇关于Android的USB主机:异步中断传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆