]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-dmm/api.c
scpi-dmm: Add support for GW-Instek 906X series bench multimeters.
[libsigrok.git] / src / hardware / scpi-dmm / api.c
index 74f971e3112bb7e82c5509115cee8e371973d382..cdd4d7cdf2c14dee75e50ca6f36089ac30c3c260 100644 (file)
@@ -57,6 +57,9 @@ static const struct scpi_command cmdset_agilent[] = {
  * I'm surprised the same instruction sequence doesn't work and INIT may
  * work for both, but I don't have the others to re-test.
  *
+ * cmdset_hp also works well for the 34410A, using cmdset_agilent throws an
+ * error on 'MEAS' without a '?'.
+ *
  * On the 34401A,
  *  MEAS <optional parameters> ? configures, arms, triggers and waits
  *       for a reading
@@ -77,6 +80,28 @@ static const struct scpi_command cmdset_hp[] = {
        ALL_ZERO,
 };
 
+static const struct scpi_command cmdset_gwinstek[] = {
+       { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
+       { 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,
+};
+
+static const struct scpi_command cmdset_gwinstek_906x[] = {
+       { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
+       { 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_QUERY_VALUE, "VAL1?", },
+       { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", },
+       ALL_ZERO,
+};
+
 static const struct mqopt_item mqopts_agilent_34405a[] = {
        { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, },
        { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, },
@@ -103,6 +128,38 @@ static const struct mqopt_item mqopts_agilent_34401a[] = {
        { SR_MQ_TIME, 0, "PER", "PER ", NO_DFLT_PREC, },
 };
 
+static const struct mqopt_item mqopts_gwinstek_gdm8200a[] = {
+       { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "01", NO_DFLT_PREC, },
+       { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "02", NO_DFLT_PREC, },
+       { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "03", NO_DFLT_PREC, },
+       { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "04", NO_DFLT_PREC, },
+       { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "05", NO_DFLT_PREC, }, /* mA */
+       { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "06", NO_DFLT_PREC, }, /* mA */
+       { SR_MQ_RESISTANCE, 0, "RES", "07", NO_DFLT_PREC, },
+       { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "16", NO_DFLT_PREC, },
+       { SR_MQ_CONTINUITY, 0, "CONT", "13", -1, },
+       { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "17", -4, },
+       { SR_MQ_TEMPERATURE, 0, "TEMP", "09", NO_DFLT_PREC, }, /* Celsius */
+       { SR_MQ_TEMPERATURE, 0, "TEMP", "15", NO_DFLT_PREC, }, /* Fahrenheit */
+       { SR_MQ_FREQUENCY, 0, "FREQ", "08", NO_DFLT_PREC, },
+       { SR_MQ_TIME, 0, "PER", "14", NO_DFLT_PREC, },
+};
+
+static const struct mqopt_item mqopts_gwinstek_gdm906x[] = {
+       { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, },
+       { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC", NO_DFLT_PREC, },
+       { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, },
+       { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC", NO_DFLT_PREC, },
+       { SR_MQ_RESISTANCE, 0, "RES", "RES", NO_DFLT_PREC, },
+       { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES", NO_DFLT_PREC, },
+       { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, },
+       { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, },
+       { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP", NO_DFLT_PREC, },
+       { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ", NO_DFLT_PREC, },
+       { SR_MQ_TIME, 0, "PER", "PER", NO_DFLT_PREC, },
+       { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, },
+};
+
 SR_PRIV const struct scpi_dmm_model models[] = {
        {
                "Agilent", "34405A",
@@ -111,6 +168,13 @@ SR_PRIV const struct scpi_dmm_model models[] = {
                ARRAY_AND_SIZE(devopts_generic),
                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),
@@ -126,6 +190,34 @@ SR_PRIV const struct scpi_dmm_model models[] = {
                /* 34401A: typ. 1020ms for AC readings (default is 1000ms). */
                1000 * 1500,
        },
+       {
+               "GW", "GDM8251A",
+               1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a),
+               scpi_dmm_get_meas_gwinstek,
+               ARRAY_AND_SIZE(devopts_generic),
+               1000 * 2500,
+       },
+       {
+               "GW", "GDM8255A",
+               1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a),
+               scpi_dmm_get_meas_gwinstek,
+               ARRAY_AND_SIZE(devopts_generic),
+               1000 * 2500,
+       },
+       {
+               "GWInstek", "GDM9060",
+               1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x),
+               scpi_dmm_get_meas_agilent,
+               ARRAY_AND_SIZE(devopts_generic),
+               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,
+       },
 };
 
 static const struct scpi_dmm_model *is_compatible(const char *vendor, const char *model)
@@ -187,6 +279,7 @@ 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);
@@ -337,6 +430,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        int ret;
        const struct mqopt_item *item;
        const char *command;
+       char *response;
 
        scpi = sdi->conn;
        devc = sdi->priv;
@@ -346,6 +440,26 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        if (ret != SR_OK)
                return ret;
 
+       /*
+        * Query for current precision if DMM supports the command
+        */
+       command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_QUERY_PREC);
+       if (command && *command) {
+               scpi_dmm_cmd_delay(scpi);
+               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(response);
+                       sr_dbg("%s: Precision: '%s'", __func__, devc->precision);
+               } else {
+                       sr_info("%s: Precision query ('%s') failed: %d",
+                               __func__, command, ret);
+               }
+       }
+
        command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_START_ACQ);
        if (command && *command) {
                scpi_dmm_cmd_delay(scpi);
@@ -385,6 +499,11 @@ 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;
+       }
+
        return SR_OK;
 }