2017-02-07 2 views
0
#include <windows.h> 
#include <devguid.h> 
#include <initguid.h> 
#include <wtypes.h> 
#include <WinBase.h> 
#include <stdio.h> 
#include "libusb.h" 
#include "resource.h" 

int main(int argc, char *argv[]) { 

    libusb_device *dev; 
    int i = 0, j = 0; 
    libusb_device **devs; 
    int r; 
    ssize_t cnt; 
    USHORT VendorID = 0x04b4; 
    USHORT ProductID = 0x00f3; 
    libusb_device_handle * DeviceHandle; 

    AllocConsole(); 

    r = libusb_init(NULL); 
    if (r < 0) 
     return r; 

    cnt = libusb_get_device_list(NULL, &devs); 
    if (cnt < 0) 
     return (int)cnt; 

    while ((dev = devs[i++]) != NULL) { 
     struct libusb_device_descriptor desc; 
     int r = libusb_get_device_descriptor(dev, &desc); 
     if (r < 0) { 
      fprintf(stderr, "failed to get device descriptor"); 
      return 1; 
     } 
     if (desc.idVendor == VendorID && 
      desc.idProduct == ProductID){ 

      int err = libusb_open(dev, 
       &DeviceHandle); 
      if (err < 0){ 
       printf("GetLastError : %d\n", GetLastError()); 
       return 1; 
       } 
      libusb_free_device_list(devs, 1); 

      libusb_close(DeviceHandle); 
     } 
    } 
    return 0; 
} 

Вот мой код. Проблема в том, что я не могу получить дескриптор устройства. & DeviceHandle всего лишь 0, и последняя ошибка не дает мне ничего. Если это важно, я пытаюсь взять кипарис в fx3. Он компилируется и отлично работает, пока я не перейду к этому вопросу. Любые мысли об этой проблеме приветствуются.libusb не может получить ручку устройства

+0

Что вы получаете в 'err'? –

+0

@ GOTO -12 в ERR – andrius

+1

Вот 'LIBUSB_ERROR_NOT_SUPPORTED \t Операция не поддерживается или невыполненными на этом platform.' http://libusb.sourceforge.net/api-1.0/group__misc.html#ggab2323aa0f04bc22038e7e1740b2f29efa01b43115484f435627be755d5dc9509b –

ответ

1

Ваш звонок libusb_open(dev, &DeviceHandle); возвращает LIBUSB_ERROR_NOT_SUPPORTED.

This post предполагает, что у вас может отсутствовать водитель winusb.