libusb读取hid输入设备usb_interrupt_read问题!

zfviwx 2009-10-19 10:34:35
很简单的问题~嵌入式linux~用libusb~接上usb键盘~成功打开device声明interface读到相关设备信息~

不知道usb_interrupt_read如何使用?

while(1)
{
r=usb_interrupt_read(fdev,0x81,string,4,0);
for (x=0;x<4 && r>0;x++)
printf("%d," ,string[x]);
printf("\n");
}

r永远是0,string永远是0,0,0,0,无论如何按键~

奇怪的是~如果加上"usb_clear_halt(fdev,0x81);"的话,string[2]中得到键盘按键值,其余三个是0,但是r也是0,这个是为什么呢?但是加上这句的话,就无法判断按键是否被一直按住了。
...全文
1364 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zfviwx 2009-10-21
  • 打赏
  • 举报
回复
哦也!!成功了~原来是读取size的问题~把4改成8就行了~不知道为什么~~不过试了一个罗技的键盘~4就没问题~可能是我这个输入设备比较特别吧~
zfviwx 2009-10-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 steptodream 的回复:]
引用 4 楼 zfviwx 的回复:
usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout)里面timeout那个参数怎么用的?是不是跟它有关系呢?

你可以对timeout设置不同的值来试试呀
[/Quote]

试过了~没变化~没有找到libusb v0.1里面timeout的解释~在v1.0以后的版本里~timeout等于0就是无限~应该和这个参数没关系
steptodream 2009-10-21
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zfviwx 的回复:]
usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout)里面timeout那个参数怎么用的?是不是跟它有关系呢?
[/Quote]
你可以对timeout设置不同的值来试试呀
steptodream 2009-10-20
  • 打赏
  • 举报
回复
没搞过嵌入式 但是程序估计有问题吧 楼主在好好考虑下
zfviwx 2009-10-20
  • 打赏
  • 举报
回复
usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout)里面timeout那个参数怎么用的?是不是跟它有关系呢?
steptodream 2009-10-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zfviwx 的回复:]
引用 1 楼 steptodream 的回复:
没搞过嵌入式 但是程序估计有问题吧  楼主在好好考虑下


嵌入式和桌面linux对于libusb用法应该一样吧?我按照http://www.hasanen.com/?p=6上面写~也不行~
[/Quote]
他那个代码应该没错吧 看你贴的那个代码也没错呀
zfviwx 2009-10-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 steptodream 的回复:]
没搞过嵌入式 但是程序估计有问题吧  楼主在好好考虑下
[/Quote]

嵌入式和桌面linux对于libusb用法应该一样吧?我按照http://www.hasanen.com/?p=6上面写~也不行~

23,223

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