2 * This file is part of the libsigrok project.
4 * Copyright (C) 2018 Gerhard Sittig <gerhard.sittig@gmx.net>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 static struct sr_dev_driver scpi_dmm_driver_info;
25 static const uint32_t scanopts[] = {
30 static const uint32_t drvopts[] = {
34 static const uint32_t devopts_generic[] = {
36 SR_CONF_CONN | SR_CONF_GET,
37 SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
38 SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
39 SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
42 static const uint32_t devopts_generic_range[] = {
44 SR_CONF_CONN | SR_CONF_GET,
45 SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
46 SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
47 SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
48 SR_CONF_RANGE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
51 static const struct scpi_command cmdset_agilent[] = {
52 { DMM_CMD_SETUP_REMOTE, "\n", },
53 { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
54 { DMM_CMD_SETUP_FUNC, "CONF:%s", },
55 { DMM_CMD_QUERY_FUNC, "CONF?", },
56 { DMM_CMD_START_ACQ, "INIT", },
57 { DMM_CMD_STOP_ACQ, "ABORT", },
58 { DMM_CMD_QUERY_VALUE, "FETCH?", },
59 { DMM_CMD_QUERY_PREC, "CONF?", },
60 { DMM_CMD_QUERY_RANGE_AUTO, "%s:RANGE:AUTO?", },
61 { DMM_CMD_QUERY_RANGE, "%s:RANGE?", },
62 { DMM_CMD_SETUP_RANGE, "CONF:%s %s", },
67 * cmdset_hp is used for the 34401A, which was added to this code after the
68 * 34405A and 34465A. It differs in starting the measurement with INIT: using
69 * MEAS without a trailing '?' (as used for the 34405A) is not valid for the
70 * 34401A and gives an error.
71 * I'm surprised the same instruction sequence doesn't work and INIT may
72 * work for both, but I don't have the others to re-test.
74 * cmdset_hp also works well for the 34410A, using cmdset_agilent throws an
75 * error on 'MEAS' without a '?'.
78 * MEAS <optional parameters> ? configures, arms, triggers and waits
80 * CONF <parameters> configures
81 * INIT prepares for triggering (trigger mode is not set, assumed
82 * internal - external might time out)
83 * *OPC waits for completion, and
84 * READ? retrieves the result
86 static const struct scpi_command cmdset_hp[] = {
87 { DMM_CMD_SETUP_REMOTE, "\n", },
88 { DMM_CMD_SETUP_FUNC, "CONF:%s", },
89 { DMM_CMD_QUERY_FUNC, "CONF?", },
90 { DMM_CMD_START_ACQ, "INIT", },
91 { DMM_CMD_STOP_ACQ, "ABORT", },
92 { DMM_CMD_QUERY_VALUE, "READ?", },
93 { DMM_CMD_QUERY_PREC, "CONF?", },
97 static const struct scpi_command cmdset_gwinstek[] = {
98 { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
99 { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
100 { DMM_CMD_SETUP_FUNC, "CONF:%s", },
101 { DMM_CMD_QUERY_FUNC, "CONF:STAT:FUNC?", },
102 { DMM_CMD_START_ACQ, "*CLS;SYST:REM", },
103 { DMM_CMD_QUERY_VALUE, "VAL1?", },
104 { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", },
108 static const struct scpi_command cmdset_gwinstek_906x[] = {
109 { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
110 { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
111 { DMM_CMD_SETUP_FUNC, "CONF:%s", },
112 { DMM_CMD_QUERY_FUNC, "CONF?", },
113 { DMM_CMD_START_ACQ, "INIT", },
114 { DMM_CMD_STOP_ACQ, "ABORT", },
115 { DMM_CMD_QUERY_VALUE, "VAL1?", },
116 { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", },
120 static const struct scpi_command cmdset_owon[] = {
121 { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
122 { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
123 { DMM_CMD_SETUP_FUNC, "CONF:%s", },
124 { DMM_CMD_QUERY_FUNC, "FUNC?", },
125 { DMM_CMD_QUERY_VALUE, "MEAS1?", },
129 static const struct mqopt_item mqopts_agilent_34405a[] = {
130 { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, },
131 { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, FLAG_CONF_DELAY | FLAG_MEAS_DELAY, },
132 { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, },
133 { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, FLAG_CONF_DELAY | FLAG_MEAS_DELAY, },
134 { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, FLAG_MEAS_DELAY, },
135 { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, FLAG_MEAS_DELAY, },
136 { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAG_NO_RANGE, },
137 { SR_MQ_CAPACITANCE, 0, "CAP", "CAP ", NO_DFLT_PREC, FLAGS_NONE, },
138 { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAG_NO_RANGE, },
139 { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP ", NO_DFLT_PREC, FLAG_NO_RANGE | FLAG_MEAS_DELAY, },
140 { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, FLAG_NO_RANGE | FLAG_MEAS_DELAY, },
143 static const struct mqopt_item mqopts_agilent_34401a[] = {
144 { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, },
145 { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, FLAGS_NONE, },
146 { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, },
147 { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, FLAGS_NONE, },
148 { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, FLAGS_NONE, },
149 { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, FLAGS_NONE, },
150 { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, },
151 { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, },
152 { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, FLAGS_NONE, },
153 { SR_MQ_TIME, 0, "PER", "PER ", NO_DFLT_PREC, FLAGS_NONE, },
156 static const struct mqopt_item mqopts_gwinstek_gdm8200a[] = {
157 { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "01", NO_DFLT_PREC, FLAGS_NONE, },
158 { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "02", NO_DFLT_PREC, FLAGS_NONE, },
159 { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "03", NO_DFLT_PREC, FLAGS_NONE, },
160 { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "04", NO_DFLT_PREC, FLAGS_NONE, },
161 { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "05", NO_DFLT_PREC, FLAGS_NONE, }, /* mA */
162 { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "06", NO_DFLT_PREC, FLAGS_NONE, }, /* mA */
163 { SR_MQ_RESISTANCE, 0, "RES", "07", NO_DFLT_PREC, FLAGS_NONE, },
164 { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "16", NO_DFLT_PREC, FLAGS_NONE, },
165 { SR_MQ_CONTINUITY, 0, "CONT", "13", -1, FLAGS_NONE, },
166 { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "17", -4, FLAGS_NONE, },
167 { SR_MQ_TEMPERATURE, 0, "TEMP", "09", NO_DFLT_PREC, FLAGS_NONE, }, /* Celsius */
168 { SR_MQ_TEMPERATURE, 0, "TEMP", "15", NO_DFLT_PREC, FLAGS_NONE, }, /* Fahrenheit */
169 { SR_MQ_FREQUENCY, 0, "FREQ", "08", NO_DFLT_PREC, FLAGS_NONE, },
170 { SR_MQ_TIME, 0, "PER", "14", NO_DFLT_PREC, FLAGS_NONE, },
173 static const struct mqopt_item mqopts_gwinstek_gdm906x[] = {
174 { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, },
175 { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC", NO_DFLT_PREC, FLAGS_NONE, },
176 { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, },
177 { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC", NO_DFLT_PREC, FLAGS_NONE, },
178 { SR_MQ_RESISTANCE, 0, "RES", "RES", NO_DFLT_PREC, FLAGS_NONE, },
179 { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES", NO_DFLT_PREC, FLAGS_NONE, },
180 { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, },
181 { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, },
182 { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP", NO_DFLT_PREC, FLAGS_NONE, },
183 { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ", NO_DFLT_PREC, FLAGS_NONE, },
184 { SR_MQ_TIME, 0, "PER", "PER", NO_DFLT_PREC, FLAGS_NONE, },
185 { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, FLAGS_NONE, },
188 static const struct mqopt_item mqopts_owon_xdm2041[] = {
189 { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT AC", NO_DFLT_PREC, FLAGS_NONE, },
190 { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT", NO_DFLT_PREC, FLAGS_NONE, },
191 { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR AC", NO_DFLT_PREC, FLAGS_NONE, },
192 { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR", NO_DFLT_PREC, FLAGS_NONE, },
193 { SR_MQ_RESISTANCE, 0, "RES", "RES", NO_DFLT_PREC, FLAGS_NONE, },
194 { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES", NO_DFLT_PREC, FLAGS_NONE, },
195 { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, },
196 { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, },
197 { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP", NO_DFLT_PREC, FLAGS_NONE, },
198 { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ", NO_DFLT_PREC, FLAGS_NONE, },
199 { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, FLAGS_NONE, },
202 static const struct mqopt_item mqopts_siglent_sdm3055[] = {
203 { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, FLAGS_NONE, },
204 { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, FLAGS_NONE, },
205 { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, FLAGS_NONE, },
206 { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, FLAGS_NONE, },
207 { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, FLAGS_NONE, },
208 { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, FLAGS_NONE, },
209 { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, FLAGS_NONE, },
210 { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, FLAGS_NONE, },
211 { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, FLAGS_NONE, },
212 { SR_MQ_TIME, 0, "PER", "PER ", NO_DFLT_PREC, FLAGS_NONE, },
213 { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, FLAGS_NONE, },
216 SR_PRIV const struct scpi_dmm_model models[] = {
219 1, 5, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
220 scpi_dmm_get_meas_agilent,
221 ARRAY_AND_SIZE(devopts_generic_range),
222 0, 200 * 1000, 2500 * 1000, 0, FALSE,
223 scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL,
227 1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34405a),
228 scpi_dmm_get_meas_agilent,
229 ARRAY_AND_SIZE(devopts_generic),
235 1, 6, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
236 scpi_dmm_get_meas_agilent,
237 ARRAY_AND_SIZE(devopts_generic_range),
238 0, 0, 10 * 1000, 0, FALSE,
239 scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL,
243 1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a),
244 scpi_dmm_get_meas_gwinstek,
245 ARRAY_AND_SIZE(devopts_generic),
246 2500 * 1000, 0, 0, 0, FALSE,
251 1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a),
252 scpi_dmm_get_meas_gwinstek,
253 ARRAY_AND_SIZE(devopts_generic),
254 2500 * 1000, 0, 0, 0, FALSE,
258 "GWInstek", "GDM9060",
259 1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x),
260 scpi_dmm_get_meas_agilent,
261 ARRAY_AND_SIZE(devopts_generic),
266 "GWInstek", "GDM9061",
267 1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x),
268 scpi_dmm_get_meas_agilent,
269 ARRAY_AND_SIZE(devopts_generic),
275 1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34401a),
276 scpi_dmm_get_meas_agilent,
277 ARRAY_AND_SIZE(devopts_generic),
278 /* 34401A: typ. 1020ms for AC readings (default is 1000ms). */
279 1500 * 1000, 0, 0, 0, FALSE,
283 "Keysight", "34465A",
284 1, 6, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a),
285 scpi_dmm_get_meas_agilent,
286 ARRAY_AND_SIZE(devopts_generic_range),
287 0, 0, 10 * 1000, 0, FALSE,
288 scpi_dmm_get_range_text, scpi_dmm_set_range_from_text, NULL,
292 1, 5, cmdset_owon, ARRAY_AND_SIZE(mqopts_owon_xdm2041),
293 scpi_dmm_get_meas_gwinstek,
294 ARRAY_AND_SIZE(devopts_generic),
299 "Siglent", "SDM3055",
300 1, 5, cmdset_hp, ARRAY_AND_SIZE(mqopts_siglent_sdm3055),
301 scpi_dmm_get_meas_agilent,
302 ARRAY_AND_SIZE(devopts_generic),
308 static const struct scpi_dmm_model *is_compatible(const char *vendor, const char *model)
311 const struct scpi_dmm_model *entry;
313 for (i = 0; i < ARRAY_SIZE(models); i++) {
315 if (!entry->vendor || !entry->model)
317 if (strcmp(vendor, entry->vendor) != 0)
319 if (strcmp(model, entry->model) != 0)
328 * Some devices (such as Owon XDM2041) do not support the standard
329 * OPeration Complete? command. This function tests the command with
330 * a short timeout, and returns TRUE if any reply (busy or not) is received.
332 static gboolean probe_opc_support(struct sr_scpi_dev_inst *scpi)
337 response = g_string_sized_new(128);
339 if (sr_scpi_get_data(scpi, SCPI_CMD_OPC, &response) != SR_OK)
341 g_string_free(response, TRUE);
346 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
348 struct sr_scpi_hw_info *hw_info;
351 const struct scpi_dmm_model *model;
352 struct sr_dev_inst *sdi;
353 struct dev_context *devc;
358 ret = sr_scpi_get_hw_id(scpi, &hw_info);
360 sr_info("Could not get IDN response.");
363 vendor = sr_vendor_alias(hw_info->manufacturer);
364 model = is_compatible(vendor, hw_info->model);
366 sr_scpi_hw_info_free(hw_info);
370 if (model->check_opc && !probe_opc_support(scpi))
371 scpi->no_opc_command = TRUE;
373 sdi = g_malloc0(sizeof(*sdi));
374 sdi->vendor = g_strdup(hw_info->manufacturer);
375 sdi->model = g_strdup(hw_info->model);
376 sdi->version = g_strdup(hw_info->firmware_version);
377 sdi->serial_num = g_strdup(hw_info->serial_number);
379 sdi->driver = &scpi_dmm_driver_info;
380 sdi->inst_type = SR_INST_SCPI;
381 ret = sr_scpi_connection_id(scpi, &sdi->connection_id);
383 g_free(sdi->connection_id);
384 sdi->connection_id = NULL;
386 sr_scpi_hw_info_free(hw_info);
387 if (model->read_timeout_us) /* non-default read timeout */
388 scpi->read_timeout_us = model->read_timeout_us;
389 devc = g_malloc0(sizeof(*devc));
391 devc->num_channels = model->num_channels;
392 devc->cmdset = model->cmdset;
395 for (i = 0; i < devc->num_channels; i++) {
396 channel_name = g_strdup_printf("P%zu", i + 1);
397 sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, channel_name);
401 * If device has DMM_CMD_SETUP_LOCAL command, send it now. To avoid
402 * leaving device in remote mode (if only a "scan" is run).
404 command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL);
405 if (command && *command) {
406 scpi_dmm_cmd_delay(scpi);
407 sr_scpi_send(scpi, command);
413 static GSList *scan(struct sr_dev_driver *di, GSList *options)
415 return sr_scpi_scan(di->context, options, probe_device);
418 static int dev_open(struct sr_dev_inst *sdi)
420 struct sr_scpi_dev_inst *scpi;
424 ret = sr_scpi_open(scpi);
426 sr_err("Failed to open SCPI device: %s.", sr_strerror(ret));
433 static int dev_close(struct sr_dev_inst *sdi)
435 struct dev_context *devc;
436 struct sr_scpi_dev_inst *scpi;
444 sr_dbg("DIAG: sdi->status %d.", sdi->status - SR_ST_NOT_FOUND);
445 if (sdi->status <= SR_ST_INACTIVE)
449 * If device has DMM_CMD_SETUP_LOCAL command, send it now
450 * to avoid leaving device in remote mode.
452 command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL);
453 if (command && *command) {
454 scpi_dmm_cmd_delay(scpi);
455 sr_scpi_send(scpi, command);
458 return sr_scpi_close(scpi);
461 static int config_get(uint32_t key, GVariant **data,
462 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
464 struct dev_context *devc;
466 enum sr_mqflag mqflag;
477 if (!sdi || !sdi->connection_id)
479 *data = g_variant_new_string(sdi->connection_id);
481 case SR_CONF_LIMIT_SAMPLES:
482 case SR_CONF_LIMIT_MSEC:
483 return sr_sw_limits_config_get(&devc->limits, key, data);
484 case SR_CONF_MEASURED_QUANTITY:
485 ret = scpi_dmm_get_mq(sdi, &mq, &mqflag, NULL, NULL);
488 arr[0] = g_variant_new_uint32(mq);
489 arr[1] = g_variant_new_uint64(mqflag);
490 *data = g_variant_new_tuple(arr, ARRAY_SIZE(arr));
493 if (!devc || !devc->model->get_range_text)
495 range = devc->model->get_range_text(sdi);
496 if (!range || !*range)
498 *data = g_variant_new_string(range);
505 static int config_set(uint32_t key, GVariant *data,
506 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
508 struct dev_context *devc;
510 enum sr_mqflag mqflag;
511 GVariant *tuple_child;
519 case SR_CONF_LIMIT_SAMPLES:
520 case SR_CONF_LIMIT_MSEC:
521 return sr_sw_limits_config_set(&devc->limits, key, data);
522 case SR_CONF_MEASURED_QUANTITY:
523 tuple_child = g_variant_get_child_value(data, 0);
524 mq = g_variant_get_uint32(tuple_child);
525 g_variant_unref(tuple_child);
526 tuple_child = g_variant_get_child_value(data, 1);
527 mqflag = g_variant_get_uint64(tuple_child);
528 g_variant_unref(tuple_child);
529 return scpi_dmm_set_mq(sdi, mq, mqflag);
531 if (!devc || !devc->model->set_range_from_text)
533 range = g_variant_get_string(data, NULL);
534 return devc->model->set_range_from_text(sdi, range);
540 static int config_list(uint32_t key, GVariant **data,
541 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
543 struct dev_context *devc;
544 GVariant *gvar, *arr[2];
550 devc = sdi ? sdi->priv : NULL;
553 case SR_CONF_SCAN_OPTIONS:
554 case SR_CONF_DEVICE_OPTIONS:
556 return STD_CONFIG_LIST(key, data, sdi, cg,
557 scanopts, drvopts, devopts_generic);
558 return std_opts_config_list(key, data, sdi, cg,
559 ARRAY_AND_SIZE(scanopts), ARRAY_AND_SIZE(drvopts),
560 devc->model->devopts, devc->model->devopts_size);
561 case SR_CONF_MEASURED_QUANTITY:
562 /* TODO Use std_gvar_measured_quantities() when available. */
565 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
566 for (i = 0; i < devc->model->mqopt_size; i++) {
567 arr[0] = g_variant_new_uint32(devc->model->mqopts[i].mq);
568 arr[1] = g_variant_new_uint64(devc->model->mqopts[i].mqflag);
569 gvar = g_variant_new_tuple(arr, ARRAY_SIZE(arr));
570 g_variant_builder_add_value(&gvb, gvar);
572 *data = g_variant_builder_end(&gvb);
575 if (!devc || !devc->model->get_range_text_list)
577 *data = devc->model->get_range_text_list(sdi);
585 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
587 struct sr_scpi_dev_inst *scpi;
588 struct dev_context *devc;
590 const struct mqopt_item *item;
593 gboolean do_mq_meas_delay;
598 ret = scpi_dmm_get_mq(sdi, &devc->start_acq_mq.curr_mq,
599 &devc->start_acq_mq.curr_mqflag, NULL, &item);
604 * Query for current precision if DMM supports the command
606 command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_QUERY_PREC);
607 if (command && *command) {
608 scpi_dmm_cmd_delay(scpi);
609 ret = sr_scpi_get_string(scpi, command, &response);
611 g_strstrip(response);
612 g_free(devc->precision);
613 devc->precision = g_strdup(response);
615 sr_dbg("%s: Precision: '%s'", __func__, devc->precision);
617 sr_info("Precision query ('%s') failed: %d",
622 command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_START_ACQ);
623 if (command && *command) {
624 scpi_dmm_cmd_delay(scpi);
625 ret = sr_scpi_send(scpi, command);
630 do_mq_meas_delay = item->drv_flags & FLAG_MEAS_DELAY;
631 if (do_mq_meas_delay && devc->model->meas_delay_us)
632 g_usleep(devc->model->meas_delay_us);
634 sr_sw_limits_acquisition_start(&devc->limits);
635 ret = std_session_send_df_header(sdi);
639 ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10,
640 scpi_dmm_receive_data, (void *)sdi);
647 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
649 struct sr_scpi_dev_inst *scpi;
650 struct dev_context *devc;
656 command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_STOP_ACQ);
657 if (command && *command) {
658 scpi_dmm_cmd_delay(scpi);
659 (void)sr_scpi_send(scpi, command);
661 sr_scpi_source_remove(sdi->session, scpi);
663 std_session_send_df_end(sdi);
665 g_free(devc->precision);
666 devc->precision = NULL;
671 static struct sr_dev_driver scpi_dmm_driver_info = {
673 .longname = "SCPI DMM",
676 .cleanup = std_cleanup,
678 .dev_list = std_dev_list,
679 .dev_clear = std_dev_clear,
680 .config_get = config_get,
681 .config_set = config_set,
682 .config_list = config_list,
683 .dev_open = dev_open,
684 .dev_close = dev_close,
685 .dev_acquisition_start = dev_acquisition_start,
686 .dev_acquisition_stop = dev_acquisition_stop,
689 SR_REGISTER_DEV_DRIVER(scpi_dmm_driver_info);