]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-pps/api.c
Change type of SR_CONF keys to uint32_t.
[libsigrok.git] / src / hardware / scpi-pps / api.c
CommitLineData
ca1a7cb5
BV
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
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
9e45cd41 20#include <string.h>
ca1a7cb5
BV
21#include "protocol.h"
22
23SR_PRIV struct sr_dev_driver scpi_pps_driver_info;
24static struct sr_dev_driver *di = &scpi_pps_driver_info;
d4eabea8
BV
25extern unsigned int num_pps_profiles;
26extern const struct scpi_pps pps_profiles[];
9e45cd41 27
584560f1 28static const uint32_t scanopts[] = {
9e45cd41
BV
29 SR_CONF_CONN,
30 SR_CONF_SERIALCOMM,
31};
ca1a7cb5 32
01b0257a
BV
33static struct pps_channel_instance pci[] = {
34 { SR_MQ_VOLTAGE, SCPI_CMD_GET_MEAS_VOLTAGE, "V" },
35 { SR_MQ_CURRENT, SCPI_CMD_GET_MEAS_CURRENT, "I" },
36 { SR_MQ_POWER, SCPI_CMD_GET_MEAS_POWER, "P" },
37};
38
ca1a7cb5
BV
39static int init(struct sr_context *sr_ctx)
40{
41 return std_init(sr_ctx, di, LOG_PREFIX);
42}
43
9e45cd41 44static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
ca1a7cb5 45{
9e45cd41
BV
46 struct dev_context *devc;
47 struct sr_dev_inst *sdi;
48 struct sr_scpi_hw_info *hw_info;
49 struct sr_channel_group *cg;
50 struct sr_channel *ch;
51 const struct scpi_pps *device;
01b0257a 52 struct pps_channel *pch;
9e45cd41
BV
53 const struct channel_group_spec *cgs;
54 struct pps_channel_group *pcg;
58b77c41
BV
55 GRegex *model_re;
56 GMatchInfo *model_mi;
01b0257a 57 GSList *l;
9e45cd41 58 uint64_t mask;
331f5654 59 unsigned int ch_num, ch_idx, i, j;
22c18b03 60 const char *vendor;
01b0257a 61 char ch_name[16];
9e45cd41
BV
62
63 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
64 sr_info("Couldn't get IDN response.");
65 return NULL;
66 }
67
68 device = NULL;
69 for (i = 0; i < num_pps_profiles; i++) {
22c18b03 70 vendor = get_vendor(hw_info->manufacturer);
58b77c41 71 if (strcasecmp(vendor, pps_profiles[i].vendor))
22c18b03 72 continue;
58b77c41
BV
73 model_re = g_regex_new(pps_profiles[i].model, 0, 0, NULL);
74 if (g_regex_match(model_re, hw_info->model, 0, &model_mi))
9e45cd41 75 device = &pps_profiles[i];
58b77c41
BV
76 g_match_info_unref(model_mi);
77 g_regex_unref(model_re);
78 if (device)
9e45cd41 79 break;
9e45cd41
BV
80 }
81 if (!device) {
82 sr_scpi_hw_info_free(hw_info);
83 return NULL;
84 }
85
58b77c41
BV
86 sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, vendor, hw_info->model,
87 hw_info->firmware_version);
9e45cd41
BV
88 sdi->conn = scpi;
89 sdi->driver = di;
90 sdi->inst_type = SR_INST_SCPI;
91 devc = g_malloc0(sizeof(struct dev_context));
92 devc->device = device;
93 sdi->priv = devc;
94
01b0257a
BV
95 ch_idx = 0;
96 for (ch_num = 0; ch_num < device->num_channels; ch_num++) {
97 /* Create one channel per measurable output unit. */
01b0257a
BV
98 for (i = 0; i < ARRAY_SIZE(pci); i++) {
99 if (!scpi_cmd_get(sdi, pci[i].command))
100 continue;
101 g_snprintf(ch_name, 16, "%s%s", pci[i].prefix,
102 device->channels[ch_num].name);
103 ch = sr_channel_new(ch_idx++, SR_CHANNEL_ANALOG, TRUE, ch_name);
104 pch = g_malloc0(sizeof(struct pps_channel));
105 pch->hw_output_idx = ch_num;
106 pch->hwname = device->channels[ch_num].name;
107 pch->mq = pci[i].mq;
108 ch->priv = pch;
109 sdi->channels = g_slist_append(sdi->channels, ch);
110 }
9e45cd41 111 }
ca1a7cb5 112
9e45cd41
BV
113 for (i = 0; i < device->num_channel_groups; i++) {
114 cgs = &device->channel_groups[i];
115 cg = g_malloc0(sizeof(struct sr_channel_group));
116 cg->name = g_strdup(cgs->name);
117 for (j = 0, mask = 1; j < 64; j++, mask <<= 1) {
118 if (cgs->channel_index_mask & mask) {
01b0257a
BV
119 for (l = sdi->channels; l; l = l->next) {
120 ch = l->data;
121 pch = ch->priv;
122 if (pch->hw_output_idx == j)
123 cg->channels = g_slist_append(cg->channels, ch);
124 }
9e45cd41
BV
125 }
126 }
127 pcg = g_malloc0(sizeof(struct pps_channel_group));
128 pcg->features = cgs->features;
129 cg->priv = pcg;
130 sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
131 }
ca1a7cb5 132
9e45cd41
BV
133 /* SCPI devices commonly lock the panel keys when accessed remotely. */
134 scpi_cmd(sdi, SCPI_CMD_KEY_UNLOCK);
135 sr_scpi_close(scpi);
ca1a7cb5 136
9e45cd41
BV
137 return sdi;
138}
ca1a7cb5 139
9e45cd41
BV
140static GSList *scan(GSList *options)
141{
142 return sr_scpi_scan(di->priv, options, probe_device);
ca1a7cb5
BV
143}
144
145static GSList *dev_list(void)
146{
147 return ((struct drv_context *)(di->priv))->instances;
148}
149
150static int dev_clear(void)
151{
152 return std_dev_clear(di, NULL);
153}
154
155static int dev_open(struct sr_dev_inst *sdi)
156{
9e45cd41
BV
157 struct sr_scpi_dev_inst *scpi;
158
159 if (sdi->status != SR_ST_ACTIVE)
160 return SR_ERR;
ca1a7cb5 161
9e45cd41
BV
162 scpi = sdi->conn;
163 if (sr_scpi_open(scpi) < 0)
164 return SR_ERR;
ca1a7cb5
BV
165
166 sdi->status = SR_ST_ACTIVE;
167
168 return SR_OK;
169}
170
171static int dev_close(struct sr_dev_inst *sdi)
172{
9e45cd41 173 struct sr_scpi_dev_inst *scpi;
ca1a7cb5 174
9e45cd41
BV
175 if (sdi->status != SR_ST_ACTIVE)
176 return SR_ERR_DEV_CLOSED;
ca1a7cb5 177
9e45cd41
BV
178 scpi = sdi->conn;
179 if (scpi) {
180 scpi_cmd(sdi, SCPI_CMD_KEY_UNLOCK);
181 sr_scpi_close(scpi);
182 sdi->status = SR_ST_INACTIVE;
183 }
ca1a7cb5
BV
184
185 return SR_OK;
186}
187
188static int cleanup(void)
189{
ca1a7cb5
BV
190 return SR_OK;
191}
192
584560f1 193static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
ca1a7cb5
BV
194 const struct sr_channel_group *cg)
195{
9e45cd41
BV
196 struct dev_context *devc;
197 struct sr_scpi_dev_inst *scpi;
198 struct sr_channel *ch;
01b0257a 199 struct pps_channel *pch;
478c8d92
BV
200 const GVariantType *gvtype;
201 unsigned int i;
202 int cmd, ret;
9e45cd41 203 char *s;
ca1a7cb5 204
9e45cd41
BV
205 if (!sdi)
206 return SR_ERR_ARG;
207
208 devc = sdi->priv;
209 scpi = sdi->conn;
ca1a7cb5 210
478c8d92 211 if (cg) {
9e45cd41
BV
212 /*
213 * These options only apply to channel groups with a single
214 * channel -- they're per-channel settings for the device.
215 */
478c8d92
BV
216
217 /*
218 * Config keys are handled below depending on whether a channel
219 * group was provided by the frontend. However some of these
220 * take a CG on one PPS but not on others. Check the device's
221 * profile for that here, and NULL out the channel group as needed.
222 */
223 for (i = 0; i < devc->device->num_devopts; i++) {
224 if (devc->device->devopts[i] == key) {
225 cg = NULL;
226 break;
227 }
228 }
229
9e45cd41 230 ch = cg->channels->data;
01b0257a 231 pch = ch->priv;
478c8d92 232 }
9e45cd41 233
478c8d92
BV
234 gvtype = NULL;
235 cmd = -1;
236 switch (key) {
237 case SR_CONF_OUTPUT_ENABLED:
238 gvtype = G_VARIANT_TYPE_BOOLEAN;
239 cmd = SCPI_CMD_GET_OUTPUT_ENABLED;
240 break;
241 case SR_CONF_OUTPUT_VOLTAGE:
242 gvtype = G_VARIANT_TYPE_DOUBLE;
243 cmd = SCPI_CMD_GET_MEAS_VOLTAGE;
244 break;
245 case SR_CONF_OUTPUT_VOLTAGE_MAX:
246 gvtype = G_VARIANT_TYPE_DOUBLE;
247 cmd = SCPI_CMD_GET_VOLTAGE_MAX;
248 break;
249 case SR_CONF_OUTPUT_CURRENT:
250 gvtype = G_VARIANT_TYPE_DOUBLE;
251 cmd = SCPI_CMD_GET_MEAS_CURRENT;
252 break;
253 case SR_CONF_OUTPUT_CURRENT_MAX:
254 gvtype = G_VARIANT_TYPE_DOUBLE;
255 cmd = SCPI_CMD_GET_CURRENT_MAX;
256 break;
257 case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
258 gvtype = G_VARIANT_TYPE_BOOLEAN;
259 cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED;
260 break;
261 case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE:
262 gvtype = G_VARIANT_TYPE_BOOLEAN;
263 cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE;
264 break;
265 case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD:
266 gvtype = G_VARIANT_TYPE_DOUBLE;
267 cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD;
268 break;
269 case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
270 gvtype = G_VARIANT_TYPE_BOOLEAN;
271 cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED;
272 break;
273 case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE:
274 gvtype = G_VARIANT_TYPE_BOOLEAN;
275 cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE;
276 break;
277 case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD:
278 gvtype = G_VARIANT_TYPE_DOUBLE;
279 cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD;
280 break;
281 case SR_CONF_OVER_TEMPERATURE_PROTECTION:
282 gvtype = G_VARIANT_TYPE_BOOLEAN;
283 cmd = SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION;
284 break;
285 }
286 if (gvtype) {
287 if (cg)
01b0257a 288 ret = scpi_cmd_resp(sdi, data, gvtype, cmd, pch->hwname);
478c8d92
BV
289 else
290 ret = scpi_cmd_resp(sdi, data, gvtype, cmd);
291 } else if (cg) {
9e45cd41
BV
292 switch (key) {
293 case SR_CONF_OUTPUT_REGULATION:
294 ret = SR_ERR;
01b0257a 295 if (scpi_cmd(sdi, SCPI_CMD_GET_OUTPUT_REGULATION, pch->hwname) == SR_OK) {
9e45cd41
BV
296 if (sr_scpi_get_string(scpi, NULL, &s) == SR_OK) {
297 if (strcmp(s, "CC") && strcmp(s, "CV") && strcmp(s, "UR")) {
298 sr_dbg("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s);
299 } else {
300 *data = g_variant_new_string(s);
301 g_free(s);
302 ret = SR_OK;
303 }
304 }
305 }
306 break;
9e45cd41 307 default:
478c8d92 308 ret = SR_ERR_NA;
9e45cd41 309 }
478c8d92
BV
310 } else
311 ret = SR_ERR_NA;
ca1a7cb5
BV
312
313 return ret;
314}
315
584560f1 316static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
ca1a7cb5
BV
317 const struct sr_channel_group *cg)
318{
9e45cd41 319 struct sr_channel *ch;
01b0257a 320 struct pps_channel *pch;
9e45cd41 321 double d;
ca1a7cb5 322 int ret;
9e45cd41 323 const char *s;
ca1a7cb5 324
fdedbfcd
BV
325 if (!sdi)
326 return SR_ERR_ARG;
327
ca1a7cb5
BV
328 if (sdi->status != SR_ST_ACTIVE)
329 return SR_ERR_DEV_CLOSED;
330
331 ret = SR_OK;
9e45cd41
BV
332 if (!cg) {
333 switch (key) {
334 /* No channel group: global options. */
478c8d92 335 case SR_CONF_OUTPUT_ENABLED:
9e45cd41 336 s = g_variant_get_boolean(data) ? "ON" : "OFF";
478c8d92 337 ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_ENABLED, s);
9e45cd41 338 break;
478c8d92
BV
339 case SR_CONF_OUTPUT_VOLTAGE_MAX:
340 d = g_variant_get_double(data);
341 ret = scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_MAX, d);
342 break;
343 case SR_CONF_OUTPUT_CURRENT_MAX:
344 d = g_variant_get_double(data);
345 ret = scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_MAX, d);
346 break;
347 case SR_CONF_OVER_TEMPERATURE_PROTECTION:
348 s = g_variant_get_boolean(data) ? "ON" : "OFF";
349 ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION, s);
9e45cd41
BV
350 break;
351 default:
352 ret = SR_ERR_NA;
353 }
354 } else {
355 /* Channel group specified. */
9e45cd41 356 ch = cg->channels->data;
01b0257a 357 pch = ch->priv;
9e45cd41 358 switch (key) {
478c8d92
BV
359 case SR_CONF_OUTPUT_ENABLED:
360 s = g_variant_get_boolean(data) ? "ON" : "OFF";
01b0257a 361 ret = scpi_cmd(sdi, SCPI_CMD_SET_OUTPUT_ENABLED, pch->hwname, s);
478c8d92 362 break;
9e45cd41
BV
363 case SR_CONF_OUTPUT_VOLTAGE_MAX:
364 d = g_variant_get_double(data);
01b0257a 365 ret = scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_MAX, pch->hwname, d);
9e45cd41
BV
366 break;
367 case SR_CONF_OUTPUT_CURRENT_MAX:
368 d = g_variant_get_double(data);
01b0257a 369 ret = scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_MAX, pch->hwname, d);
9e45cd41
BV
370 break;
371 case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
372 s = g_variant_get_boolean(data) ? "ON" : "OFF";
478c8d92 373 ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLED,
01b0257a 374 pch->hwname, s);
9e45cd41
BV
375 break;
376 case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD:
377 d = g_variant_get_double(data);
478c8d92 378 ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD,
01b0257a 379 pch->hwname, d);
9e45cd41
BV
380 break;
381 case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
382 s = g_variant_get_boolean(data) ? "ON" : "OFF";
478c8d92 383 ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLED,
01b0257a 384 pch->hwname, s);
9e45cd41
BV
385 break;
386 case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD:
387 d = g_variant_get_double(data);
478c8d92 388 ret = scpi_cmd(sdi, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD,
01b0257a 389 pch->hwname, d);
9e45cd41
BV
390 break;
391 default:
392 ret = SR_ERR_NA;
393 }
ca1a7cb5
BV
394 }
395
396 return ret;
397}
398
584560f1 399static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
ca1a7cb5
BV
400 const struct sr_channel_group *cg)
401{
9e45cd41
BV
402 struct dev_context *devc;
403 struct sr_channel *ch;
404 struct channel_spec *ch_spec;
405 GVariant *gvar;
406 GVariantBuilder gvb;
407 int ret, i;
408 const char *s[16];
409
410 /* Always available, even without sdi. */
411 if (key == SR_CONF_SCAN_OPTIONS) {
584560f1
BV
412 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
413 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
9e45cd41
BV
414 return SR_OK;
415 }
ca1a7cb5 416
9e45cd41
BV
417 if (!sdi)
418 return SR_ERR_ARG;
419 devc = sdi->priv;
ca1a7cb5
BV
420
421 ret = SR_OK;
9e45cd41
BV
422 if (!cg) {
423 /* No channel group: global options. */
424 switch (key) {
425 case SR_CONF_DEVICE_OPTIONS:
584560f1 426 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
9e45cd41 427 devc->device->devopts, devc->device->num_devopts,
584560f1 428 sizeof(uint32_t));
9e45cd41
BV
429 break;
430 case SR_CONF_OUTPUT_CHANNEL_CONFIG:
478c8d92 431 /* Not used. */
9e45cd41
BV
432 i = 0;
433 if (devc->device->features & PPS_INDEPENDENT)
434 s[i++] = "Independent";
435 if (devc->device->features & PPS_SERIES)
436 s[i++] = "Series";
437 if (devc->device->features & PPS_PARALLEL)
438 s[i++] = "Parallel";
439 if (i == 0) {
440 /*
441 * Shouldn't happen: independent-only devices
442 * shouldn't advertise this option at all.
443 */
444 return SR_ERR_NA;
445 }
446 *data = g_variant_new_strv(s, i);
447 break;
448 default:
449 return SR_ERR_NA;
450 }
451 } else {
452 /* Channel group specified. */
9e45cd41
BV
453 /*
454 * Per-channel-group options depending on a channel are actually
455 * done with the first channel. Channel groups in PPS can have
456 * more than one channel, but they will typically be of equal
01b0257a 457 * specification for use in series or parallel mode.
9e45cd41 458 */
9e45cd41
BV
459 ch = cg->channels->data;
460
461 switch (key) {
462 case SR_CONF_DEVICE_OPTIONS:
584560f1 463 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
9e45cd41 464 devc->device->devopts_cg, devc->device->num_devopts_cg,
584560f1 465 sizeof(uint32_t));
9e45cd41
BV
466 break;
467 case SR_CONF_OUTPUT_VOLTAGE_MAX:
468 ch_spec = &(devc->device->channels[ch->index]);
469 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
470 /* Min, max, write resolution. */
471 for (i = 0; i < 3; i++) {
472 gvar = g_variant_new_double(ch_spec->voltage[i]);
473 g_variant_builder_add_value(&gvb, gvar);
474 }
475 *data = g_variant_builder_end(&gvb);
476 break;
477 case SR_CONF_OUTPUT_CURRENT_MAX:
478 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
479 /* Min, max, step. */
480 for (i = 0; i < 3; i++) {
481 ch_spec = &(devc->device->channels[ch->index]);
482 gvar = g_variant_new_double(ch_spec->current[i]);
483 g_variant_builder_add_value(&gvb, gvar);
484 }
485 *data = g_variant_builder_end(&gvb);
486 break;
487 default:
488 return SR_ERR_NA;
489 }
ca1a7cb5
BV
490 }
491
492 return ret;
493}
494
495static int dev_acquisition_start(const struct sr_dev_inst *sdi,
9e45cd41 496 void *cb_data)
ca1a7cb5 497{
9e45cd41
BV
498 struct dev_context *devc;
499 struct sr_scpi_dev_inst *scpi;
500 struct sr_channel *ch;
01b0257a
BV
501 struct pps_channel *pch;
502 int cmd, ret;
ca1a7cb5
BV
503
504 if (sdi->status != SR_ST_ACTIVE)
505 return SR_ERR_DEV_CLOSED;
506
9e45cd41
BV
507 devc = sdi->priv;
508 scpi = sdi->conn;
509 devc->cb_data = cb_data;
510
01b0257a 511 if ((ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10,
9e45cd41
BV
512 scpi_pps_receive_data, (void *)sdi)) != SR_OK)
513 return ret;
514 std_session_send_df_header(sdi, LOG_PREFIX);
515
01b0257a 516 /* Prime the pipe with the first channel's fetch. */
9e45cd41 517 ch = sdi->channels->data;
01b0257a 518 pch = ch->priv;
9e45cd41 519 devc->cur_channel = ch;
01b0257a
BV
520 if (pch->mq == SR_MQ_VOLTAGE)
521 cmd = SCPI_CMD_GET_MEAS_VOLTAGE;
522 else if (pch->mq == SR_MQ_CURRENT)
523 cmd = SCPI_CMD_GET_MEAS_CURRENT;
524 else if (pch->mq == SR_MQ_POWER)
525 cmd = SCPI_CMD_GET_MEAS_POWER;
526 else
527 return SR_ERR;
528 scpi_cmd(sdi, cmd, pch->hwname);
ca1a7cb5
BV
529
530 return SR_OK;
531}
532
533static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
534{
9e45cd41
BV
535 struct sr_scpi_dev_inst *scpi;
536 float f;
537
ca1a7cb5
BV
538 (void)cb_data;
539
540 if (sdi->status != SR_ST_ACTIVE)
541 return SR_ERR_DEV_CLOSED;
542
9e45cd41
BV
543 scpi = sdi->conn;
544
545 /*
546 * A requested value is certainly on the way. Retrieve it now,
547 * to avoid leaving the device in a state where it's not expecting
548 * commands.
549 */
550 sr_scpi_get_float(scpi, NULL, &f);
551 sr_scpi_source_remove(sdi->session, scpi);
552
ca1a7cb5
BV
553 return SR_OK;
554}
555
556SR_PRIV struct sr_dev_driver scpi_pps_driver_info = {
557 .name = "scpi-pps",
558 .longname = "SCPI PPS",
559 .api_version = 1,
560 .init = init,
561 .cleanup = cleanup,
562 .scan = scan,
563 .dev_list = dev_list,
564 .dev_clear = dev_clear,
565 .config_get = config_get,
566 .config_set = config_set,
567 .config_list = config_list,
568 .dev_open = dev_open,
569 .dev_close = dev_close,
570 .dev_acquisition_start = dev_acquisition_start,
571 .dev_acquisition_stop = dev_acquisition_stop,
572 .priv = NULL,
573};