]> sigrok.org Git - libsigrok.git/blobdiff - src/scpi/scpi_usbtmc_libusb.c
scpi-pps: Seperate existing HP 66xxA and 66xxB profiles.
[libsigrok.git] / src / scpi / scpi_usbtmc_libusb.c
index decafdb62af3c44b0635853d751694d0fb29eef8..d09b35ffb42b165bd12880e123cf0aba42221f00 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <config.h>
+#include <inttypes.h>
 #include <string.h>
 #include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
@@ -105,8 +106,16 @@ struct usbtmc_blacklist {
 static struct usbtmc_blacklist blacklist_remote[] = {
        { 0x1ab1, 0x0588 }, /* Rigol DS1000 series */
        { 0x1ab1, 0x04b0 }, /* Rigol DS2000 series */
+       { 0x1ab1, 0x04b1 }, /* Rigol DS4000 series */
        { 0x0957, 0x0588 }, /* Agilent DSO1000 series (rebadged Rigol DS1000) */
        { 0x0b21, 0xffff }, /* All Yokogawa devices */
+       { 0xf4ec, 0xffff }, /* All Siglent SDS devices */
+       ALL_ZERO
+};
+
+/* Devices that shall get reset during open(). */
+static struct usbtmc_blacklist whitelist_usb_reset[] = {
+       { 0xf4ec, 0xffff }, /* All Siglent SDS devices */
        ALL_ZERO
 };
 
@@ -131,8 +140,9 @@ static GSList *scpi_usbtmc_libusb_scan(struct drv_context *drvc)
 
                for (confidx = 0; confidx < des.bNumConfigurations; confidx++) {
                        if ((ret = libusb_get_config_descriptor(devlist[i], confidx, &confdes)) < 0) {
-                               sr_dbg("Failed to get configuration descriptor: %s, "
-                                      "ignoring device.", libusb_error_name(ret));
+                               if (ret != LIBUSB_ERROR_NOT_FOUND)
+                                       sr_dbg("Failed to get configuration descriptor: %s, "
+                                              "ignoring device.", libusb_error_name(ret));
                                break;
                        }
                        for (intfidx = 0; intfidx < confdes->bNumInterfaces; intfidx++) {
@@ -155,7 +165,7 @@ static GSList *scpi_usbtmc_libusb_scan(struct drv_context *drvc)
        }
        libusb_free_device_list(devlist, 1);
 
-       sr_dbg("Found %d device(s).", g_slist_length(resources));
+       /* No log message for #devices found (caller will log that). */
 
        return resources;
 }
@@ -290,6 +300,7 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi)
        int confidx, intfidx, epidx, config = 0, current_config;
        uint8_t capabilities[24];
        int ret, found = 0;
+       int do_reset;
 
        if (usb->devhdl)
                return SR_OK;
@@ -302,8 +313,9 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi)
 
        for (confidx = 0; confidx < des.bNumConfigurations; confidx++) {
                if ((ret = libusb_get_config_descriptor(dev, confidx, &confdes)) < 0) {
-                       sr_dbg("Failed to get configuration descriptor: %s, "
-                              "ignoring device.", libusb_error_name(ret));
+                       if (ret != LIBUSB_ERROR_NOT_FOUND)
+                               sr_dbg("Failed to get configuration descriptor: %s, "
+                                      "ignoring device.", libusb_error_name(ret));
                        continue;
                }
                for (intfidx = 0; intfidx < confdes->bNumInterfaces; intfidx++) {
@@ -370,6 +382,12 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi)
                return SR_ERR;
        }
 
+       /* Optionally reset the USB device. */
+       do_reset = check_usbtmc_blacklist(whitelist_usb_reset,
+               des.idVendor, des.idProduct);
+       if (do_reset)
+               libusb_reset_device(usb->devhdl);
+
        /* Get capabilities. */
        ret = libusb_control_transfer(usb->devhdl, LIBUSB_ENDPOINT_IN |
                LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
@@ -396,6 +414,18 @@ static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi)
        return SR_OK;
 }
 
+static int scpi_usbtmc_libusb_connection_id(struct sr_scpi_dev_inst *scpi,
+               char **connection_id)
+{
+       struct scpi_usbtmc_libusb *uscpi = scpi->priv;
+       struct sr_usb_dev_inst *usb = uscpi->usb;
+
+       *connection_id = g_strdup_printf("%s/%" PRIu8 ".%" PRIu8 "",
+               scpi->prefix, usb->bus, usb->address);
+
+       return SR_OK;
+}
+
 static int scpi_usbtmc_libusb_source_add(struct sr_session *session,
                void *priv, int events, int timeout, sr_receive_data_callback cb,
                void *cb_data)
@@ -617,7 +647,7 @@ static int scpi_usbtmc_libusb_close(struct sr_scpi_dev_inst *scpi)
        if ((ret = libusb_release_interface(usb->devhdl, uscpi->interface)) < 0)
                sr_err("Failed to release interface: %s.",
                       libusb_error_name(ret));
-       
+
        if (uscpi->detached_kernel_driver) {
                if ((ret = libusb_attach_kernel_driver(usb->devhdl,
                                                uscpi->interface)) < 0)
@@ -640,10 +670,12 @@ static void scpi_usbtmc_libusb_free(void *priv)
 SR_PRIV const struct sr_scpi_dev_inst scpi_usbtmc_libusb_dev = {
        .name          = "USBTMC",
        .prefix        = "usbtmc",
+       .transport     = SCPI_TRANSPORT_USBTMC,
        .priv_size     = sizeof(struct scpi_usbtmc_libusb),
        .scan          = scpi_usbtmc_libusb_scan,
        .dev_inst_new  = scpi_usbtmc_libusb_dev_inst_new,
        .open          = scpi_usbtmc_libusb_open,
+       .connection_id = scpi_usbtmc_libusb_connection_id,
        .source_add    = scpi_usbtmc_libusb_source_add,
        .source_remove = scpi_usbtmc_libusb_source_remove,
        .send          = scpi_usbtmc_libusb_send,