Вывод lsusb -v -d (VID,PID)
user
$ lsusb -v -d 16c0:05df
Bus 002 Device 115: ID 16c0:05df VOTI
Couldn't open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x16c0 VOTI
idProduct 0x05df
bcdDevice 1.00
iManufacturer 1
iProduct 2
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 34
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.01
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 22
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 100
Код, которым пытаюсь заставить его работать
Код:
#include <libusb-1.0/libusb.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#define DEV_VID 0x16c0 //0x5824
#define DEV_PID 0x05df //0x1503
#define DEV_CONFIG 1
#define DEV_INTF 0
int main(int argc, char * argv[]){
libusb_device_handle * handle;
int i, ret;
unsigned int level;
unsigned char command[1], buf[8], channel;
char param;
libusb_init(NULL);
libusb_set_debug(NULL, 3);
handle = libusb_open_device_with_vid_pid(NULL, DEV_VID, DEV_PID);
if (handle == NULL) {
printf("Не удалось найти устройство\n"); libusb_exit(NULL); return 0;
}
if (libusb_kernel_driver_active(handle,DEV_INTF))
libusb_detach_kernel_driver(handle, DEV_INTF);
if ((ret = libusb_set_configuration(handle, DEV_CONFIG)) < 0){
printf("Ошибка конфигурации\n"); libusb_close(handle); libusb_exit(NULL); return 0;
}
if (libusb_claim_interface(handle, DEV_INTF) < 0){
printf("Ошибка интерфейса\n"); libusb_close(handle); libusb_exit(NULL); return 0;
}
int tr;
unsigned char data[10];
data[0]=0x0D;
data[1]=0x0D;
ret = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT, 0x9, 0x300, 0, data, 2, 500);
printf("received %i bytes\n",ret);
ret=libusb_interrupt_transfer(handle,0x81/*EP_1_IN*/,data,2/*len*/,&tr,1000);
printf("ret=%i\ndata[0]=0x%x\ndata[1]=0x%x\n",ret,data[0],data[1]);
libusb_release_interface(handle,0);
libusb_attach_kernel_driver(handle, DEV_INTF);
libusb_close(handle);
libusb_exit(NULL);
return 0;
}
root
# gcc -o prog test.c -lusb-1.0 && ./prog
received 2 bytes
ret=-7
data[0]=0xd
data[1]=0xd
От рута, поскольку libusb этого требует. Сколько я понимаю, возвращаемое значение -7 означает TIMEOUT, доступное время на это не влияет (до 10 сек по крайней мере), данные 0xd это ранее записанное, должно было вернуть 0x0.