如何使用libusb库获取usb海量存储大小?

时间:2015-12-29 11:32:25

标签: libusb libusb-1.0

我使用libusb库找到usb大容量存储相关信息。 但是不知道如何获得usb大容量存储空间?

我的试用版是:

void printdev(libusb_device *dev);
int main() 

{

    libusb_device **devs;

    libusb_context *ctx = NULL; //a libusb session

    int r; 

    ssize_t cnt; //holding number of devices in list

    r = libusb_init(&ctx); //initialize a library session

    if(r < 0)
    {

        cout<<"Init Error "<<r<<endl; //there was an error

        return 1;

    }

    libusb_set_debug(ctx, 3); //set verbosity level to 3, as suggested in the documentation

    cnt = libusb_get_device_list(ctx, &devs); //get the list of devices

    if(cnt < 0)
    {

        cout<<"Get Device Error"<<endl; //there was an error

    }

    cout<<cnt<<" Devices in list."<<endl; //print total number of usb devices

    int i;

    for(i = 0; i < cnt; i++)
    {

        printdev(devs[i]);

    }

    libusb_free_device_list(devs, 1); //free the list, unref the devices in it

    libusb_exit(ctx); //close the session

    return 0;

}


void printdev(libusb_device *dev)
{

    libusb_device_descriptor desc;
    libusb_config_descriptor *conDesc;
    char szBuffer[256] = {0};
    unsigned char strDesc[256];
    libusb_device_handle *devHandle = NULL;
    int retVal;
    __int64 i64Temp;
    DWORD dwProdId;
    DWORD dwProdId1;

    i64Temp = 13888;
    dwProdId = (DWORD)i64Temp;


    retVal = libusb_open (dev, &devHandle);
    if (retVal != LIBUSB_SUCCESS)
    return;

    int r = libusb_get_device_descriptor(dev, &desc);

    if (r < 0)
    {

        cout<<"failed to get device descriptor"<<endl;

        return;

    }

    r = libusb_get_config_descriptor(dev, 0, &conDesc);
    printf("Interface Class = %d\n", conDesc->interface->altsetting->bInterfaceClass);

    cout<<"Number of possible configurations: "<<(int)desc.bNumConfigurations<<"  ";

//  cout<<"Device Class: "<<desc.bDeviceClass<<endl;
//  cout<<"Device Class: "<<desc.bDeviceSubClass<<endl;



    printf("Class = %d\n", desc.bDeviceClass);
    cout<<"VendorID: "<<desc.idVendor<<endl;


    cout<<"ProductID: "<<desc.idProduct<<endl;

    dwProdId1 = (DWORD)desc.idProduct;
    if (dwProdId1 == dwProdId)
    {
        printf("in if\n");
    }
    else
    {
        printf("in else\n");
    }
        retVal = libusb_get_string_descriptor_ascii(devHandle, desc.iManufacturer, strDesc, 256);

        printf ("Manufacturer:  %s\n",  strDesc);

    retVal = libusb_get_string_descriptor_ascii(devHandle, desc.iSerialNumber, strDesc, 256);
    printf ("SerialNumber:  %s\n",  strDesc);

    retVal = libusb_get_string_descriptor_ascii(devHandle, desc.iProduct, strDesc, 256);
    printf ("Product:  %s\n",  strDesc);

    printf("\n\n");
 }

0 个答案:

没有答案