libusb1.0 库 函数libusb_control_transfer 调用失败

cindyzzzzzzzzzz 2018-01-26 07:42:24
在调用libusb库时候 ,打开设备是成功的状态下,函数 libusb_control_transfer 往USB设备写入数据时候失败,下面是libusb_set_debug输出的部分信息。

unsigned char tmp[3] = {0xa0, 0x81, 0x01};
int ret = libusb_control_transfer(dev_handle, (uint8_t)0x21,
(uint8_t)0x09, /* set/get test */
(uint16_t)0x02ba, /* test type */
(uint16_t)0, /* interface id */
tmp, (uint16_t)3, (unsigned int)1000);
ret 返回-1 写入失败
USB设备数据传输协议 部分如下,
Set Report
Setup packet[0] = 0x21;
Setup packet[1] = 0x09;
Setup packet[2] = 0xba;
Setup packet[3] = 0x02;
Setup packet[4] = 0x00;
Setup packet[5] = 0x00;
Setup packet[6] = DATA LEN;
Setup packet[7] = 0x00;

libusb_set_debug 调试信息:
[ 0.523030] [00000ba4] libusb: debug [_hid_set_report] report ID: 0xBA
[ 0.523030] [00000ba4] libusb: warning [_hid_set_report] mismatched report ID (data is A0, parameter is BA)
[ 0.523030] [00000ba4] libusb: debug [_hid_set_report] Failed to Write HID Output Report: [1] 函数不正确。
[ 0.523030] [00000ba4] libusb: debug [composite_submit_control_transfer] trying to skip restricted interface #0 (HID keyboard or mouse?)
[ 0.523030] [00000ba4] libusb: debug [composite_submit_control_transfer] trying to skip restricted interface #1 (HID keyboard or mouse?)




win32的部分 也是相同参数 写入是OK的 求大牛指教 libusb_control_transfer的参数 是否填写有误?
char tmp[3] = {0xa0, 0x81, 0x01};
int ret = usb_control_msg(dev, 0x21,
0x09, /* set/get test */
0x02ba, /* test type */
0, /* interface id */
tmp, 3, 1000);

...全文
3879 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
全才欧巴 2018-08-30
  • 打赏
  • 举报
回复
value的高8位写report type,低8位写report id,你看看你有没有写对。
全才欧巴 2018-08-30
  • 打赏
  • 举报
回复
我来回答你吧。
libusb的这个函数test type那里是2个字节,高8位要填report_type,低8位填report ID。
你看看源码中_hid_class_request函数就明白了。这个与bus hound和usb_control_msg要求的不一样。

21,595

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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