+static struct sr_dev_driver scpi_dmm_driver_info;
+
+static const uint32_t scanopts[] = {
+ SR_CONF_CONN,
+ SR_CONF_SERIALCOMM,
+};
+
+static const uint32_t drvopts[] = {
+ SR_CONF_MULTIMETER,
+};
+
+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,
+};
+
+static const uint32_t devopts_generic_range[] = {
+ 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,
+ SR_CONF_RANGE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+};
+
+static const struct scpi_command cmdset_agilent[] = {
+ { DMM_CMD_SETUP_REMOTE, "\n", },
+ { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
+ { DMM_CMD_SETUP_FUNC, "CONF:%s", },
+ { DMM_CMD_QUERY_FUNC, "CONF?", },
+ { DMM_CMD_START_ACQ, "INIT", },
+ { DMM_CMD_STOP_ACQ, "ABORT", },
+ { DMM_CMD_QUERY_VALUE, "FETCH?", },
+ { DMM_CMD_QUERY_PREC, "CONF?", },
+ { DMM_CMD_QUERY_RANGE_AUTO, "%s:RANGE:AUTO?", },
+ { DMM_CMD_QUERY_RANGE, "%s:RANGE?", },
+ { DMM_CMD_SETUP_RANGE, "CONF:%s %s", },
+ ALL_ZERO,
+};
+
+/*
+ * cmdset_hp is used for the 34401A, which was added to this code after the
+ * 34405A and 34465A. It differs in starting the measurement with INIT: using
+ * MEAS without a trailing '?' (as used for the 34405A) is not valid for the
+ * 34401A and gives an error.
+ * 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
+ * CONF <parameters> configures
+ * INIT prepares for triggering (trigger mode is not set, assumed
+ * internal - external might time out)
+ * *OPC waits for completion, and
+ * READ? retrieves the result
+ */
+static const struct scpi_command cmdset_hp[] = {
+ { DMM_CMD_SETUP_REMOTE, "\n", },
+ { DMM_CMD_SETUP_FUNC, "CONF:%s", },
+ { DMM_CMD_QUERY_FUNC, "CONF?", },
+ { DMM_CMD_START_ACQ, "INIT", },
+ { DMM_CMD_STOP_ACQ, "ABORT", },
+ { DMM_CMD_QUERY_VALUE, "READ?", },
+ { DMM_CMD_QUERY_PREC, "CONF?", },
+ ALL_ZERO,
+};
+
+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_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_LOCAL, "SYST:LOC", },
+ { DMM_CMD_SETUP_FUNC, "CONF:%s", },
+ { DMM_CMD_QUERY_FUNC, "CONF?", },
+ { DMM_CMD_START_ACQ, "INIT", },
+ { DMM_CMD_STOP_ACQ, "ABORT", },
+ { DMM_CMD_QUERY_VALUE, "VAL1?", },
+ { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", },
+ ALL_ZERO,
+};
+
+static const struct scpi_command cmdset_owon[] = {
+ { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
+ { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
+ { DMM_CMD_SETUP_FUNC, "CONF:%s", },
+ { DMM_CMD_QUERY_FUNC, "FUNC?", },
+ { DMM_CMD_QUERY_VALUE, "MEAS1?", },
+ ALL_ZERO,
+};
+
+static const struct mqopt_item mqopts_agilent_34405a[] = {
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, FLAG_CONF_DELAY | FLAG_MEAS_DELAY, },
+ { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, FLAG_CONF_DELAY | FLAG_MEAS_DELAY, },
+ { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, FLAG_MEAS_DELAY, },
+ { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, FLAG_MEAS_DELAY, },
+ { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAG_NO_RANGE, },
+ { SR_MQ_CAPACITANCE, 0, "CAP", "CAP ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAG_NO_RANGE, },
+ { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP ", NO_DFLT_PREC, FLAG_NO_RANGE | FLAG_MEAS_DELAY, },
+ { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, FLAG_NO_RANGE | FLAG_MEAS_DELAY, },
+};
+
+static const struct mqopt_item mqopts_agilent_34401a[] = {
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, },
+ { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_TIME, 0, "PER", "PER ", NO_DFLT_PREC, FLAGS_NONE, },
+};
+
+static const struct mqopt_item mqopts_gwinstek_gdm8200a[] = {
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "01", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "02", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "03", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "04", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "05", NO_DFLT_PREC, FLAGS_NONE, }, /* mA */
+ { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "06", NO_DFLT_PREC, FLAGS_NONE, }, /* mA */
+ { SR_MQ_RESISTANCE, 0, "RES", "07", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "16", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CONTINUITY, 0, "CONT", "13", -1, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "17", -4, FLAGS_NONE, },
+ { SR_MQ_TEMPERATURE, 0, "TEMP", "09", NO_DFLT_PREC, FLAGS_NONE, }, /* Celsius */
+ { SR_MQ_TEMPERATURE, 0, "TEMP", "15", NO_DFLT_PREC, FLAGS_NONE, }, /* Fahrenheit */
+ { SR_MQ_FREQUENCY, 0, "FREQ", "08", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_TIME, 0, "PER", "14", NO_DFLT_PREC, FLAGS_NONE, },
+};
+
+static const struct mqopt_item mqopts_gwinstek_gdm906x[] = {
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, 0, "RES", "RES", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, },
+ { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_TIME, 0, "PER", "PER", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, FLAGS_NONE, },
+};
+
+static const struct mqopt_item mqopts_owon_xdm2041[] = {
+ { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT AC", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR AC", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, 0, "RES", "RES", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, },
+ { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, FLAGS_NONE, },
+};
+
+static const struct mqopt_item mqopts_siglent_sdm3055[] = {
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, },
+ { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, },
+ { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_TIME, 0, "PER", "PER ", NO_DFLT_PREC, FLAGS_NONE, },
+ { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, FLAGS_NONE, },
+};
+
+SR_PRIV const struct scpi_dmm_model models[] = {
+ {
+ "Agilent", "34405A",
+ 1, 5, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
+ scpi_dmm_get_meas_agilent,
+ ARRAY_AND_SIZE(devopts_generic_range),
+ 0, 200 * 1000, 2500 * 1000, 0, FALSE,
+ scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL,
+ },
+ {
+ "Agilent", "34410A",
+ 1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34405a),
+ scpi_dmm_get_meas_agilent,
+ ARRAY_AND_SIZE(devopts_generic),
+ 0, 0, 0, 0, FALSE,
+ NULL, NULL, NULL,
+ },
+ {
+ "Agilent", "34460A",
+ 1, 6, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
+ scpi_dmm_get_meas_agilent,
+ ARRAY_AND_SIZE(devopts_generic_range),
+ 0, 0, 10 * 1000, 0, FALSE,
+ scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL,
+ },
+ {
+ "GW", "GDM8251A",
+ 1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a),
+ scpi_dmm_get_meas_gwinstek,
+ ARRAY_AND_SIZE(devopts_generic),
+ 2500 * 1000, 0, 0, 0, FALSE,
+ NULL, NULL, NULL,
+ },
+ {
+ "GW", "GDM8255A",
+ 1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a),
+ scpi_dmm_get_meas_gwinstek,
+ ARRAY_AND_SIZE(devopts_generic),
+ 2500 * 1000, 0, 0, 0, FALSE,
+ NULL, NULL, NULL,
+ },
+ {
+ "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, 0, FALSE,
+ NULL, NULL, NULL,
+ },
+ {
+ "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, 0, FALSE,
+ NULL, NULL, NULL,
+ },
+ {
+ "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). */
+ 1500 * 1000, 0, 0, 0, FALSE,
+ NULL, NULL, NULL,
+ },
+ {
+ "Keysight", "34465A",
+ 1, 6, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
+ scpi_dmm_get_meas_agilent,
+ ARRAY_AND_SIZE(devopts_generic_range),
+ 0, 0, 10 * 1000, 0, FALSE,
+ scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL,
+ },
+ {
+ "OWON", "XDM1041",
+ 1, 5, cmdset_owon, ARRAY_AND_SIZE(mqopts_owon_xdm2041),
+ scpi_dmm_get_meas_gwinstek,
+ ARRAY_AND_SIZE(devopts_generic),
+ 0, 0, 0, 1e9, TRUE,
+ NULL, NULL, NULL,
+ },
+ {
+ "OWON", "XDM2041",
+ 1, 5, cmdset_owon, ARRAY_AND_SIZE(mqopts_owon_xdm2041),
+ scpi_dmm_get_meas_gwinstek,
+ ARRAY_AND_SIZE(devopts_generic),
+ 0, 0, 0, 1e9, TRUE,
+ NULL, NULL, NULL,
+ },
+ {
+ "Siglent", "SDM3055",
+ 1, 5, cmdset_hp, ARRAY_AND_SIZE(mqopts_siglent_sdm3055),
+ scpi_dmm_get_meas_agilent,
+ ARRAY_AND_SIZE(devopts_generic),
+ 0, 0, 0, 0, FALSE,
+ NULL, NULL, NULL,
+ },
+};
+
+static const struct scpi_dmm_model *is_compatible(const char *vendor, const char *model)
+{
+ size_t i;
+ const struct scpi_dmm_model *entry;
+
+ for (i = 0; i < ARRAY_SIZE(models); i++) {
+ entry = &models[i];
+ if (!entry->vendor || !entry->model)
+ continue;
+ if (strcmp(vendor, entry->vendor) != 0)
+ continue;
+ if (strcmp(model, entry->model) != 0)
+ continue;
+ return entry;
+ }
+
+ return NULL;
+}
+
+/*
+ * Some devices (such as Owon XDM2041) do not support the standard
+ * OPeration Complete? command. This function tests the command with
+ * a short timeout, and returns TRUE if any reply (busy or not) is received.
+ */
+static gboolean probe_opc_support(struct sr_scpi_dev_inst *scpi)