本文介绍了使用open2的libusb为Android(,诠释FD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编的libusb修改后的版本在Android设备被用来从

有没有对如何在C程序中使用此特定功能的例子吗?


  1. 头需要什么列入为了使这个图书馆工作。

  2. 在如何在C程序中使用open2(,INT FD)的任何实例


解决方案

这是没有新的图书馆。只有一个修改版本的libusb的。因此,所有的libusb的命令适用在这里。唯一的区别是libusb_open2,你将不得不libusb_open代替使用。从的libusb / libusb.h文件,libusb_open2的原型是可见的。

  INT LIBUSB_CALL libusb_open2(libusb_device *开发,libusb_device_handle **手柄,INT FD);

现在,使用的libusb在Android上,步骤会。


  1. 首先获得权限USB设备,您有兴趣的细节这里给出:的


  2. 然后,使用该方法提取的USB设备的文件描述符 getFileDescriptor()


  3. 使用此文件描述符开放连接USB设备。这是做一个libusb_device。


现在你可以使用这个libusb_device做一切可以使用计算机上的libusb要做的东西。有很多在给出的例子。

有关其他查询可以发起Hangouts谈谈freenode上#libusb。
对于具体的实例,通过文档。自己尝试一下。如果卡住的地方问在这里。难道没有想到spoonfeeding。

I compiled the modified version of libusb to be used in Android devices from

https://github.com/martinmarinov/rtl_tcp_andro-/blob/master/jni/libusb-andro/README

Is there any example on how to use this particular function in a C program?

  1. What headers need to be included in order for this library to work.
  2. Any examples on how to use open2(, int fd) in a C program
解决方案

This is no new library. Only a modified version of libusb. So, all the libusb commands are applicable here. The only difference would be libusb_open2 which you would have to use in stead of libusb_open. From the libusb/libusb.h file, the prototype of libusb_open2 is visible.

int LIBUSB_CALL libusb_open2(libusb_device *dev, libusb_device_handle **handle, int fd);

Now, for using libusb on android, the steps would be.

  1. First get permissions for the USB device you are interested in. The details are given here : http://developer.android.com/guide/topics/connectivity/usb/host.html

  2. Then extract the file descriptor of the USB device using the method getFileDescriptor()

  3. Use this file descriptor open connection to the usb device. That is make a libusb_device.

Now you can use this libusb_device to do all the stuff that can be done on computer using libusb. There are plenty of examples given on the libusb website.

For other queries you can hangout on #libusb on freenode.For specific examples, go through the documentation. Try on your own. And if stuck somewhere ask here. Do no expect spoonfeeding.

这篇关于使用open2的libusb为Android(,诠释FD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 01:52