]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-dmm/api.c
scpi-dmm: Add infinity limit to model-specific config.
[libsigrok.git] / src / hardware / scpi-dmm / api.c
index cdd4d7cdf2c14dee75e50ca6f36089ac30c3c260..456c24dbf9ea93e13668efa56b482f642057185a 100644 (file)
@@ -33,6 +33,7 @@ static const uint32_t drvopts[] = {
 
 static const uint32_t devopts_generic[] = {
        SR_CONF_CONTINUOUS,
+       SR_CONF_CONN | SR_CONF_GET,
        SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
@@ -82,10 +83,10 @@ static const struct scpi_command cmdset_hp[] = {
 
 static const struct scpi_command cmdset_gwinstek[] = {
        { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
+       { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
        { DMM_CMD_SETUP_FUNC, "CONF:%s", },
        { DMM_CMD_QUERY_FUNC, "CONF:STAT:FUNC?", },
        { DMM_CMD_START_ACQ, "*CLS;SYST:REM", },
-       { DMM_CMD_STOP_ACQ, "SYST:LOC", },
        { DMM_CMD_QUERY_VALUE, "VAL1?", },
        { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", },
        ALL_ZERO,
@@ -93,10 +94,11 @@ static const struct scpi_command cmdset_gwinstek[] = {
 
 static const struct scpi_command cmdset_gwinstek_906x[] = {
        { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
+       { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
        { DMM_CMD_SETUP_FUNC, "CONF:%s", },
        { DMM_CMD_QUERY_FUNC, "CONF?", },
-       { DMM_CMD_START_ACQ, "*CLS;SYST:REM", },
-       { DMM_CMD_STOP_ACQ, "SYST:LOC", },
+       { DMM_CMD_START_ACQ, "INIT", },
+       { DMM_CMD_STOP_ACQ, "ABORT", },
        { DMM_CMD_QUERY_VALUE, "VAL1?", },
        { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", },
        ALL_ZERO,
@@ -166,57 +168,57 @@ SR_PRIV const struct scpi_dmm_model models[] = {
                1, 5, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
                scpi_dmm_get_meas_agilent,
                ARRAY_AND_SIZE(devopts_generic),
-               0,
+               0, 0,
        },
        {
                "Agilent", "34410A",
                1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34405a),
                scpi_dmm_get_meas_agilent,
                ARRAY_AND_SIZE(devopts_generic),
-               0,
-       },
-       {
-               "Keysight", "34465A",
-               1, 5, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
-               scpi_dmm_get_meas_agilent,
-               ARRAY_AND_SIZE(devopts_generic),
-               0,
-       },
-       {
-               "HP", "34401A",
-               1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34401a),
-               scpi_dmm_get_meas_agilent,
-               ARRAY_AND_SIZE(devopts_generic),
-               /* 34401A: typ. 1020ms for AC readings (default is 1000ms). */
-               1000 * 1500,
+               0, 0,
        },
        {
                "GW", "GDM8251A",
                1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a),
                scpi_dmm_get_meas_gwinstek,
                ARRAY_AND_SIZE(devopts_generic),
-               1000 * 2500,
+               1000 * 2500, 0,
        },
        {
                "GW", "GDM8255A",
                1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a),
                scpi_dmm_get_meas_gwinstek,
                ARRAY_AND_SIZE(devopts_generic),
-               1000 * 2500,
+               1000 * 2500, 0,
        },
        {
                "GWInstek", "GDM9060",
                1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x),
                scpi_dmm_get_meas_agilent,
                ARRAY_AND_SIZE(devopts_generic),
-               0,
+               0, 0,
        },
        {
                "GWInstek", "GDM9061",
                1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x),
                scpi_dmm_get_meas_agilent,
                ARRAY_AND_SIZE(devopts_generic),
-               0,
+               0, 0,
+       },
+       {
+               "HP", "34401A",
+               1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34401a),
+               scpi_dmm_get_meas_agilent,
+               ARRAY_AND_SIZE(devopts_generic),
+               /* 34401A: typ. 1020ms for AC readings (default is 1000ms). */
+               1000 * 1500, 0,
+       },
+       {
+               "Keysight", "34465A",
+               1, 5, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
+               scpi_dmm_get_meas_agilent,
+               ARRAY_AND_SIZE(devopts_generic),
+               0, 0,
        },
 };
 
@@ -249,6 +251,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        struct dev_context *devc;
        size_t i;
        gchar *channel_name;
+       const char *command;
 
        scpi_dmm_cmd_delay(scpi);
        ret = sr_scpi_get_hw_id(scpi, &hw_info);
@@ -271,6 +274,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        sdi->conn = scpi;
        sdi->driver = &scpi_dmm_driver_info;
        sdi->inst_type = SR_INST_SCPI;
+       ret = sr_scpi_connection_id(scpi, &sdi->connection_id);
+       if (ret != SR_OK) {
+               g_free(sdi->connection_id);
+               sdi->connection_id = NULL;
+       }
        sr_scpi_hw_info_free(hw_info);
        if (model->read_timeout_us)  /* non-default read timeout */
                scpi->read_timeout_us = model->read_timeout_us;
@@ -279,13 +287,22 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        devc->num_channels = model->num_channels;
        devc->cmdset = model->cmdset;
        devc->model = model;
-       devc->precision = NULL;
 
        for (i = 0; i < devc->num_channels; i++) {
                channel_name = g_strdup_printf("P%zu", i + 1);
                sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, channel_name);
        }
 
+       /*
+        * If device has DMM_CMD_SETUP_LOCAL command, send it now. To avoid
+        * leaving device in remote mode (if only a "scan" is run).
+        */
+       command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL);
+       if (command && *command) {
+               scpi_dmm_cmd_delay(scpi);
+               sr_scpi_send(scpi, command);
+       }
+
        return sdi;
 }
 
@@ -311,8 +328,11 @@ static int dev_open(struct sr_dev_inst *sdi)
 
 static int dev_close(struct sr_dev_inst *sdi)
 {
+       struct dev_context *devc;
        struct sr_scpi_dev_inst *scpi;
+       const char *command;
 
+       devc = sdi->priv;
        scpi = sdi->conn;
        if (!scpi)
                return SR_ERR_BUG;
@@ -321,6 +341,16 @@ static int dev_close(struct sr_dev_inst *sdi)
        if (sdi->status <= SR_ST_INACTIVE)
                return SR_OK;
 
+       /*
+        * If device has DMM_CMD_SETUP_LOCAL command, send it now
+        * to avoid leaving device in remote mode.
+        */
+       command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL);
+       if (command && *command) {
+               scpi_dmm_cmd_delay(scpi);
+               sr_scpi_send(scpi, command);
+       }
+
        return sr_scpi_close(scpi);
 }
 
