Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9268403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:48:15+00:00 2026-06-18T14:48:15+00:00

I’m learning to use libusb v1.0.0 for the first time on Ubuntu 12.10. Here

  • 0

I’m learning to use libusb v1.0.0 for the first time on Ubuntu 12.10. Here is some small test code I’m using to try and understand how to use this API:

#include <libusb-1.0/libusb.h>
...
libusb_device **list;
libusb_get_device_list(ctx, &list); // Returns 11 USB devices which is correct.
for (size_t idx = 0; list[idx] != NULL; idx ++)
{
    libusb_device *dev = list[idx];
    libusb_device_descriptor desc = {0};
    int rc = libusb_get_device_descriptor(dev, &desc);

At this point, rc == 0, meaning it should have completed successfully. Source: documentation for *libusb_get_device_descriptor()*.

But the structure desc is always empty. None of the fields ever get set. If I change the last two lines above to this:

    libusb_device_descriptor desc = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int rc = libusb_get_device_descriptor(dev, &desc);

…then when libusb_get_device_descriptor() returns, I see desc remains unchanged, confirming for me that I’m not getting what I expect from this API.

I’ve also tried to run a.out as root just in case this requires elevated privileges. Doing a Google search on libusb_get_device_descriptor hasn’t gotten me anywhere.

Relevant commands I ran to try this code:

sudo apt-get install libusb-1.0.0-dev
g++ -ggdb test.cpp -lusb-1.0
./a.out 

Ah! Crazy user error! sharth’s code helped me figure it out. Here is the code I was actually using — see if you can spot the error:

std::cout << "rc == " << libusb_get_device_descriptor(dev, &desc) << std::endl
          << "vendor == " << desc.idVendor << std::endl;

I guess the way the compiler evaluates this, it is free to evaluate desc.idVendor before the call to libusb_get_device_descriptor() has actually been made. My bad.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:48:17+00:00Added an answer on June 18, 2026 at 2:48 pm

    You didn’t include a full, compilable test case. So I built one. This works for me on CentOS 6 x64. I’m also running this as a normal user account.

    Source

    #include <cassert>
    #include <cstdio>
    #include <libusb-1.0/libusb.h>
    
    int main() {
        libusb_context *context = NULL;
        libusb_device **list = NULL;
        int rc = 0;
        ssize_t count = 0;
    
        rc = libusb_init(&context);
        assert(rc == 0);
    
        count = libusb_get_device_list(context, &list);
        assert(count > 0);
    
        for (size_t idx = 0; idx < count; ++idx) {
            libusb_device *device = list[idx];
            libusb_device_descriptor desc = {0};
    
            rc = libusb_get_device_descriptor(device, &desc);
            assert(rc == 0);
    
            printf("Vendor:Device = %04x:%04x\n", desc.idVendor, desc.idProduct);
        }
    
        libusb_free_device_list(list, 1);
        libusb_exit(context);
    }
    

    Output

    Vendor:Device = 1d6b:0002
    Vendor:Device = 1d6b:0002
    Vendor:Device = 8087:0020
    Vendor:Device = 8087:0020
    Vendor:Device = 0424:2514
    Vendor:Device = 10c4:ea60
    Vendor:Device = 051d:0002
    Vendor:Device = 0624:0248
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I'm using an ASP request returning a XML file containing some latin characters. By
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am confused How to use looping for Json response Array in another Array.
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.