title: Issue retrieving serial number of USB devices on Mac OS X
body: <p>I'm working with libusb 0.1 and <a href="https://en.wikipedia.org/wiki/Qt_%28software%29" rel="nofollow">Qt</a> in a <a href="https://en.wikipedia.org/wiki/OS_X_Yosemite" rel="nofollow">Mac&nbsp;OS&nbsp;X v10.10</a> (Yosemite) environment. My goal is to get the serial numbers of all connected USB keys (usbclass = 8).</p>
  
  <p>Usually the first reading occur properly, and I cannot understand why, but sometimes from subsequent readings, the device is no longer detected. Sometimes I get -60 error code on the <code>usb_get_string_simple(handle, device-&gt;descriptor.iSerialNumber)</code> function. How can I fix this problem?</p>
  
  <p>I've tried USB keys with FAT, FAT32 and NTFS file systems, but they all had the same issue.</p>
  
  <p>In the same project, I use libusb to read/write with printer devices connected to the Mac, and read serialnumbers too. No issue with this type of devices. So strange.</p>
  
  <p>In the .pro file:</p>
  
  <pre><code>INCLUDEPATH +=   /Users/sborfedor/Desktop/root/current/includes
  DEPENDPATH  +=   /Users/sborfedor/Desktop/root/current/includes
  LIBS        += -L/Users/sborfedor/Desktop/root/current/bin_osx/libs/ -lusb-legacy
  DESTDIR     =    /Users/sborfedor/Desktop/root/current/bin_osx
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>void MainWindow::run() {
      struct usb_bus* bus = NULL;
      struct usb_device* device = NULL;
      const int MASSSTORAGE_CLASS = 8;
      usb_init();
      usb_set_debug(3);
      usb_find_busses();
      usb_find_devices();
      int ret;
      for ( bus = usb_get_busses(); bus; bus = bus-&gt;next ) {
          for ( device = bus-&gt;devices; device; device = device-&gt;next )  {
              if (device-&gt;descriptor.bDeviceClass != MASSSTORAGE_CLASS &amp;&amp; device-&gt;descriptor.bDeviceClass != 0) {
                  continue;
              }
              for ( int cid = 0; cid &lt; device-&gt;descriptor.bNumConfigurations; ++cid ) {
                  struct usb_config_descriptor* config = &amp;( device-&gt;config[cid] );
                  if (config == NULL)
                      continue;
                  for ( int iid = 0; iid &lt; config-&gt;bNumInterfaces; ++iid ) {
                      struct usb_interface* interface = &amp;( config-&gt;interface[iid] );
                      if (interface == NULL)
                          continue;
                      usb_dev_handle* handle = usb_open( device );
                      if (handle == NULL)
                          continue;
                      for ( int sid = 0; sid &lt; interface-&gt;num_altsetting; sid++ ) {
                          struct usb_interface_descriptor* settings = &amp;( interface-&gt;altsetting[sid] );
                          if (settings == NULL)
                              continue;
                          int usbClass = device-&gt;descriptor.bDeviceClass;
                          if (usbClass == 0) {
                              usbClass = settings-&gt;bInterfaceClass;
                          }
                          if (usbClass != MASSSTORAGE_CLASS)
                              continue;
                          char device_serial_number[255];
                          ret = usb_get_string_simple( handle, device-&gt;descriptor.iSerialNumber, device_serial_number, sizeof(device_serial_number) );
                          if (ret &gt; 0 ) {
                              qDebug() &lt;&lt; "SERIAL_NUMBER="&lt;&lt;QString(device_serial_number);
                          } else {
                              qDebug() &lt;&lt; "*** usb_get_string_simple( handle, device-&gt;descriptor.iSerialNumber, device_serial_number, USBX_DEVICE_SERIAL_NUMBER_MAX_SIZE ) RET="&lt;&lt;ret;
                          }
                      }
                      usb_close( handle );
                  }
              }
          }
      }
  }
  </code></pre>