]> sigrok.org Git - libsigrok.git/blame - src/hardware/yokogawa-dlm/api.c
sr_dev_close(): Factor out SR_ERR_DEV_CLOSED check.
[libsigrok.git] / src / hardware / yokogawa-dlm / api.c
CommitLineData
10763937
SA
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 abraxa (Soeren Apel) <soeren@apelpie.net>
5 * Based on the Hameg HMO driver by poljar (Damir Jelić) <poljarinho@gmail.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
6ec6c43b 21#include <config.h>
10763937 22#include <stdlib.h>
5a1afc09 23#include "scpi.h"
10763937
SA
24#include "protocol.h"
25
dd5c48a6 26static struct sr_dev_driver yokogawa_dlm_driver_info;
8ab929d6 27
329733d9
UH
28static const char *MANUFACTURER_ID = "YOKOGAWA";
29static const char *MANUFACTURER_NAME = "Yokogawa";
8ab929d6 30
f3c60fb6
SA
31static const uint32_t dlm_scanopts[] = {
32 SR_CONF_CONN,
33};
34
35static const uint32_t dlm_drvopts[] = {
cf0280fa
AJ
36 SR_CONF_LOGIC_ANALYZER,
37 SR_CONF_OSCILLOSCOPE,
38};
39
f3c60fb6
SA
40static const uint32_t dlm_devopts[] = {
41 SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
42 SR_CONF_SAMPLERATE | SR_CONF_GET,
43 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
44 SR_CONF_NUM_HDIV | SR_CONF_GET,
45 SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET,
f3c60fb6 46 SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
86621306 47 SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
f3c60fb6
SA
48};
49
50static const uint32_t dlm_analog_devopts[] = {
f3c60fb6 51 SR_CONF_NUM_VDIV | SR_CONF_GET,
86621306
UH
52 SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
53 SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
f3c60fb6
SA
54};
55
56static const uint32_t dlm_digital_devopts[] = {
57};
58
8ab929d6
SA
59enum {
60 CG_INVALID = -1,
61 CG_NONE,
62 CG_ANALOG,
63 CG_DIGITAL,
64};
65
8ab929d6
SA
66static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi)
67{
68 struct sr_dev_inst *sdi;
69 struct dev_context *devc;
70 struct sr_scpi_hw_info *hw_info;
71 char *model_name;
72 int model_index;
73
74 sdi = NULL;
75 devc = NULL;
76 hw_info = NULL;
77
78 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
79 sr_info("Couldn't get IDN response.");
80 goto fail;
81 }
82
83 if (strcmp(hw_info->manufacturer, MANUFACTURER_ID) != 0)
84 goto fail;
85
86 if (dlm_model_get(hw_info->model, &model_name, &model_index) != SR_OK)
87 goto fail;
88
aac29cc1 89 sdi = g_malloc0(sizeof(struct sr_dev_inst));
0af636be
UH
90 sdi->vendor = g_strdup(MANUFACTURER_NAME);
91 sdi->model = g_strdup(model_name);
92 sdi->version = g_strdup(hw_info->firmware_version);
8ab929d6 93
d1314831
SA
94 sdi->serial_num = g_strdup(hw_info->serial_number);
95
8ab929d6
SA
96 sr_scpi_hw_info_free(hw_info);
97 hw_info = NULL;
98
ac10a927 99 devc = g_malloc0(sizeof(struct dev_context));
8ab929d6 100
4f840ce9 101 sdi->driver = &yokogawa_dlm_driver_info;
8ab929d6
SA
102 sdi->priv = devc;
103 sdi->inst_type = SR_INST_SCPI;
104 sdi->conn = scpi;
105
106 if (dlm_device_init(sdi, model_index) != SR_OK)
107 goto fail;
108
8ab929d6
SA
109 return sdi;
110
111fail:
7b365c47 112 sr_scpi_hw_info_free(hw_info);
4bf93988 113 sr_dev_inst_free(sdi);
b1f83103 114 g_free(devc);
8ab929d6
SA
115
116 return NULL;
117}
118
4f840ce9 119static GSList *scan(struct sr_dev_driver *di, GSList *options)
8ab929d6 120{
41812aca 121 return sr_scpi_scan(di->context, options, probe_usbtmc_device);
8ab929d6
SA
122}
123
8ab929d6
SA
124static void clear_helper(void *priv)
125{
126 struct dev_context *devc;
127
128 devc = priv;
129
130 dlm_scope_state_destroy(devc->model_state);
131
132 g_free(devc->analog_groups);
133 g_free(devc->digital_groups);
134 g_free(devc);
135}
136
4f840ce9 137static int dev_clear(const struct sr_dev_driver *di)
8ab929d6
SA
138{
139 return std_dev_clear(di, clear_helper);
140}
141
142static int dev_open(struct sr_dev_inst *sdi)
143{
144 if (sdi->status != SR_ST_ACTIVE && sr_scpi_open(sdi->conn) != SR_OK)
145 return SR_ERR;
146
147 if (dlm_scope_state_query(sdi) != SR_OK)
148 return SR_ERR;
149
150 sdi->status = SR_ST_ACTIVE;
151
152 return SR_OK;
153}
154
155static int dev_close(struct sr_dev_inst *sdi)
156{
8ab929d6
SA
157 sr_scpi_close(sdi->conn);
158
159 sdi->status = SR_ST_INACTIVE;
160
161 return SR_OK;
162}
163
8ab929d6
SA
164/**
165 * Check which category a given channel group belongs to.
166 *
167 * @param devc Our internal device context.
a9308652 168 * @param cg The channel group to check.
8ab929d6 169 *
a9308652
UH
170 * @retval CG_NONE cg is NULL
171 * @retval CG_ANALOG cg is an analog group
8ab929d6
SA
172 * @retval CG_DIGITAL cg is a digital group
173 * @retval CG_INVALID cg is something else
174 */
175static int check_channel_group(struct dev_context *devc,
ac10a927 176 const struct sr_channel_group *cg)
8ab929d6
SA
177{
178 unsigned int i;
329733d9 179 const struct scope_config *model;
8ab929d6
SA
180
181 model = devc->model_config;
182
183 if (!cg)
184 return CG_NONE;
185
a9308652 186 for (i = 0; i < model->analog_channels; i++)
8ab929d6
SA
187 if (cg == devc->analog_groups[i])
188 return CG_ANALOG;
189
a9308652 190 for (i = 0; i < model->pods; i++)
8ab929d6
SA
191 if (cg == devc->digital_groups[i])
192 return CG_DIGITAL;
193
194 sr_err("Invalid channel group specified.");
195 return CG_INVALID;
196}
197
584560f1 198static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
ac10a927 199 const struct sr_channel_group *cg)
8ab929d6
SA
200{
201 int ret, cg_type;
202 unsigned int i;
203 struct dev_context *devc;
329733d9 204 const struct scope_config *model;
8ab929d6
SA
205 struct scope_state *state;
206
709468ba 207 if (!sdi)
8ab929d6
SA
208 return SR_ERR_ARG;
209
709468ba
UH
210 devc = sdi->priv;
211
8ab929d6
SA
212 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
213 return SR_ERR;
214
8ab929d6
SA
215 model = devc->model_config;
216 state = devc->model_state;
217
218 switch (key) {
bf622e6d 219 case SR_CONF_NUM_HDIV:
8ab929d6
SA
220 *data = g_variant_new_int32(model->num_xdivs);
221 ret = SR_OK;
222 break;
223 case SR_CONF_TIMEBASE:
224 *data = g_variant_new("(tt)",
f3c60fb6
SA
225 dlm_timebases[state->timebase][0],
226 dlm_timebases[state->timebase][1]);
8ab929d6
SA
227 ret = SR_OK;
228 break;
229 case SR_CONF_NUM_VDIV:
230 if (cg_type == CG_NONE) {
231 sr_err("No channel group specified.");
232 return SR_ERR_CHANNEL_GROUP;
233 } else if (cg_type == CG_ANALOG) {
234 *data = g_variant_new_int32(model->num_ydivs);
235 ret = SR_OK;
236 break;
237 } else {
238 ret = SR_ERR_NA;
239 }
240 break;
241 case SR_CONF_VDIV:
242 ret = SR_ERR_NA;
243 if (cg_type == CG_NONE) {
244 sr_err("No channel group specified.");
245 return SR_ERR_CHANNEL_GROUP;
246 } else if (cg_type != CG_ANALOG)
247 break;
248
a9308652 249 for (i = 0; i < model->analog_channels; i++) {
8ab929d6
SA
250 if (cg != devc->analog_groups[i])
251 continue;
252 *data = g_variant_new("(tt)",
f3c60fb6
SA
253 dlm_vdivs[state->analog_states[i].vdiv][0],
254 dlm_vdivs[state->analog_states[i].vdiv][1]);
8ab929d6
SA
255 ret = SR_OK;
256 break;
257 }
258 break;
259 case SR_CONF_TRIGGER_SOURCE:
260 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
261 ret = SR_OK;
262 break;
263 case SR_CONF_TRIGGER_SLOPE:
f3c60fb6 264 *data = g_variant_new_string(dlm_trigger_slopes[state->trigger_slope]);
8ab929d6
SA
265 ret = SR_OK;
266 break;
267 case SR_CONF_HORIZ_TRIGGERPOS:
268 *data = g_variant_new_double(state->horiz_triggerpos);
269 ret = SR_OK;
270 break;
271 case SR_CONF_COUPLING:
272 ret = SR_ERR_NA;
273 if (cg_type == CG_NONE) {
274 sr_err("No channel group specified.");
275 return SR_ERR_CHANNEL_GROUP;
276 } else if (cg_type != CG_ANALOG)
277 break;
278
a9308652 279 for (i = 0; i < model->analog_channels; i++) {
8ab929d6
SA
280 if (cg != devc->analog_groups[i])
281 continue;
282 *data = g_variant_new_string((*model->coupling_options)[state->analog_states[i].coupling]);
283 ret = SR_OK;
284 break;
285 }
286 break;
287 case SR_CONF_SAMPLERATE:
288 *data = g_variant_new_uint64(state->sample_rate);
289 ret = SR_OK;
290 break;
291 default:
292 ret = SR_ERR_NA;
293 }
294
295 return ret;
296}
297
298static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
299{
300 unsigned int i;
301 GVariant *rational[2];
302 GVariantBuilder gvb;
303
304 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
305
306 for (i = 0; i < n; i++) {
307 rational[0] = g_variant_new_uint64((*array)[i][0]);
308 rational[1] = g_variant_new_uint64((*array)[i][1]);
309
310 /* FIXME: Valgrind reports a memory leak here. */
311 g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
312 }
313
314 return g_variant_builder_end(&gvb);
315}
316
584560f1 317static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
ac10a927 318 const struct sr_channel_group *cg)
8ab929d6
SA
319{
320 int ret, cg_type;
321 unsigned int i, j;
322 char float_str[30];
323 struct dev_context *devc;
329733d9 324 const struct scope_config *model;
8ab929d6
SA
325 struct scope_state *state;
326 const char *tmp;
327 uint64_t p, q;
328 double tmp_d;
329 gboolean update_sample_rate;
330
331 if (!sdi || !(devc = sdi->priv))
332 return SR_ERR_ARG;
333
334 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
335 return SR_ERR;
336
337 model = devc->model_config;
338 state = devc->model_state;
339 update_sample_rate = FALSE;
340
341 ret = SR_ERR_NA;
342
343 switch (key) {
344 case SR_CONF_LIMIT_FRAMES:
345 devc->frame_limit = g_variant_get_uint64(data);
346 ret = SR_OK;
347 break;
348 case SR_CONF_TRIGGER_SOURCE:
349 tmp = g_variant_get_string(data, NULL);
350 for (i = 0; (*model->trigger_sources)[i]; i++) {
351 if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
352 continue;
353 state->trigger_source = i;
354 /* TODO: A and B trigger support possible? */
355 ret = dlm_trigger_source_set(sdi->conn, (*model->trigger_sources)[i]);
356 break;
357 }
358 break;
359 case SR_CONF_VDIV:
360 if (cg_type == CG_NONE) {
361 sr_err("No channel group specified.");
362 return SR_ERR_CHANNEL_GROUP;
363 }
364
365 g_variant_get(data, "(tt)", &p, &q);
366
f3c60fb6
SA
367 for (i = 0; i < ARRAY_SIZE(dlm_vdivs); i++) {
368 if (p != dlm_vdivs[i][0] ||
369 q != dlm_vdivs[i][1])
8ab929d6 370 continue;
a9308652 371 for (j = 1; j <= model->analog_channels; j++) {
8ab929d6
SA
372 if (cg != devc->analog_groups[j - 1])
373 continue;
374 state->analog_states[j - 1].vdiv = i;
375 g_ascii_formatd(float_str, sizeof(float_str),
376 "%E", (float) p / q);
377 if (dlm_analog_chan_vdiv_set(sdi->conn, j, float_str) != SR_OK ||
ac10a927 378 sr_scpi_get_opc(sdi->conn) != SR_OK)
8ab929d6
SA
379 return SR_ERR;
380
381 break;
382 }
383
384 ret = SR_OK;
385 break;
386 }
387 break;
388 case SR_CONF_TIMEBASE:
389 g_variant_get(data, "(tt)", &p, &q);
390
f3c60fb6
SA
391 for (i = 0; i < ARRAY_SIZE(dlm_timebases); i++) {
392 if (p != dlm_timebases[i][0] ||
393 q != dlm_timebases[i][1])
8ab929d6
SA
394 continue;
395 state->timebase = i;
396 g_ascii_formatd(float_str, sizeof(float_str),
397 "%E", (float) p / q);
398 ret = dlm_timebase_set(sdi->conn, float_str);
399 update_sample_rate = TRUE;
400 break;
401 }
402 break;
403 case SR_CONF_HORIZ_TRIGGERPOS:
404 tmp_d = g_variant_get_double(data);
405
406 /* TODO: Check if the calculation makes sense for the DLM. */
407 if (tmp_d < 0.0 || tmp_d > 1.0)
408 return SR_ERR;
409
410 state->horiz_triggerpos = tmp_d;
411 tmp_d = -(tmp_d - 0.5) *
f3c60fb6
SA
412 ((double) dlm_timebases[state->timebase][0] /
413 dlm_timebases[state->timebase][1])
ac10a927 414 * model->num_xdivs;
8ab929d6
SA
415
416 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
417 ret = dlm_horiz_trigger_pos_set(sdi->conn, float_str);
418 break;
419 case SR_CONF_TRIGGER_SLOPE:
420 tmp = g_variant_get_string(data, NULL);
421
422 if (!tmp || !(tmp[0] == 'f' || tmp[0] == 'r'))
423 return SR_ERR_ARG;
424
425 /* Note: See dlm_trigger_slopes[] in protocol.c. */
426 state->trigger_slope = (tmp[0] == 'r') ?
427 SLOPE_POSITIVE : SLOPE_NEGATIVE;
428
429 ret = dlm_trigger_slope_set(sdi->conn, state->trigger_slope);
430 break;
431 case SR_CONF_COUPLING:
432 if (cg_type == CG_NONE) {
433 sr_err("No channel group specified.");
434 return SR_ERR_CHANNEL_GROUP;
435 }
436
437 tmp = g_variant_get_string(data, NULL);
438
439 for (i = 0; (*model->coupling_options)[i]; i++) {
440 if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
441 continue;
a9308652 442 for (j = 1; j <= model->analog_channels; j++) {
8ab929d6
SA
443 if (cg != devc->analog_groups[j - 1])
444 continue;
445 state->analog_states[j-1].coupling = i;
446
447 if (dlm_analog_chan_coupl_set(sdi->conn, j, tmp) != SR_OK ||
ac10a927 448 sr_scpi_get_opc(sdi->conn) != SR_OK)
8ab929d6
SA
449 return SR_ERR;
450 break;
451 }
452
453 ret = SR_OK;
454 break;
455 }
456 break;
457 default:
458 ret = SR_ERR_NA;
459 break;
460 }
461
462 if (ret == SR_OK)
463 ret = sr_scpi_get_opc(sdi->conn);
464
465 if (ret == SR_OK && update_sample_rate)
466 ret = dlm_sample_rate_query(sdi);
467
468 return ret;
469}
470
c65a021c
SA
471static int config_channel_set(const struct sr_dev_inst *sdi,
472 struct sr_channel *ch, unsigned int changes)
473{
a9308652 474 /* Currently we only handle SR_CHANNEL_SET_ENABLED. */
c65a021c
SA
475 if (changes != SR_CHANNEL_SET_ENABLED)
476 return SR_ERR_NA;
477
478 return dlm_channel_state_set(sdi, ch->index, ch->enabled);
479}
480
584560f1 481static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
ac10a927 482 const struct sr_channel_group *cg)
8ab929d6 483{
cf0280fa
AJ
484 int cg_type = CG_NONE;
485 struct dev_context *devc = NULL;
329733d9 486 const struct scope_config *model = NULL;
8ab929d6 487
9a512113 488 /* SR_CONF_SCAN_OPTIONS is always valid, regardless of sdi or channel group. */
f3c60fb6
SA
489 if (key == SR_CONF_SCAN_OPTIONS) {
490 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
491 dlm_scanopts, ARRAY_SIZE(dlm_scanopts), sizeof(uint32_t));
492 return SR_OK;
493 }
8ab929d6 494
f3c60fb6
SA
495 /* If sdi is NULL, nothing except SR_CONF_DEVICE_OPTIONS can be provided. */
496 if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
497 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
498 dlm_drvopts, ARRAY_SIZE(dlm_drvopts), sizeof(uint32_t));
499 return SR_OK;
cf0280fa 500 }
8ab929d6 501
f3c60fb6
SA
502 if (!sdi)
503 return SR_ERR_ARG;
504
505 devc = sdi->priv;
506 model = devc->model_config;
507
a9308652
UH
508 /*
509 * If cg is NULL, only the SR_CONF_DEVICE_OPTIONS that are not
9a512113 510 * specific to a channel group must be returned.
a9308652 511 */
f3c60fb6
SA
512 if (!cg) {
513 switch (key) {
514 case SR_CONF_DEVICE_OPTIONS:
515 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
516 dlm_devopts, ARRAY_SIZE(dlm_devopts), sizeof(uint32_t));
517 return SR_OK;
518 case SR_CONF_TIMEBASE:
519 *data = build_tuples(&dlm_timebases, ARRAY_SIZE(dlm_timebases));
520 return SR_OK;
521 case SR_CONF_TRIGGER_SOURCE:
522 if (!model)
523 return SR_ERR_ARG;
524 *data = g_variant_new_strv(*model->trigger_sources,
525 g_strv_length((char **)*model->trigger_sources));
526 return SR_OK;
527 case SR_CONF_TRIGGER_SLOPE:
528 *data = g_variant_new_strv(dlm_trigger_slopes,
529 g_strv_length((char **)dlm_trigger_slopes));
530 return SR_OK;
531 case SR_CONF_NUM_HDIV:
49f49cb5 532 *data = g_variant_new_uint32(model->num_xdivs);
f3c60fb6
SA
533 return SR_OK;
534 default:
535 return SR_ERR_NA;
536 }
537 }
538
539 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
540 return SR_ERR;
541
8ab929d6 542 switch (key) {
8ab929d6 543 case SR_CONF_DEVICE_OPTIONS:
f3c60fb6 544 if (cg_type == CG_ANALOG) {
584560f1 545 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
f3c60fb6
SA
546 dlm_analog_devopts, ARRAY_SIZE(dlm_analog_devopts), sizeof(uint32_t));
547 } else if (cg_type == CG_DIGITAL) {
548 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
549 dlm_digital_devopts, ARRAY_SIZE(dlm_digital_devopts), sizeof(uint32_t));
8ab929d6 550 } else {
584560f1
BV
551 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
552 NULL, 0, sizeof(uint32_t));
8ab929d6
SA
553 }
554 break;
555 case SR_CONF_COUPLING:
556 if (cg_type == CG_NONE)
557 return SR_ERR_CHANNEL_GROUP;
558 *data = g_variant_new_strv(*model->coupling_options,
ac10a927 559 g_strv_length((char **)*model->coupling_options));
8ab929d6 560 break;
8ab929d6
SA
561 case SR_CONF_VDIV:
562 if (cg_type == CG_NONE)
563 return SR_ERR_CHANNEL_GROUP;
f3c60fb6 564 *data = build_tuples(&dlm_vdivs, ARRAY_SIZE(dlm_vdivs));
8ab929d6
SA
565 break;
566 default:
567 return SR_ERR_NA;
568 }
569
570 return SR_OK;
571}
572
573static int dlm_check_channels(GSList *channels)
574{
575 GSList *l;
576 struct sr_channel *ch;
577 gboolean enabled_pod1, enabled_chan4;
578
579 enabled_pod1 = enabled_chan4 = FALSE;
580
581 /* Note: On the DLM2000, CH4 and Logic are shared. */
582 /* TODO Handle non-DLM2000 models. */
583 for (l = channels; l; l = l->next) {
584 ch = l->data;
585 switch (ch->type) {
586 case SR_CHANNEL_ANALOG:
587 if (ch->index == 3)
588 enabled_chan4 = TRUE;
589 break;
590 case SR_CHANNEL_LOGIC:
591 enabled_pod1 = TRUE;
592 break;
593 default:
594 return SR_ERR;
595 }
596 }
597
598 if (enabled_pod1 && enabled_chan4)
599 return SR_ERR;
600
601 return SR_OK;
602}
603
695dc859 604static int dev_acquisition_start(const struct sr_dev_inst *sdi)
8ab929d6
SA
605{
606 GSList *l;
607 gboolean digital_added;
608 struct sr_channel *ch;
609 struct dev_context *devc;
610 struct sr_scpi_dev_inst *scpi;
611
8ab929d6
SA
612 scpi = sdi->conn;
613 devc = sdi->priv;
614 digital_added = FALSE;
615
616 g_slist_free(devc->enabled_channels);
617 devc->enabled_channels = NULL;
618
619 for (l = sdi->channels; l; l = l->next) {
620 ch = l->data;
621 if (!ch->enabled)
622 continue;
623 /* Only add a single digital channel. */
624 if (ch->type != SR_CHANNEL_LOGIC || !digital_added) {
625 devc->enabled_channels = g_slist_append(
ac10a927
SA
626 devc->enabled_channels, ch);
627 if (ch->type == SR_CHANNEL_LOGIC)
628 digital_added = TRUE;
8ab929d6
SA
629 }
630 }
631
632 if (!devc->enabled_channels)
633 return SR_ERR;
634
635 if (dlm_check_channels(devc->enabled_channels) != SR_OK) {
636 sr_err("Invalid channel configuration specified!");
637 return SR_ERR_NA;
638 }
639
af3487ec
SA
640 /* Request data for the first enabled channel. */
641 devc->current_channel = devc->enabled_channels;
642 dlm_channel_data_request(sdi);
643
0028d5a1
SA
644 /* Call our callback when data comes in or after 5ms. */
645 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 5,
8ab929d6
SA
646 dlm_data_receive, (void *)sdi);
647
648 return SR_OK;
649}
650
695dc859 651static int dev_acquisition_stop(struct sr_dev_inst *sdi)
8ab929d6
SA
652{
653 struct dev_context *devc;
8ab929d6 654
bee2b016 655 std_session_send_df_end(sdi);
8ab929d6 656
8ab929d6
SA
657 devc = sdi->priv;
658
659 devc->num_frames = 0;
660 g_slist_free(devc->enabled_channels);
661 devc->enabled_channels = NULL;
af3487ec
SA
662
663 sr_scpi_source_remove(sdi->session, sdi->conn);
8ab929d6
SA
664
665 return SR_OK;
666}
10763937 667
dd5c48a6 668static struct sr_dev_driver yokogawa_dlm_driver_info = {
10763937 669 .name = "yokogawa-dlm",
ac10a927 670 .longname = "Yokogawa DL/DLM",
10763937 671 .api_version = 1,
c2fdcc25 672 .init = std_init,
700d6b64 673 .cleanup = std_cleanup,
8ab929d6 674 .scan = scan,
c01bf34c 675 .dev_list = std_dev_list,
8ab929d6
SA
676 .dev_clear = dev_clear,
677 .config_get = config_get,
678 .config_set = config_set,
c65a021c 679 .config_channel_set = config_channel_set,
8ab929d6
SA
680 .config_list = config_list,
681 .dev_open = dev_open,
682 .dev_close = dev_close,
683 .dev_acquisition_start = dev_acquisition_start,
684 .dev_acquisition_stop = dev_acquisition_stop,
41812aca 685 .context = NULL,
10763937 686};
dd5c48a6 687SR_REGISTER_DEV_DRIVER(yokogawa_dlm_driver_info);