]> sigrok.org Git - libsigrok.git/commitdiff
scpi_usbtmc_libusb: set_configuration only if it is not already set
authorAurelien Jacobs <redacted>
Thu, 24 Sep 2015 19:43:06 +0000 (21:43 +0200)
committerUwe Hermann <redacted>
Sat, 24 Oct 2015 19:32:13 +0000 (21:32 +0200)
This avoids the issues described here:
http://libusb.sourceforge.net/api-1.0/caveats.html#configsel

src/scpi/scpi_usbtmc_libusb.c

index 0b14cb3f89da912e8eecf039cc83c62384f79ce9..d7b7ef999b08bf9c3d2fbd558eb80a047f51141d 100644 (file)
@@ -299,7 +299,7 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi)
        struct libusb_config_descriptor *confdes;
        const struct libusb_interface_descriptor *intfdes;
        const struct libusb_endpoint_descriptor *ep;
-       int confidx, intfidx, epidx, config = 0;
+       int confidx, intfidx, epidx, config = 0, current_config;
        uint8_t capabilities[24];
        int ret, found = 0;
 
@@ -367,10 +367,13 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi)
                uscpi->detached_kernel_driver = 1;
        }
 
-       if ((ret = libusb_set_configuration(usb->devhdl, config)) < 0) {
-               sr_err("Failed to set configuration: %s.",
-                      libusb_error_name(ret));
-               return SR_ERR;
+       if (libusb_get_configuration(usb->devhdl, &current_config) == 0
+           && current_config != config) {
+               if ((ret = libusb_set_configuration(usb->devhdl, config)) < 0) {
+                       sr_err("Failed to set configuration: %s.",
+                              libusb_error_name(ret));
+                       return SR_ERR;
+               }
        }
 
        if ((ret = libusb_claim_interface(usb->devhdl, uscpi->interface)) < 0) {