@@ -338,6 +368,11 @@ static int config_get(uint32_t key, GVariant **data,
        devc = sdi->priv;
 
        switch (key) {
+       case SR_CONF_CONN:
+               if (!sdi || !sdi->connection_id)
+                       return SR_ERR_NA;
+               *data = g_variant_new_string(sdi->connection_id);
+               return SR_OK;
        case SR_CONF_LIMIT_SAMPLES:
        case SR_CONF_LIMIT_MSEC:
                return sr_sw_limits_config_get(&devc->limits, key, data);
@@ -449,14 +484,13 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                ret = sr_scpi_get_string(scpi, command, &response);
                if (ret == SR_OK) {
                        g_strstrip(response);
-                       if (devc->precision)
-                               g_free(devc->precision);
-                       devc->precision=g_strdup(response);
+                       g_free(devc->precision);
+                       devc->precision = g_strdup(response);
                        g_free(response);
                        sr_dbg("%s: Precision: '%s'", __func__, devc->precision);
                } else {
-                       sr_info("%s: Precision query ('%s') failed: %d",
-                               __func__, command, ret);
+                       sr_info("Precision query ('%s') failed: %d",
+                               command, ret);
                }
        }
 
@@ -499,10 +533,8 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 
        std_session_send_df_end(sdi);
 
-       if (devc->precision) {
-               g_free(devc->precision);
-               devc->precision = NULL;
-       }
+       g_free(devc->precision);
+       devc->precision = NULL;
 
        return SR_OK;
 }