X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fhardware%2Fhp-3457a%2Fapi.c;h=4cfc2d758b54e79625609d408ef0f506d028a5b7;hp=5325224e5e8207e7593b5a0c55765e20866be7e2;hb=69498046f64006a11234b0d281a481338f6f329c;hpb=758906aa711c2936e7e9adcb449f70905087a5d9 diff --git a/src/hardware/hp-3457a/api.c b/src/hardware/hp-3457a/api.c index 5325224e..4cfc2d75 100644 --- a/src/hardware/hp-3457a/api.c +++ b/src/hardware/hp-3457a/api.c @@ -127,6 +127,14 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) struct sr_dev_inst *sdi; struct dev_context *devc; + /* + * The device cannot get identified by means of SCPI queries. + * Neither shall non-SCPI requests get emitted before reliable + * identification of the device. Assume that we only get here + * when user specs led us to believe it's safe to communicate + * to the expected kind of device. + */ + /* * This command ensures we receive an EOI after every response, so that * we don't wait the entire timeout after the response is received. @@ -138,13 +146,15 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) if ((ret != SR_OK) || !response) return NULL; - if (strcmp(response, "HP3457A")) + if (strcmp(response, "HP3457A") != 0) { + g_free(response); return NULL; + } g_free(response); - devc = g_malloc0(sizeof(struct dev_context)); - sdi = g_malloc0(sizeof(struct sr_dev_inst)); + devc = g_malloc0(sizeof(*devc)); + sdi = g_malloc0(sizeof(*sdi)); sdi->vendor = g_strdup("Hewlett-Packard"); sdi->model = g_strdup("3457A"); sdi->version = get_revision(scpi); @@ -168,6 +178,14 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) static GSList *scan(struct sr_dev_driver *di, GSList *options) { + const char *conn; + + /* Only scan for a device when conn= was specified. */ + conn = NULL; + (void)sr_serial_extract_options(options, &conn, NULL); + if (!conn) + return NULL; + return sr_scpi_scan(di->context, options, probe_device); } @@ -359,8 +377,13 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return SR_ERR_ARG; } - devc->current_channel = devc->active_channels->data; devc->num_active_channels = g_slist_length(devc->active_channels); + if (!devc->num_active_channels) { + sr_err("Need at least one active channel!"); + g_slist_free(devc->active_channels); + return SR_ERR_ARG; + } + devc->current_channel = devc->active_channels->data; hp_3457a_select_input(sdi, front_selected ? CONN_FRONT : CONN_REAR);