]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2018 Gerhard Sittig <gerhard.sittig@gmx.net> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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/>. | |
18 | */ | |
19 | ||
20 | #include <string.h> | |
21 | #include "protocol.h" | |
22 | ||
23 | static struct sr_dev_driver scpi_dmm_driver_info; | |
24 | ||
25 | static const uint32_t scanopts[] = { | |
26 | SR_CONF_CONN, | |
27 | SR_CONF_SERIALCOMM, | |
28 | }; | |
29 | ||
30 | static const uint32_t drvopts[] = { | |
31 | SR_CONF_MULTIMETER, | |
32 | }; | |
33 | ||
34 | static const uint32_t devopts_generic[] = { | |
35 | SR_CONF_CONTINUOUS, | |
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, | |
40 | }; | |
41 | ||
42 | static const struct scpi_command cmdset_agilent[] = { | |
43 | { DMM_CMD_SETUP_REMOTE, "\n", }, | |
44 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, | |
45 | { DMM_CMD_QUERY_FUNC, "CONF?", }, | |
46 | { DMM_CMD_START_ACQ, "MEAS", }, | |
47 | { DMM_CMD_STOP_ACQ, "ABORT", }, | |
48 | { DMM_CMD_QUERY_VALUE, "READ?", }, | |
49 | { DMM_CMD_QUERY_PREC, "CONF?", }, | |
50 | ALL_ZERO, | |
51 | }; | |
52 | ||
53 | /* | |
54 | * cmdset_hp is used for the 34401A, which was added to this code after the | |
55 | * 34405A and 34465A. It differs in starting the measurement with INIT: using | |
56 | * MEAS without a trailing '?' (as used for the 34405A) is not valid for the | |
57 | * 34401A and gives an error. | |
58 | * I'm surprised the same instruction sequence doesn't work and INIT may | |
59 | * work for both, but I don't have the others to re-test. | |
60 | * | |
61 | * cmdset_hp also works well for the 34410A, using cmdset_agilent throws an | |
62 | * error on 'MEAS' without a '?'. | |
63 | * | |
64 | * On the 34401A, | |
65 | * MEAS <optional parameters> ? configures, arms, triggers and waits | |
66 | * for a reading | |
67 | * CONF <parameters> configures | |
68 | * INIT prepares for triggering (trigger mode is not set, assumed | |
69 | * internal - external might time out) | |
70 | * *OPC waits for completion, and | |
71 | * READ? retrieves the result | |
72 | */ | |
73 | static const struct scpi_command cmdset_hp[] = { | |
74 | { DMM_CMD_SETUP_REMOTE, "\n", }, | |
75 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, | |
76 | { DMM_CMD_QUERY_FUNC, "CONF?", }, | |
77 | { DMM_CMD_START_ACQ, "INIT", }, | |
78 | { DMM_CMD_STOP_ACQ, "ABORT", }, | |
79 | { DMM_CMD_QUERY_VALUE, "READ?", }, | |
80 | { DMM_CMD_QUERY_PREC, "CONF?", }, | |
81 | ALL_ZERO, | |
82 | }; | |
83 | ||
84 | static const struct scpi_command cmdset_gwinstek[] = { | |
85 | { DMM_CMD_SETUP_REMOTE, "SYST:REM", }, | |
86 | { DMM_CMD_SETUP_LOCAL, "SYST:LOC", }, | |
87 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, | |
88 | { DMM_CMD_QUERY_FUNC, "CONF:STAT:FUNC?", }, | |
89 | { DMM_CMD_START_ACQ, "*CLS;SYST:REM", }, | |
90 | { DMM_CMD_QUERY_VALUE, "VAL1?", }, | |
91 | { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", }, | |
92 | ALL_ZERO, | |
93 | }; | |
94 | ||
95 | static const struct scpi_command cmdset_gwinstek_906x[] = { | |
96 | { DMM_CMD_SETUP_REMOTE, "SYST:REM", }, | |
97 | { DMM_CMD_SETUP_LOCAL, "SYST:LOC", }, | |
98 | { DMM_CMD_SETUP_FUNC, "CONF:%s", }, | |
99 | { DMM_CMD_QUERY_FUNC, "CONF?", }, | |
100 | { DMM_CMD_START_ACQ, "INIT", }, | |
101 | { DMM_CMD_STOP_ACQ, "ABORT", }, | |
102 | { DMM_CMD_QUERY_VALUE, "VAL1?", }, | |
103 | { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", }, | |
104 | ALL_ZERO, | |
105 | }; | |
106 | ||
107 | static const struct mqopt_item mqopts_agilent_34405a[] = { | |
108 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, }, | |
109 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, }, | |
110 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, }, | |
111 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, }, | |
112 | { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, }, | |
113 | { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, }, | |
114 | { SR_MQ_CAPACITANCE, 0, "CAP", "CAP ", NO_DFLT_PREC, }, | |
115 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, }, | |
116 | { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP ", NO_DFLT_PREC, }, | |
117 | { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, }, | |
118 | }; | |
119 | ||
120 | static const struct mqopt_item mqopts_agilent_34401a[] = { | |
121 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, }, | |
122 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC ", NO_DFLT_PREC, }, | |
123 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, }, | |
124 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC ", NO_DFLT_PREC, }, | |
125 | { SR_MQ_RESISTANCE, 0, "RES", "RES ", NO_DFLT_PREC, }, | |
126 | { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES ", NO_DFLT_PREC, }, | |
127 | { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, }, | |
128 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, }, | |
129 | { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ ", NO_DFLT_PREC, }, | |
130 | { SR_MQ_TIME, 0, "PER", "PER ", NO_DFLT_PREC, }, | |
131 | }; | |
132 | ||
133 | static const struct mqopt_item mqopts_gwinstek_gdm8200a[] = { | |
134 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "01", NO_DFLT_PREC, }, | |
135 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "02", NO_DFLT_PREC, }, | |
136 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "03", NO_DFLT_PREC, }, | |
137 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "04", NO_DFLT_PREC, }, | |
138 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "05", NO_DFLT_PREC, }, /* mA */ | |
139 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "06", NO_DFLT_PREC, }, /* mA */ | |
140 | { SR_MQ_RESISTANCE, 0, "RES", "07", NO_DFLT_PREC, }, | |
141 | { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "16", NO_DFLT_PREC, }, | |
142 | { SR_MQ_CONTINUITY, 0, "CONT", "13", -1, }, | |
143 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "17", -4, }, | |
144 | { SR_MQ_TEMPERATURE, 0, "TEMP", "09", NO_DFLT_PREC, }, /* Celsius */ | |
145 | { SR_MQ_TEMPERATURE, 0, "TEMP", "15", NO_DFLT_PREC, }, /* Fahrenheit */ | |
146 | { SR_MQ_FREQUENCY, 0, "FREQ", "08", NO_DFLT_PREC, }, | |
147 | { SR_MQ_TIME, 0, "PER", "14", NO_DFLT_PREC, }, | |
148 | }; | |
149 | ||
150 | static const struct mqopt_item mqopts_gwinstek_gdm906x[] = { | |
151 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC, "VOLT:DC", "VOLT ", NO_DFLT_PREC, }, | |
152 | { SR_MQ_VOLTAGE, SR_MQFLAG_AC, "VOLT:AC", "VOLT:AC", NO_DFLT_PREC, }, | |
153 | { SR_MQ_CURRENT, SR_MQFLAG_DC, "CURR:DC", "CURR ", NO_DFLT_PREC, }, | |
154 | { SR_MQ_CURRENT, SR_MQFLAG_AC, "CURR:AC", "CURR:AC", NO_DFLT_PREC, }, | |
155 | { SR_MQ_RESISTANCE, 0, "RES", "RES", NO_DFLT_PREC, }, | |
156 | { SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, "FRES", "FRES", NO_DFLT_PREC, }, | |
157 | { SR_MQ_CONTINUITY, 0, "CONT", "CONT", -1, }, | |
158 | { SR_MQ_VOLTAGE, SR_MQFLAG_DC | SR_MQFLAG_DIODE, "DIOD", "DIOD", -4, }, | |
159 | { SR_MQ_TEMPERATURE, 0, "TEMP", "TEMP", NO_DFLT_PREC, }, | |
160 | { SR_MQ_FREQUENCY, 0, "FREQ", "FREQ", NO_DFLT_PREC, }, | |
161 | { SR_MQ_TIME, 0, "PER", "PER", NO_DFLT_PREC, }, | |
162 | { SR_MQ_CAPACITANCE, 0, "CAP", "CAP", NO_DFLT_PREC, }, | |
163 | }; | |
164 | ||
165 | SR_PRIV const struct scpi_dmm_model models[] = { | |
166 | { | |
167 | "Agilent", "34405A", | |
168 | 1, 5, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a), | |
169 | scpi_dmm_get_meas_agilent, | |
170 | ARRAY_AND_SIZE(devopts_generic), | |
171 | 0, | |
172 | }, | |
173 | { | |
174 | "Agilent", "34410A", | |
175 | 1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34405a), | |
176 | scpi_dmm_get_meas_agilent, | |
177 | ARRAY_AND_SIZE(devopts_generic), | |
178 | 0, | |
179 | }, | |
180 | { | |
181 | "GW", "GDM8251A", | |
182 | 1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a), | |
183 | scpi_dmm_get_meas_gwinstek, | |
184 | ARRAY_AND_SIZE(devopts_generic), | |
185 | 1000 * 2500, | |
186 | }, | |
187 | { | |
188 | "GW", "GDM8255A", | |
189 | 1, 6, cmdset_gwinstek, ARRAY_AND_SIZE(mqopts_gwinstek_gdm8200a), | |
190 | scpi_dmm_get_meas_gwinstek, | |
191 | ARRAY_AND_SIZE(devopts_generic), | |
192 | 1000 * 2500, | |
193 | }, | |
194 | { | |
195 | "GWInstek", "GDM9060", | |
196 | 1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x), | |
197 | scpi_dmm_get_meas_agilent, | |
198 | ARRAY_AND_SIZE(devopts_generic), | |
199 | 0, | |
200 | }, | |
201 | { | |
202 | "GWInstek", "GDM9061", | |
203 | 1, 6, cmdset_gwinstek_906x, ARRAY_AND_SIZE(mqopts_gwinstek_gdm906x), | |
204 | scpi_dmm_get_meas_agilent, | |
205 | ARRAY_AND_SIZE(devopts_generic), | |
206 | 0, | |
207 | }, | |
208 | { | |
209 | "HP", "34401A", | |
210 | 1, 6, cmdset_hp, ARRAY_AND_SIZE(mqopts_agilent_34401a), | |
211 | scpi_dmm_get_meas_agilent, | |
212 | ARRAY_AND_SIZE(devopts_generic), | |
213 | /* 34401A: typ. 1020ms for AC readings (default is 1000ms). */ | |
214 | 1000 * 1500, | |
215 | }, | |
216 | { | |
217 | "Keysight", "34465A", | |
218 | 1, 5, cmdset_agilent, ARRAY_AND_SIZE(mqopts_agilent_34405a), | |
219 | scpi_dmm_get_meas_agilent, | |
220 | ARRAY_AND_SIZE(devopts_generic), | |
221 | 0, | |
222 | }, | |
223 | }; | |
224 | ||
225 | static const struct scpi_dmm_model *is_compatible(const char *vendor, const char *model) | |
226 | { | |
227 | size_t i; | |
228 | const struct scpi_dmm_model *entry; | |
229 | ||
230 | for (i = 0; i < ARRAY_SIZE(models); i++) { | |
231 | entry = &models[i]; | |
232 | if (!entry->vendor || !entry->model) | |
233 | continue; | |
234 | if (strcmp(vendor, entry->vendor) != 0) | |
235 | continue; | |
236 | if (strcmp(model, entry->model) != 0) | |
237 | continue; | |
238 | return entry; | |
239 | } | |
240 | ||
241 | return NULL; | |
242 | } | |
243 | ||
244 | static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) | |
245 | { | |
246 | struct sr_scpi_hw_info *hw_info; | |
247 | int ret; | |
248 | const char *vendor; | |
249 | const struct scpi_dmm_model *model; | |
250 | struct sr_dev_inst *sdi; | |
251 | struct dev_context *devc; | |
252 | size_t i; | |
253 | gchar *channel_name; | |
254 | const char *command; | |
255 | ||
256 | scpi_dmm_cmd_delay(scpi); | |
257 | ret = sr_scpi_get_hw_id(scpi, &hw_info); | |
258 | if (ret != SR_OK) { | |
259 | sr_info("Could not get IDN response."); | |
260 | return NULL; | |
261 | } | |
262 | vendor = sr_vendor_alias(hw_info->manufacturer); | |
263 | model = is_compatible(vendor, hw_info->model); | |
264 | if (!model) { | |
265 | sr_scpi_hw_info_free(hw_info); | |
266 | return NULL; | |
267 | } | |
268 | ||
269 | sdi = g_malloc0(sizeof(*sdi)); | |
270 | sdi->vendor = g_strdup(hw_info->manufacturer); | |
271 | sdi->model = g_strdup(hw_info->model); | |
272 | sdi->version = g_strdup(hw_info->firmware_version); | |
273 | sdi->serial_num = g_strdup(hw_info->serial_number); | |
274 | sdi->conn = scpi; | |
275 | sdi->driver = &scpi_dmm_driver_info; | |
276 | sdi->inst_type = SR_INST_SCPI; | |
277 | ret = sr_scpi_connection_id(scpi, &sdi->connection_id); | |
278 | if (ret != SR_OK) { | |
279 | g_free(sdi->connection_id); | |
280 | sdi->connection_id = NULL; | |
281 | } | |
282 | sr_scpi_hw_info_free(hw_info); | |
283 | if (model->read_timeout_us) /* non-default read timeout */ | |
284 | scpi->read_timeout_us = model->read_timeout_us; | |
285 | devc = g_malloc0(sizeof(*devc)); | |
286 | sdi->priv = devc; | |
287 | devc->num_channels = model->num_channels; | |
288 | devc->cmdset = model->cmdset; | |
289 | devc->model = model; | |
290 | ||
291 | for (i = 0; i < devc->num_channels; i++) { | |
292 | channel_name = g_strdup_printf("P%zu", i + 1); | |
293 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, channel_name); | |
294 | } | |
295 | ||
296 | /* | |
297 | * If device has DMM_CMD_SETUP_LOCAL command, send it now. To avoid | |
298 | * leaving device in remote mode (if only a "scan" is run). | |
299 | */ | |
300 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL); | |
301 | if (command && *command) { | |
302 | scpi_dmm_cmd_delay(scpi); | |
303 | sr_scpi_send(scpi, command); | |
304 | } | |
305 | ||
306 | return sdi; | |
307 | } | |
308 | ||
309 | static GSList *scan(struct sr_dev_driver *di, GSList *options) | |
310 | { | |
311 | return sr_scpi_scan(di->context, options, probe_device); | |
312 | } | |
313 | ||
314 | static int dev_open(struct sr_dev_inst *sdi) | |
315 | { | |
316 | struct sr_scpi_dev_inst *scpi; | |
317 | int ret; | |
318 | ||
319 | scpi = sdi->conn; | |
320 | ret = sr_scpi_open(scpi); | |
321 | if (ret < 0) { | |
322 | sr_err("Failed to open SCPI device: %s.", sr_strerror(ret)); | |
323 | return SR_ERR; | |
324 | } | |
325 | ||
326 | return SR_OK; | |
327 | } | |
328 | ||
329 | static int dev_close(struct sr_dev_inst *sdi) | |
330 | { | |
331 | struct dev_context *devc; | |
332 | struct sr_scpi_dev_inst *scpi; | |
333 | const char *command; | |
334 | ||
335 | devc = sdi->priv; | |
336 | scpi = sdi->conn; | |
337 | if (!scpi) | |
338 | return SR_ERR_BUG; | |
339 | ||
340 | sr_dbg("DIAG: sdi->status %d.", sdi->status - SR_ST_NOT_FOUND); | |
341 | if (sdi->status <= SR_ST_INACTIVE) | |
342 | return SR_OK; | |
343 | ||
344 | /* | |
345 | * If device has DMM_CMD_SETUP_LOCAL command, send it now | |
346 | * to avoid leaving device in remote mode. | |
347 | */ | |
348 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL); | |
349 | if (command && *command) { | |
350 | scpi_dmm_cmd_delay(scpi); | |
351 | sr_scpi_send(scpi, command); | |
352 | } | |
353 | ||
354 | return sr_scpi_close(scpi); | |
355 | } | |
356 | ||
357 | static int config_get(uint32_t key, GVariant **data, | |
358 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
359 | { | |
360 | struct dev_context *devc; | |
361 | enum sr_mq mq; | |
362 | enum sr_mqflag mqflag; | |
363 | GVariant *arr[2]; | |
364 | int ret; | |
365 | ||
366 | (void)cg; | |
367 | ||
368 | devc = sdi->priv; | |
369 | ||
370 | switch (key) { | |
371 | case SR_CONF_CONN: | |
372 | if (!sdi || !sdi->connection_id) | |
373 | return SR_ERR_NA; | |
374 | *data = g_variant_new_string(sdi->connection_id); | |
375 | return SR_OK; | |
376 | case SR_CONF_LIMIT_SAMPLES: | |
377 | case SR_CONF_LIMIT_MSEC: | |
378 | return sr_sw_limits_config_get(&devc->limits, key, data); | |
379 | case SR_CONF_MEASURED_QUANTITY: | |
380 | ret = scpi_dmm_get_mq(sdi, &mq, &mqflag, NULL, NULL); | |
381 | if (ret != SR_OK) | |
382 | return ret; | |
383 | arr[0] = g_variant_new_uint32(mq); | |
384 | arr[1] = g_variant_new_uint64(mqflag); | |
385 | *data = g_variant_new_tuple(arr, ARRAY_SIZE(arr)); | |
386 | return SR_OK; | |
387 | default: | |
388 | return SR_ERR_NA; | |
389 | } | |
390 | } | |
391 | ||
392 | static int config_set(uint32_t key, GVariant *data, | |
393 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
394 | { | |
395 | struct dev_context *devc; | |
396 | enum sr_mq mq; | |
397 | enum sr_mqflag mqflag; | |
398 | GVariant *tuple_child; | |
399 | ||
400 | (void)cg; | |
401 | ||
402 | devc = sdi->priv; | |
403 | ||
404 | switch (key) { | |
405 | case SR_CONF_LIMIT_SAMPLES: | |
406 | case SR_CONF_LIMIT_MSEC: | |
407 | return sr_sw_limits_config_set(&devc->limits, key, data); | |
408 | case SR_CONF_MEASURED_QUANTITY: | |
409 | tuple_child = g_variant_get_child_value(data, 0); | |
410 | mq = g_variant_get_uint32(tuple_child); | |
411 | g_variant_unref(tuple_child); | |
412 | tuple_child = g_variant_get_child_value(data, 1); | |
413 | mqflag = g_variant_get_uint64(tuple_child); | |
414 | g_variant_unref(tuple_child); | |
415 | return scpi_dmm_set_mq(sdi, mq, mqflag); | |
416 | default: | |
417 | return SR_ERR_NA; | |
418 | } | |
419 | } | |
420 | ||
421 | static int config_list(uint32_t key, GVariant **data, | |
422 | const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) | |
423 | { | |
424 | struct dev_context *devc; | |
425 | GVariant *gvar, *arr[2]; | |
426 | GVariantBuilder gvb; | |
427 | size_t i; | |
428 | ||
429 | (void)cg; | |
430 | ||
431 | devc = sdi ? sdi->priv : NULL; | |
432 | ||
433 | switch (key) { | |
434 | case SR_CONF_SCAN_OPTIONS: | |
435 | case SR_CONF_DEVICE_OPTIONS: | |
436 | if (!devc) | |
437 | return STD_CONFIG_LIST(key, data, sdi, cg, | |
438 | scanopts, drvopts, devopts_generic); | |
439 | return std_opts_config_list(key, data, sdi, cg, | |
440 | ARRAY_AND_SIZE(scanopts), ARRAY_AND_SIZE(drvopts), | |
441 | devc->model->devopts, devc->model->devopts_size); | |
442 | case SR_CONF_MEASURED_QUANTITY: | |
443 | /* TODO Use std_gvar_measured_quantities() when available. */ | |
444 | if (!devc) | |
445 | return SR_ERR_ARG; | |
446 | g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); | |
447 | for (i = 0; i < devc->model->mqopt_size; i++) { | |
448 | arr[0] = g_variant_new_uint32(devc->model->mqopts[i].mq); | |
449 | arr[1] = g_variant_new_uint64(devc->model->mqopts[i].mqflag); | |
450 | gvar = g_variant_new_tuple(arr, ARRAY_SIZE(arr)); | |
451 | g_variant_builder_add_value(&gvb, gvar); | |
452 | } | |
453 | *data = g_variant_builder_end(&gvb); | |
454 | return SR_OK; | |
455 | default: | |
456 | (void)devc; | |
457 | return SR_ERR_NA; | |
458 | } | |
459 | } | |
460 | ||
461 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) | |
462 | { | |
463 | struct sr_scpi_dev_inst *scpi; | |
464 | struct dev_context *devc; | |
465 | int ret; | |
466 | const struct mqopt_item *item; | |
467 | const char *command; | |
468 | char *response; | |
469 | ||
470 | scpi = sdi->conn; | |
471 | devc = sdi->priv; | |
472 | ||
473 | ret = scpi_dmm_get_mq(sdi, &devc->start_acq_mq.curr_mq, | |
474 | &devc->start_acq_mq.curr_mqflag, NULL, &item); | |
475 | if (ret != SR_OK) | |
476 | return ret; | |
477 | ||
478 | /* | |
479 | * Query for current precision if DMM supports the command | |
480 | */ | |
481 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_QUERY_PREC); | |
482 | if (command && *command) { | |
483 | scpi_dmm_cmd_delay(scpi); | |
484 | ret = sr_scpi_get_string(scpi, command, &response); | |
485 | if (ret == SR_OK) { | |
486 | g_strstrip(response); | |
487 | g_free(devc->precision); | |
488 | devc->precision = g_strdup(response); | |
489 | g_free(response); | |
490 | sr_dbg("%s: Precision: '%s'", __func__, devc->precision); | |
491 | } else { | |
492 | sr_info("Precision query ('%s') failed: %d", | |
493 | command, ret); | |
494 | } | |
495 | } | |
496 | ||
497 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_START_ACQ); | |
498 | if (command && *command) { | |
499 | scpi_dmm_cmd_delay(scpi); | |
500 | ret = sr_scpi_send(scpi, command); | |
501 | if (ret != SR_OK) | |
502 | return ret; | |
503 | } | |
504 | ||
505 | sr_sw_limits_acquisition_start(&devc->limits); | |
506 | ret = std_session_send_df_header(sdi); | |
507 | if (ret != SR_OK) | |
508 | return ret; | |
509 | ||
510 | ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10, | |
511 | scpi_dmm_receive_data, (void *)sdi); | |
512 | if (ret != SR_OK) | |
513 | return ret; | |
514 | ||
515 | return SR_OK; | |
516 | } | |
517 | ||
518 | static int dev_acquisition_stop(struct sr_dev_inst *sdi) | |
519 | { | |
520 | struct sr_scpi_dev_inst *scpi; | |
521 | struct dev_context *devc; | |
522 | const char *command; | |
523 | ||
524 | scpi = sdi->conn; | |
525 | devc = sdi->priv; | |
526 | ||
527 | command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_STOP_ACQ); | |
528 | if (command && *command) { | |
529 | scpi_dmm_cmd_delay(scpi); | |
530 | (void)sr_scpi_send(scpi, command); | |
531 | } | |
532 | sr_scpi_source_remove(sdi->session, scpi); | |
533 | ||
534 | std_session_send_df_end(sdi); | |
535 | ||
536 | g_free(devc->precision); | |
537 | devc->precision = NULL; | |
538 | ||
539 | return SR_OK; | |
540 | } | |
541 | ||
542 | static struct sr_dev_driver scpi_dmm_driver_info = { | |
543 | .name = "scpi-dmm", | |
544 | .longname = "SCPI DMM", | |
545 | .api_version = 1, | |
546 | .init = std_init, | |
547 | .cleanup = std_cleanup, | |
548 | .scan = scan, | |
549 | .dev_list = std_dev_list, | |
550 | .dev_clear = std_dev_clear, | |
551 | .config_get = config_get, | |
552 | .config_set = config_set, | |
553 | .config_list = config_list, | |
554 | .dev_open = dev_open, | |
555 | .dev_close = dev_close, | |
556 | .dev_acquisition_start = dev_acquisition_start, | |
557 | .dev_acquisition_stop = dev_acquisition_stop, | |
558 | .context = NULL, | |
559 | }; | |
560 | SR_REGISTER_DEV_DRIVER(scpi_dmm_driver_info); |