X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhp-3457a%2Fapi.c;h=4cfc2d758b54e79625609d408ef0f506d028a5b7;hb=713a3f352496f928b9911bfdc7e87a67134113df;hp=23ac98517fbcc94c06744cea82ee45e66cf76714;hpb=e66d1892d0dd16ed166fc8f13493f95de0607362;p=libsigrok.git diff --git a/src/hardware/hp-3457a/api.c b/src/hardware/hp-3457a/api.c index 23ac9851..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); } @@ -243,10 +261,8 @@ static int config_get(uint32_t key, GVariant **data, } static int config_set(uint32_t key, GVariant *data, - const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - int ret; enum sr_mq mq; enum sr_mqflag mq_flags; struct dev_context *devc; @@ -256,7 +272,6 @@ static int config_set(uint32_t key, GVariant *data, devc = sdi->priv; - ret = SR_OK; switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); @@ -266,17 +281,15 @@ static int config_set(uint32_t key, GVariant *data, mq = g_variant_get_uint32(tuple_child); tuple_child = g_variant_get_child_value(data, 1); mq_flags = g_variant_get_uint64(tuple_child); - ret = hp_3457a_set_mq(sdi, mq, mq_flags); g_variant_unref(tuple_child); - break; + return hp_3457a_set_mq(sdi, mq, mq_flags); case SR_CONF_ADC_POWERLINE_CYCLES: - ret = hp_3457a_set_nplc(sdi, g_variant_get_double(data)); - break; + return hp_3457a_set_nplc(sdi, g_variant_get_double(data)); default: - ret = SR_ERR_NA; + return SR_ERR_NA; } - return ret; + return SR_OK; } static int config_list(uint32_t key, GVariant **data, @@ -364,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);