]> sigrok.org Git - libsigrok.git/blame - src/hardware/yokogawa-dlm/api.c
sr_dev_close(): Set status to SR_ST_INACTIVE.
[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{
6402c379 144 if (sr_scpi_open(sdi->conn) != SR_OK)
8ab929d6
SA
145 return SR_ERR;
146
147 if (dlm_scope_state_query(sdi) != SR_OK)
148 return SR_ERR;
149
8ab929d6
SA
150 return SR_OK;
151}
152
153static int dev_close(struct sr_dev_inst *sdi)
154{
f1ba6b4b 155 return sr_scpi_close(sdi->conn);
8ab929d6
SA
156}
157
8ab929d6
SA
158/**
159 * Check which category a given channel group belongs to.
160 *
161 * @param devc Our internal device context.
a9308652 162 * @param cg The channel group to check.
8ab929d6 163 *
a9308652
UH
164 * @retval CG_NONE cg is NULL
165 * @retval CG_ANALOG cg is an analog group
8ab929d6
SA
166 * @retval CG_DIGITAL cg is a digital group
167 * @retval CG_INVALID cg is something else
168 */
169static int check_channel_group(struct dev_context *devc,
ac10a927 170 const struct sr_channel_group *cg)
8ab929d6
SA
171{
172 unsigned int i;
329733d9 173 const struct scope_config *model;
8ab929d6
SA
174
175 model = devc->model_config;
176
177 if (!cg)
178 return CG_NONE;
179
a9308652 180 for (i = 0; i < model->analog_channels; i++)
8ab929d6
SA
181 if (cg == devc->analog_groups[i])
182 return CG_ANALOG;
183
a9308652 184 for (i = 0; i < model->pods; i++)
8ab929d6
SA
185 if (cg == devc->digital_groups[i])
186 return CG_DIGITAL;
187
188 sr_err("Invalid channel group specified.");
189 return CG_INVALID;
190}
191
584560f1 192static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
ac10a927 193 const struct sr_channel_group *cg)
8ab929d6
SA
194{
195 int ret, cg_type;
196 unsigned int i;
197 struct dev_context *devc;
329733d9 198 const struct scope_config *model;
8ab929d6
SA
199 struct scope_state *state;
200
709468ba 201 if (!sdi)
8ab929d6
SA
202 return SR_ERR_ARG;
203
709468ba
UH
204 devc = sdi->priv;
205
8ab929d6
SA
206 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
207 return SR_ERR;
208
8ab929d6
SA
209 model = devc->model_config;
210 state = devc->model_state;
211
212 switch (key) {
bf622e6d 213 case SR_CONF_NUM_HDIV:
8ab929d6
SA
214 *data = g_variant_new_int32(model->num_xdivs);
215 ret = SR_OK;
216 break;
217 case SR_CONF_TIMEBASE:
218 *data = g_variant_new("(tt)",
f3c60fb6
SA
219 dlm_timebases[state->timebase][0],
220 dlm_timebases[state->timebase][1]);
8ab929d6
SA
221 ret = SR_OK;
222 break;
223 case SR_CONF_NUM_VDIV:
224 if (cg_type == CG_NONE) {
225 sr_err("No channel group specified.");
226 return SR_ERR_CHANNEL_GROUP;
227 } else if (cg_type == CG_ANALOG) {
228 *data = g_variant_new_int32(model->num_ydivs);
229 ret = SR_OK;
230 break;
231 } else {
232 ret = SR_ERR_NA;
233 }
234 break;
235 case SR_CONF_VDIV:
236 ret = SR_ERR_NA;
237 if (cg_type == CG_NONE) {
238 sr_err("No channel group specified.");
239 return SR_ERR_CHANNEL_GROUP;
240 } else if (cg_type != CG_ANALOG)
241 break;
242
a9308652 243 for (i = 0; i < model->analog_channels; i++) {
8ab929d6
SA
244 if (cg != devc->analog_groups[i])
245 continue;
246 *data = g_variant_new("(tt)",
f3c60fb6
SA
247 dlm_vdivs[state->analog_states[i].vdiv][0],
248 dlm_vdivs[state->analog_states[i].vdiv][1]);
8ab929d6
SA
249 ret = SR_OK;
250 break;
251 }
252 break;
253 case SR_CONF_TRIGGER_SOURCE:
254 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
255 ret = SR_OK;
256 break;
257 case SR_CONF_TRIGGER_SLOPE:
f3c60fb6 258 *data = g_variant_new_string(dlm_trigger_slopes[state->trigger_slope]);
8ab929d6
SA
259 ret = SR_OK;
260 break;
261 case SR_CONF_HORIZ_TRIGGERPOS:
262 *data = g_variant_new_double(state->horiz_triggerpos);
263 ret = SR_OK;
264 break;
265 case SR_CONF_COUPLING:
266 ret = SR_ERR_NA;
267 if (cg_type == CG_NONE) {
268 sr_err("No channel group specified.");
269 return SR_ERR_CHANNEL_GROUP;
270 } else if (cg_type != CG_ANALOG)
271 break;
272
a9308652 273 for (i = 0; i < model->analog_channels; i++) {
8ab929d6
SA
274 if (cg != devc->analog_groups[i])
275 continue;
276 *data = g_variant_new_string((*model->coupling_options)[state->analog_states[i].coupling]);
277 ret = SR_OK;
278 break;
279 }
280 break;
281 case SR_CONF_SAMPLERATE:
282 *data = g_variant_new_uint64(state->sample_rate);
283 ret = SR_OK;
284 break;
285 default:
286 ret = SR_ERR_NA;
287 }
288
289 return ret;
290}
291
292static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
293{
294 unsigned int i;
295 GVariant *rational[2];
296 GVariantBuilder gvb;
297
298 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
299
300 for (i = 0; i < n; i++) {
301 rational[0] = g_variant_new_uint64((*array)[i][0]);
302 rational[1] = g_variant_new_uint64((*array)[i][1]);
303
304 /* FIXME: Valgrind reports a memory leak here. */
305 g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
306 }
307
308 return g_variant_builder_end(&gvb);
309}
310
584560f1 311static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
ac10a927 312 const struct sr_channel_group *cg)
8ab929d6
SA
313{
314 int ret, cg_type;
315 unsigned int i, j;
316 char float_str[30];
317 struct dev_context *devc;
329733d9 318 const struct scope_config *model;
8ab929d6
SA
319 struct scope_state *state;
320 const char *tmp;
321 uint64_t p, q;
322 double tmp_d;
323 gboolean update_sample_rate;
324
325 if (!sdi || !(devc = sdi->priv))
326 return SR_ERR_ARG;
327
328 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
329 return SR_ERR;
330
331 model = devc->model_config;
332 state = devc->model_state;
333 update_sample_rate = FALSE;
334
335 ret = SR_ERR_NA;
336
337 switch (key) {
338 case SR_CONF_LIMIT_FRAMES:
339 devc->frame_limit = g_variant_get_uint64(data);
340 ret = SR_OK;
341 break;
342 case SR_CONF_TRIGGER_SOURCE:
343 tmp = g_variant_get_string(data, NULL);
344 for (i = 0; (*model->trigger_sources)[i]; i++) {
345 if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
346 continue;
347 state->trigger_source = i;
348 /* TODO: A and B trigger support possible? */
349 ret = dlm_trigger_source_set(sdi->conn, (*model->trigger_sources)[i]);
350 break;
351 }
352 break;
353 case SR_CONF_VDIV:
354 if (cg_type == CG_NONE) {
355 sr_err("No channel group specified.");
356 return SR_ERR_CHANNEL_GROUP;
357 }
358
359 g_variant_get(data, "(tt)", &p, &q);
360
f3c60fb6
SA
361 for (i = 0; i < ARRAY_SIZE(dlm_vdivs); i++) {
362 if (p != dlm_vdivs[i][0] ||
363 q != dlm_vdivs[i][1])
8ab929d6 364 continue;
a9308652 365 for (j = 1; j <= model->analog_channels; j++) {
8ab929d6
SA
366 if (cg != devc->analog_groups[j - 1])
367 continue;
368 state->analog_states[j - 1].vdiv = i;
369 g_ascii_formatd(float_str, sizeof(float_str),
370 "%E", (float) p / q);
371 if (dlm_analog_chan_vdiv_set(sdi->conn, j, float_str) != SR_OK ||
ac10a927 372 sr_scpi_get_opc(sdi->conn) != SR_OK)
8ab929d6
SA
373 return SR_ERR;
374
375 break;
376 }
377
378 ret = SR_OK;
379 break;
380 }
381 break;
382 case SR_CONF_TIMEBASE:
383 g_variant_get(data, "(tt)", &p, &q);
384
f3c60fb6
SA
385 for (i = 0; i < ARRAY_SIZE(dlm_timebases); i++) {
386 if (p != dlm_timebases[i][0] ||
387 q != dlm_timebases[i][1])
8ab929d6
SA
388 continue;
389 state->timebase = i;
390 g_ascii_formatd(float_str, sizeof(float_str),
391 "%E", (float) p / q);
392 ret = dlm_timebase_set(sdi->conn, float_str);
393 update_sample_rate = TRUE;
394 break;
395 }
396 break;
397 case SR_CONF_HORIZ_TRIGGERPOS:
398 tmp_d = g_variant_get_double(data);
399
400 /* TODO: Check if the calculation makes sense for the DLM. */
401 if (tmp_d < 0.0 || tmp_d > 1.0)
402 return SR_ERR;
403
404 state->horiz_triggerpos = tmp_d;
405 tmp_d = -(tmp_d - 0.5) *
f3c60fb6
SA
406 ((double) dlm_timebases[state->timebase][0] /
407 dlm_timebases[state->timebase][1])
ac10a927 408 * model->num_xdivs;
8ab929d6
SA
409
410 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
411 ret = dlm_horiz_trigger_pos_set(sdi->conn, float_str);
412 break;
413 case SR_CONF_TRIGGER_SLOPE:
414 tmp = g_variant_get_string(data, NULL);
415
416 if (!tmp || !(tmp[0] == 'f' || tmp[0] == 'r'))
417 return SR_ERR_ARG;
418
419 /* Note: See dlm_trigger_slopes[] in protocol.c. */
420 state->trigger_slope = (tmp[0] == 'r') ?
421 SLOPE_POSITIVE : SLOPE_NEGATIVE;
422
423 ret = dlm_trigger_slope_set(sdi->conn, state->trigger_slope);
424 break;
425 case SR_CONF_COUPLING:
426 if (cg_type == CG_NONE) {
427 sr_err("No channel group specified.");
428 return SR_ERR_CHANNEL_GROUP;
429 }
430
431 tmp = g_variant_get_string(data, NULL);
432
433 for (i = 0; (*model->coupling_options)[i]; i++) {
434 if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
435 continue;
a9308652 436 for (j = 1; j <= model->analog_channels; j++) {
8ab929d6
SA
437 if (cg != devc->analog_groups[j - 1])
438 continue;
439 state->analog_states[j-1].coupling = i;
440
441 if (dlm_analog_chan_coupl_set(sdi->conn, j, tmp) != SR_OK ||
ac10a927 442 sr_scpi_get_opc(sdi->conn) != SR_OK)
8ab929d6
SA
443 return SR_ERR;
444 break;
445 }
446
447 ret = SR_OK;
448 break;
449 }
450 break;
451 default:
452 ret = SR_ERR_NA;
453 break;
454 }
455
456 if (ret == SR_OK)
457 ret = sr_scpi_get_opc(sdi->conn);
458
459 if (ret == SR_OK && update_sample_rate)
460 ret = dlm_sample_rate_query(sdi);
461
462 return ret;
463}
464
c65a021c
SA
465static int config_channel_set(const struct sr_dev_inst *sdi,
466 struct sr_channel *ch, unsigned int changes)
467{
a9308652 468 /* Currently we only handle SR_CHANNEL_SET_ENABLED. */
c65a021c
SA
469 if (changes != SR_CHANNEL_SET_ENABLED)
470 return SR_ERR_NA;
471
472 return dlm_channel_state_set(sdi, ch->index, ch->enabled);
473}
474
584560f1 475static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
ac10a927 476 const struct sr_channel_group *cg)
8ab929d6 477{
cf0280fa
AJ
478 int cg_type = CG_NONE;
479 struct dev_context *devc = NULL;
329733d9 480 const struct scope_config *model = NULL;
8ab929d6 481
9a512113 482 /* SR_CONF_SCAN_OPTIONS is always valid, regardless of sdi or channel group. */
f3c60fb6
SA
483 if (key == SR_CONF_SCAN_OPTIONS) {
484 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
485 dlm_scanopts, ARRAY_SIZE(dlm_scanopts), sizeof(uint32_t));
486 return SR_OK;
487 }
8ab929d6 488
f3c60fb6
SA
489 /* If sdi is NULL, nothing except SR_CONF_DEVICE_OPTIONS can be provided. */
490 if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
491 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
492 dlm_drvopts, ARRAY_SIZE(dlm_drvopts), sizeof(uint32_t));
493 return SR_OK;
cf0280fa 494 }
8ab929d6 495
f3c60fb6
SA
496 if (!sdi)
497 return SR_ERR_ARG;
498
499 devc = sdi->priv;
500 model = devc->model_config;
501
a9308652
UH
502 /*
503 * If cg is NULL, only the SR_CONF_DEVICE_OPTIONS that are not
9a512113 504 * specific to a channel group must be returned.
a9308652 505 */
f3c60fb6
SA
506 if (!cg) {
507 switch (key) {
508 case SR_CONF_DEVICE_OPTIONS:
509 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
510 dlm_devopts, ARRAY_SIZE(dlm_devopts), sizeof(uint32_t));
511 return SR_OK;
512 case SR_CONF_TIMEBASE:
513 *data = build_tuples(&dlm_timebases, ARRAY_SIZE(dlm_timebases));
514 return SR_OK;
515 case SR_CONF_TRIGGER_SOURCE:
516 if (!model)
517 return SR_ERR_ARG;
518 *data = g_variant_new_strv(*model->trigger_sources,
519 g_strv_length((char **)*model->trigger_sources));
520 return SR_OK;
521 case SR_CONF_TRIGGER_SLOPE:
522 *data = g_variant_new_strv(dlm_trigger_slopes,
523 g_strv_length((char **)dlm_trigger_slopes));
524 return SR_OK;
525 case SR_CONF_NUM_HDIV:
49f49cb5 526 *data = g_variant_new_uint32(model->num_xdivs);
f3c60fb6
SA
527 return SR_OK;
528 default:
529 return SR_ERR_NA;
530 }
531 }
532
533 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
534 return SR_ERR;
535
8ab929d6 536 switch (key) {
8ab929d6 537 case SR_CONF_DEVICE_OPTIONS:
f3c60fb6 538 if (cg_type == CG_ANALOG) {
584560f1 539 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
f3c60fb6
SA
540 dlm_analog_devopts, ARRAY_SIZE(dlm_analog_devopts), sizeof(uint32_t));
541 } else if (cg_type == CG_DIGITAL) {
542 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
543 dlm_digital_devopts, ARRAY_SIZE(dlm_digital_devopts), sizeof(uint32_t));
8ab929d6 544 } else {
584560f1
BV
545 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
546 NULL, 0, sizeof(uint32_t));
8ab929d6
SA
547 }
548 break;
549 case SR_CONF_COUPLING:
550 if (cg_type == CG_NONE)
551 return SR_ERR_CHANNEL_GROUP;
552 *data = g_variant_new_strv(*model->coupling_options,
ac10a927 553 g_strv_length((char **)*model->coupling_options));
8ab929d6 554 break;
8ab929d6
SA
555 case SR_CONF_VDIV:
556 if (cg_type == CG_NONE)
557 return SR_ERR_CHANNEL_GROUP;
f3c60fb6 558 *data = build_tuples(&dlm_vdivs, ARRAY_SIZE(dlm_vdivs));
8ab929d6
SA
559 break;
560 default:
561 return SR_ERR_NA;
562 }
563
564 return SR_OK;
565}
566
567static int dlm_check_channels(GSList *channels)
568{
569 GSList *l;
570 struct sr_channel *ch;
571 gboolean enabled_pod1, enabled_chan4;
572
573 enabled_pod1 = enabled_chan4 = FALSE;
574
575 /* Note: On the DLM2000, CH4 and Logic are shared. */
576 /* TODO Handle non-DLM2000 models. */
577 for (l = channels; l; l = l->next) {
578 ch = l->data;
579 switch (ch->type) {
580 case SR_CHANNEL_ANALOG:
581 if (ch->index == 3)
582 enabled_chan4 = TRUE;
583 break;
584 case SR_CHANNEL_LOGIC:
585 enabled_pod1 = TRUE;
586 break;
587 default:
588 return SR_ERR;
589 }
590 }
591
592 if (enabled_pod1 && enabled_chan4)
593 return SR_ERR;
594
595 return SR_OK;
596}
597
695dc859 598static int dev_acquisition_start(const struct sr_dev_inst *sdi)
8ab929d6
SA
599{
600 GSList *l;
601 gboolean digital_added;
602 struct sr_channel *ch;
603 struct dev_context *devc;
604 struct sr_scpi_dev_inst *scpi;
605
8ab929d6
SA
606 scpi = sdi->conn;
607 devc = sdi->priv;
608 digital_added = FALSE;
609
610 g_slist_free(devc->enabled_channels);
611 devc->enabled_channels = NULL;
612
613 for (l = sdi->channels; l; l = l->next) {
614 ch = l->data;
615 if (!ch->enabled)
616 continue;
617 /* Only add a single digital channel. */
618 if (ch->type != SR_CHANNEL_LOGIC || !digital_added) {
619 devc->enabled_channels = g_slist_append(
ac10a927
SA
620 devc->enabled_channels, ch);
621 if (ch->type == SR_CHANNEL_LOGIC)
622 digital_added = TRUE;
8ab929d6
SA
623 }
624 }
625
626 if (!devc->enabled_channels)
627 return SR_ERR;
628
629 if (dlm_check_channels(devc->enabled_channels) != SR_OK) {
630 sr_err("Invalid channel configuration specified!");
631 return SR_ERR_NA;
632 }
633
af3487ec
SA
634 /* Request data for the first enabled channel. */
635 devc->current_channel = devc->enabled_channels;
636 dlm_channel_data_request(sdi);
637
0028d5a1
SA
638 /* Call our callback when data comes in or after 5ms. */
639 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 5,
8ab929d6
SA
640 dlm_data_receive, (void *)sdi);
641
642 return SR_OK;
643}
644
695dc859 645static int dev_acquisition_stop(struct sr_dev_inst *sdi)
8ab929d6
SA
646{
647 struct dev_context *devc;
8ab929d6 648
bee2b016 649 std_session_send_df_end(sdi);
8ab929d6 650
8ab929d6
SA
651 devc = sdi->priv;
652
653 devc->num_frames = 0;
654 g_slist_free(devc->enabled_channels);
655 devc->enabled_channels = NULL;
af3487ec
SA
656
657 sr_scpi_source_remove(sdi->session, sdi->conn);
8ab929d6
SA
658
659 return SR_OK;
660}
10763937 661
dd5c48a6 662static struct sr_dev_driver yokogawa_dlm_driver_info = {
10763937 663 .name = "yokogawa-dlm",
ac10a927 664 .longname = "Yokogawa DL/DLM",
10763937 665 .api_version = 1,
c2fdcc25 666 .init = std_init,
700d6b64 667 .cleanup = std_cleanup,
8ab929d6 668 .scan = scan,
c01bf34c 669 .dev_list = std_dev_list,
8ab929d6
SA
670 .dev_clear = dev_clear,
671 .config_get = config_get,
672 .config_set = config_set,
c65a021c 673 .config_channel_set = config_channel_set,
8ab929d6
SA
674 .config_list = config_list,
675 .dev_open = dev_open,
676 .dev_close = dev_close,
677 .dev_acquisition_start = dev_acquisition_start,
678 .dev_acquisition_stop = dev_acquisition_stop,
41812aca 679 .context = NULL,
10763937 680};
dd5c48a6 681SR_REGISTER_DEV_DRIVER(yokogawa_dlm_driver_info);