代码之家  ›  专栏  ›  技术社区  ›  nonchip Wing

linux上的HIDAPI似乎无法识别描述符

  •  1
  • nonchip Wing  · 技术社区  · 6 年前

    [ 7679.312788] hid-generic 0003:16D0:0E70.0012: hiddev0,hidraw0: USB HID v1.01 Device [.de.nonchip TinyStick HIDSTM1640] on usb-0000:00:13.0-3/input0
    

    实际的HID描述符(我将其放入设备固件,而不是嗅探+解码)如下:

    PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {    /* USB report descriptor */
        0x06, 0x00, 0xff,              // USAGE_PAGE (Generic Desktop)
        0x09, 0x01,                    // USAGE (Vendor Usage 1)
        0xa1, 0x01,                    // COLLECTION (Application)
        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
        0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
        0x75, 0x08,                    //   REPORT_SIZE (8)
        0x95, 0x08,                    //   REPORT_COUNT (8)
        0x09, 0x00,                    //   USAGE (Undefined)  
        0x82, 0x02, 0x01,              //   INPUT (Data,Var,Abs,Buf)
        0x95, 32, //   REPORT_COUNT (32)
        0x09, 0x00,                    //   USAGE (Undefined)        
        0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)
        0xc0                           // END_COLLECTION
    };
    

    字符串描述符定义为:

    #define USB_CFG_VENDOR_NAME     '.','d','e','.','n','o','n','c','h','i','p'
    #define USB_CFG_VENDOR_NAME_LEN 11
    #define USB_CFG_DEVICE_NAME     'T','i','n','y','S','t','i','c','k',' ','H','I','D','S','T','M','1','6','4','0'
    #define USB_CFG_DEVICE_NAME_LEN 20
    

    我正在使用hidapi中的以下代码来(尝试)找到它:

    #define HIDSERIAL_VENDOR_ID 0x16d0
    #define HIDSERIAL_PRODUCT_ID 0x0E70
    #define HIDSERIAL_MANUFACTURER_STRING L".de.nonchip"
    #define HIDSERIAL_PRODUCT_STRING L"TinyStick HIDSTM1640"
    
    hid_device* hidserial_find_device(void){
      hid_device *handle = NULL;
    
      hid_init();
      // Enumerate and print the HID devices on the system
      struct hid_device_info *devs, *cur_dev;
    
      devs = hid_enumerate(HIDSERIAL_VENDOR_ID, HIDSERIAL_PRODUCT_ID);
      cur_dev = devs; 
      while (cur_dev) {
        wprintf(L"%ls %ls\n", cur_dev->manufacturer_string, cur_dev->product_string); // <------ DEBUG
        if( cur_dev->manufacturer_string!=NULL && cur_dev->product_string!=NULL &&
            0==wcscmp(HIDSERIAL_MANUFACTURER_STRING,cur_dev->manufacturer_string) &&
            0==wcscmp(HIDSERIAL_PRODUCT_STRING,cur_dev->product_string)){
          handle = hid_open_path(cur_dev->path);
          break;
        }
        cur_dev = cur_dev->next;
      }
      hid_free_enumeration(devs);
    
      return handle;
    }
    

    我的问题是,虽然内核正确地报告了这个设备,但是没有找到它。调试输出显示 (null) (null) ,这表示设备是由其VID:PID对枚举的,但字符串突然变空。我没有收到任何错误(有人可能会期待类似“权限被拒绝”,但没有任何报告,甚至运行它作为根似乎没有帮助)。。。

    0 回复  |  直到 6 年前