我的问题是libusb不会传输批量来读取键盘输入。这是代码:
#include <stdio.h>
#include <libusb-1.0/libusb.h>
int main(void)
{
libusb_init(NULL);
libusb_device **list;
libusb_device *found = NULL;
ssize_t cnt = libusb_get_device_list(NULL, &list);
ssize_t i = 0;
struct libusb_device_descriptor desc;
libusb_device_handle *h;
unsigned char strDesc[128];
for (i = 0; i < cnt; i++) {
libusb_device *device = list[i];
libusb_get_device_descriptor(device, &desc);
if (desc.idProduct == 0x203) {
libusb_open(device, &h);
libusb_get_string_descriptor_ascii(h, desc.iProduct, strDesc, 128);
printf("=== %s found in host ===\n", strDesc);
found = device;
break;
}
}
libusb_device_handle *handle;
libusb_open(found, &handle);
unsigned char data[16];
int act_len;
libusb_get_device_descriptor(found, &desc);
int r = libusb_bulk_transfer(handle, LIBUSB_ENDPOINT_IN, data, sizeof(data), &act_len, 0);
const char *err = libusb_error_name(r);
printf("%s\n", err);
libusb_free_device_list(list, 1);
libusb_close(handle);
return 0;
}
基本上它遍历所有列出的设备,直到找到我的键盘,pId为0x203。然后它尝试启动libusb_bulk_transfer()
,但在执行时它会抛出LIBUSB_ERROR_NOT_FOUND
。
有人可以帮我解决这个问题吗?我搜索过,但似乎没有人有解决方案。谢谢!
我正在运行OS X 10.10.1。