From: Martin Ling Date: Sat, 24 Oct 2015 21:27:45 +0000 (+0100) Subject: scpi: Move closing of discovered devices to sr_scpi_scan_resource(). X-Git-Tag: libsigrok-0.4.0~184 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a00106b7f819a2e64a65cfe767edae93bf2fb403;p=libsigrok.git scpi: Move closing of discovered devices to sr_scpi_scan_resource(). --- diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index 4f384aa2..cfec15ee 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -57,7 +57,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) } sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_ACTIVE; sdi->vendor = g_strdup(hw_info->manufacturer); sdi->model = g_strdup(hw_info->model); sdi->version = g_strdup(hw_info->firmware_version); diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 7a2d91c7..415f945b 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -81,7 +81,6 @@ static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi goto fail; sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_ACTIVE; sdi->vendor = g_strdup(hw_info->manufacturer); sdi->model = g_strdup(hw_info->model); sdi->version = g_strdup(hw_info->firmware_version); @@ -100,10 +99,6 @@ static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi if (hmo_init_device(sdi) != SR_OK) goto fail; - sr_scpi_close(sdi->conn); - - sdi->status = SR_ST_INACTIVE; - return sdi; fail: diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 442f4820..1f784cfc 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -313,7 +313,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) } sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_ACTIVE; sdi->vendor = g_strdup(model->series->vendor->name); sdi->model = g_strdup(model->name); sdi->version = g_strdup(hw_info->firmware_version); @@ -404,10 +403,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) sdi->priv = devc; - sdi->status = SR_ST_INACTIVE; - - sr_scpi_close(scpi); - return sdi; } diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 25bc7eed..a29744ed 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -91,7 +91,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) } sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup(vendor); sdi->model = g_strdup(hw_info->model); sdi->version = g_strdup(hw_info->firmware_version); @@ -168,7 +167,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) hw_info = NULL; scpi_cmd(sdi, devc->device->commands, SCPI_CMD_LOCAL); - sr_scpi_close(scpi); return sdi; } diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 61c71ea8..21fa1657 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -92,7 +92,6 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi) goto fail; sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_ACTIVE; sdi->vendor = g_strdup(MANUFACTURER_NAME); sdi->model = g_strdup(model_name); sdi->version = g_strdup(hw_info->firmware_version); @@ -112,9 +111,6 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi) if (dlm_device_init(sdi, model_index) != SR_OK) goto fail; - sr_scpi_close(sdi->conn); - - sdi->status = SR_ST_INACTIVE; return sdi; fail: diff --git a/src/scpi/scpi.c b/src/scpi/scpi.c index 0efde8ba..c3c2f713 100644 --- a/src/scpi/scpi.c +++ b/src/scpi/scpi.c @@ -110,12 +110,16 @@ static struct sr_dev_inst *sr_scpi_scan_resource(struct drv_context *drvc, return NULL; }; - if ((sdi = probe_device(scpi))) - return sdi; + sdi = probe_device(scpi); sr_scpi_close(scpi); - sr_scpi_free(scpi); - return NULL; + + if (sdi) + sdi->status = SR_ST_INACTIVE; + else + sr_scpi_free(scpi); + + return sdi; } SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options,