X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fscpi%2Fscpi_usbtmc_libusb.c;h=2da67030ed2495c41e9a0c3dcd56f9255d72f201;hb=dedaeacad0ef889506b79a8bed634140da28aa72;hp=a109703ea0318d81d43877cc2fa1364a625b1cab;hpb=7a970e3170a94b6cb8f6f92647552643dd20dc9a;p=libsigrok.git diff --git a/src/scpi/scpi_usbtmc_libusb.c b/src/scpi/scpi_usbtmc_libusb.c index a109703e..2da67030 100644 --- a/src/scpi/scpi_usbtmc_libusb.c +++ b/src/scpi/scpi_usbtmc_libusb.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include "libsigrok-internal.h" @@ -105,6 +106,8 @@ struct usbtmc_blacklist { static struct usbtmc_blacklist blacklist_remote[] = { { 0x1ab1, 0x0588 }, /* Rigol DS1000 series */ { 0x1ab1, 0x04b0 }, /* Rigol DS2000 series */ + { 0x1ab1, 0x04b1 }, /* Rigol DS4000 series */ + { 0x1ab1, 0x0515 }, /* Rigol MSO5000 series */ { 0x0957, 0x0588 }, /* Agilent DSO1000 series (rebadged Rigol DS1000) */ { 0x0b21, 0xffff }, /* All Yokogawa devices */ { 0xf4ec, 0xffff }, /* All Siglent SDS devices */ @@ -138,8 +141,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++) { @@ -310,8 +314,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++) { @@ -410,6 +415,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) @@ -507,14 +524,36 @@ static int scpi_usbtmc_bulkin_start(struct scpi_usbtmc_libusb *uscpi, uint8_t *transfer_attributes) { struct sr_usb_dev_inst *usb = uscpi->usb; - int ret, transferred, message_size; + int ret, transferred, message_size, tries; + + for (tries = 0; ; tries++) { + ret = libusb_bulk_transfer(usb->devhdl, uscpi->bulk_in_ep, data, + size, &transferred, + TRANSFER_TIMEOUT); + if (ret < 0) { + sr_err("USBTMC bulk in transfer error: %s.", + libusb_error_name(ret)); + return SR_ERR; + } - ret = libusb_bulk_transfer(usb->devhdl, uscpi->bulk_in_ep, data, size, - &transferred, TRANSFER_TIMEOUT); - if (ret < 0) { - sr_err("USBTMC bulk in transfer error: %s.", - libusb_error_name(ret)); - return SR_ERR; + if (transferred == 0 && tries < 1) { + /* + * The DEV_DEP_MSG_IN message is empty, and the TMC + * spec says it should at least contain a header. + * The Rigol DS1054Z seems to do this sometimes, and + * it follows up with a valid message. Give the device + * one more chance to send a header. + */ + sr_warn("USBTMC bulk in start was empty; retrying\n"); + continue; + } + + if (transferred < USBTMC_BULK_HEADER_SIZE) { + sr_err("USBTMC bulk in returned too little data: %d/%d bytes\n", transferred, size); + return SR_ERR; + } + + break; } if (usbtmc_bulk_in_header_read(data, msg_id, uscpi->bTag, &message_size, @@ -654,10 +693,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,