]> sigrok.org Git - libsigrok.git/blob - src/hardware/hameg-hmo/api.c
drivers: Consistently name SCPI helper functions 'probe_device'.
[libsigrok.git] / src / hardware / hameg-hmo / api.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2013 poljar (Damir Jelić) <poljarinho@gmail.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
20 #include <config.h>
21 #include <stdlib.h>
22 #include "scpi.h"
23 #include "protocol.h"
24
25 #define SERIALCOMM "115200/8n1/flow=1"
26
27 static struct sr_dev_driver hameg_hmo_driver_info;
28
29 static const char *manufacturers[] = {
30         "HAMEG",
31         "Rohde&Schwarz",
32 };
33
34 static const uint32_t scanopts[] = {
35         SR_CONF_CONN,
36         SR_CONF_SERIALCOMM,
37 };
38
39 static const uint32_t drvopts[] = {
40         SR_CONF_OSCILLOSCOPE,
41 };
42
43 enum {
44         CG_INVALID = -1,
45         CG_NONE,
46         CG_ANALOG,
47         CG_DIGITAL,
48 };
49
50 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
51 {
52         struct sr_dev_inst *sdi;
53         struct dev_context *devc;
54         struct sr_scpi_hw_info *hw_info;
55
56         sdi = NULL;
57         devc = NULL;
58         hw_info = NULL;
59
60         if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
61                 sr_info("Couldn't get IDN response.");
62                 goto fail;
63         }
64
65         if (std_str_idx_s(hw_info->manufacturer, ARRAY_AND_SIZE(manufacturers)) < 0)
66                 goto fail;
67
68         sdi = g_malloc0(sizeof(struct sr_dev_inst));
69         sdi->vendor = g_strdup(hw_info->manufacturer);
70         sdi->model = g_strdup(hw_info->model);
71         sdi->version = g_strdup(hw_info->firmware_version);
72         sdi->serial_num = g_strdup(hw_info->serial_number);
73         sdi->driver = &hameg_hmo_driver_info;
74         sdi->inst_type = SR_INST_SCPI;
75         sdi->conn = scpi;
76
77         sr_scpi_hw_info_free(hw_info);
78         hw_info = NULL;
79
80         devc = g_malloc0(sizeof(struct dev_context));
81
82         sdi->priv = devc;
83
84         if (hmo_init_device(sdi) != SR_OK)
85                 goto fail;
86
87         return sdi;
88
89 fail:
90         sr_scpi_hw_info_free(hw_info);
91         sr_dev_inst_free(sdi);
92         g_free(devc);
93
94         return NULL;
95 }
96
97 static GSList *scan(struct sr_dev_driver *di, GSList *options)
98 {
99         return sr_scpi_scan(di->context, options, probe_device);
100 }
101
102 static void clear_helper(struct dev_context *devc)
103 {
104         hmo_scope_state_free(devc->model_state);
105         g_free(devc->analog_groups);
106         g_free(devc->digital_groups);
107 }
108
109 static int dev_clear(const struct sr_dev_driver *di)
110 {
111         return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
112 }
113
114 static int dev_open(struct sr_dev_inst *sdi)
115 {
116         if (sr_scpi_open(sdi->conn) != SR_OK)
117                 return SR_ERR;
118
119         if (hmo_scope_state_get(sdi) != SR_OK)
120                 return SR_ERR;
121
122         return SR_OK;
123 }
124
125 static int dev_close(struct sr_dev_inst *sdi)
126 {
127         return sr_scpi_close(sdi->conn);
128 }
129
130 static int check_channel_group(struct dev_context *devc,
131                              const struct sr_channel_group *cg)
132 {
133         unsigned int i;
134         const struct scope_config *model;
135
136         model = devc->model_config;
137
138         if (!cg)
139                 return CG_NONE;
140
141         for (i = 0; i < model->analog_channels; i++)
142                 if (cg == devc->analog_groups[i])
143                         return CG_ANALOG;
144
145         for (i = 0; i < model->digital_pods; i++)
146                 if (cg == devc->digital_groups[i])
147                         return CG_DIGITAL;
148
149         sr_err("Invalid channel group specified.");
150
151         return CG_INVALID;
152 }
153
154 static int config_get(uint32_t key, GVariant **data,
155         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
156 {
157         int cg_type;
158         unsigned int i;
159         struct dev_context *devc;
160         const struct scope_config *model;
161         struct scope_state *state;
162
163         if (!sdi)
164                 return SR_ERR_ARG;
165
166         devc = sdi->priv;
167
168         if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
169                 return SR_ERR;
170
171         model = devc->model_config;
172         state = devc->model_state;
173
174         switch (key) {
175         case SR_CONF_NUM_HDIV:
176                 *data = g_variant_new_int32(model->num_xdivs);
177                 break;
178         case SR_CONF_TIMEBASE:
179                 *data = g_variant_new("(tt)", (*model->timebases)[state->timebase][0],
180                                       (*model->timebases)[state->timebase][1]);
181                 break;
182         case SR_CONF_NUM_VDIV:
183                 if (cg_type == CG_NONE) {
184                         return SR_ERR_CHANNEL_GROUP;
185                 } else if (cg_type == CG_ANALOG) {
186                         for (i = 0; i < model->analog_channels; i++) {
187                                 if (cg != devc->analog_groups[i])
188                                         continue;
189                                 *data = g_variant_new_int32(model->num_ydivs);
190                                 break;
191                         }
192                 } else {
193                         return SR_ERR_NA;
194                 }
195                 break;
196         case SR_CONF_VDIV:
197                 if (cg_type == CG_NONE) {
198                         return SR_ERR_CHANNEL_GROUP;
199                 } else if (cg_type == CG_ANALOG) {
200                         for (i = 0; i < model->analog_channels; i++) {
201                                 if (cg != devc->analog_groups[i])
202                                         continue;
203                                 *data = g_variant_new("(tt)",
204                                                       (*model->vdivs)[state->analog_channels[i].vdiv][0],
205                                                       (*model->vdivs)[state->analog_channels[i].vdiv][1]);
206                                 break;
207                         }
208                 } else {
209                         return SR_ERR_NA;
210                 }
211                 break;
212         case SR_CONF_TRIGGER_SOURCE:
213                 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
214                 break;
215         case SR_CONF_TRIGGER_SLOPE:
216                 *data = g_variant_new_string((*model->trigger_slopes)[state->trigger_slope]);
217                 break;
218         case SR_CONF_HORIZ_TRIGGERPOS:
219                 *data = g_variant_new_double(state->horiz_triggerpos);
220                 break;
221         case SR_CONF_COUPLING:
222                 if (cg_type == CG_NONE) {
223                         return SR_ERR_CHANNEL_GROUP;
224                 } else if (cg_type == CG_ANALOG) {
225                         for (i = 0; i < model->analog_channels; i++) {
226                                 if (cg != devc->analog_groups[i])
227                                         continue;
228                                 *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[i].coupling]);
229                                 break;
230                         }
231                 } else {
232                         return SR_ERR_NA;
233                 }
234                 break;
235         case SR_CONF_SAMPLERATE:
236                 *data = g_variant_new_uint64(state->sample_rate);
237                 break;
238         default:
239                 return SR_ERR_NA;
240         }
241
242         return SR_OK;
243 }
244
245 static int config_set(uint32_t key, GVariant *data,
246         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
247 {
248         int ret, cg_type, idx;
249         unsigned int i, j;
250         char command[MAX_COMMAND_SIZE], float_str[30];
251         struct dev_context *devc;
252         const struct scope_config *model;
253         struct scope_state *state;
254         const char *tmp;
255         double tmp_d;
256         gboolean update_sample_rate;
257
258         if (!sdi)
259                 return SR_ERR_ARG;
260
261         devc = sdi->priv;
262
263         if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
264                 return SR_ERR;
265
266         model = devc->model_config;
267         state = devc->model_state;
268         update_sample_rate = FALSE;
269
270         ret = SR_ERR_NA;
271
272         switch (key) {
273         case SR_CONF_LIMIT_FRAMES:
274                 devc->frame_limit = g_variant_get_uint64(data);
275                 ret = SR_OK;
276                 break;
277         case SR_CONF_TRIGGER_SOURCE:
278                 tmp = g_variant_get_string(data, NULL);
279                 for (i = 0; (*model->trigger_sources)[i]; i++) {
280                         if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
281                                 continue;
282                         state->trigger_source = i;
283                         g_snprintf(command, sizeof(command),
284                                    (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
285                                    (*model->trigger_sources)[i]);
286
287                         ret = sr_scpi_send(sdi->conn, command);
288                         break;
289                 }
290                 break;
291         case SR_CONF_VDIV:
292                 if (cg_type == CG_NONE)
293                         return SR_ERR_CHANNEL_GROUP;
294                 if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
295                         return SR_ERR_ARG;
296                 for (j = 1; j <= model->analog_channels; j++) {
297                         if (cg != devc->analog_groups[j - 1])
298                                 continue;
299                         state->analog_channels[j - 1].vdiv = idx;
300                         g_ascii_formatd(float_str, sizeof(float_str), "%E",
301                                 (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]);
302                         g_snprintf(command, sizeof(command),
303                                    (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
304                                    j, float_str);
305                         if (sr_scpi_send(sdi->conn, command) != SR_OK ||
306                             sr_scpi_get_opc(sdi->conn) != SR_OK)
307                                 return SR_ERR;
308                         break;
309                 }
310                 ret = SR_OK;
311                 break;
312         case SR_CONF_TIMEBASE:
313                 if ((idx = std_u64_tuple_idx(data, *model->timebases, model->num_timebases)) < 0)
314                         return SR_ERR_ARG;
315                 state->timebase = idx;
316                 g_ascii_formatd(float_str, sizeof(float_str), "%E",
317                         (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]);
318                 g_snprintf(command, sizeof(command),
319                            (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
320                            float_str);
321                 ret = sr_scpi_send(sdi->conn, command);
322                 update_sample_rate = TRUE;
323                 break;
324         case SR_CONF_HORIZ_TRIGGERPOS:
325                 tmp_d = g_variant_get_double(data);
326
327                 if (tmp_d < 0.0 || tmp_d > 1.0)
328                         return SR_ERR;
329
330                 state->horiz_triggerpos = tmp_d;
331                 tmp_d = -(tmp_d - 0.5) *
332                         ((double) (*model->timebases)[state->timebase][0] /
333                         (*model->timebases)[state->timebase][1])
334                          * model->num_xdivs;
335
336                 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
337                 g_snprintf(command, sizeof(command),
338                            (*model->scpi_dialect)[SCPI_CMD_SET_HORIZ_TRIGGERPOS],
339                            float_str);
340
341                 ret = sr_scpi_send(sdi->conn, command);
342                 break;
343         case SR_CONF_TRIGGER_SLOPE:
344                 tmp = g_variant_get_string(data, NULL);
345                 for (i = 0; (*model->trigger_slopes)[i]; i++) {
346                         if (g_strcmp0(tmp, (*model->trigger_slopes)[i]) != 0)
347                                 continue;
348                         state->trigger_slope = i;
349                         g_snprintf(command, sizeof(command),
350                                    (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
351                                    (*model->trigger_slopes)[i]);
352
353                         ret = sr_scpi_send(sdi->conn, command);
354                         break;
355                 }
356                 break;
357         case SR_CONF_COUPLING:
358                 if (cg_type == CG_NONE)
359                         return SR_ERR_CHANNEL_GROUP;
360
361                 tmp = g_variant_get_string(data, NULL);
362
363                 for (i = 0; (*model->coupling_options)[i]; i++) {
364                         if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
365                                 continue;
366                         for (j = 1; j <= model->analog_channels; j++) {
367                                 if (cg != devc->analog_groups[j - 1])
368                                         continue;
369                                 state->analog_channels[j-1].coupling = i;
370
371                                 g_snprintf(command, sizeof(command),
372                                            (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
373                                            j, tmp);
374
375                                 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
376                                     sr_scpi_get_opc(sdi->conn) != SR_OK)
377                                         return SR_ERR;
378                                 break;
379                         }
380
381                         ret = SR_OK;
382                         break;
383                 }
384                 break;
385         default:
386                 ret = SR_ERR_NA;
387                 break;
388         }
389
390         if (ret == SR_OK)
391                 ret = sr_scpi_get_opc(sdi->conn);
392
393         if (ret == SR_OK && update_sample_rate)
394                 ret = hmo_update_sample_rate(sdi);
395
396         return ret;
397 }
398
399 static int config_list(uint32_t key, GVariant **data,
400         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
401 {
402         int cg_type = CG_NONE;
403         struct dev_context *devc = NULL;
404         const struct scope_config *model = NULL;
405
406         if (sdi) {
407                 devc = sdi->priv;
408                 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
409                         return SR_ERR;
410
411                 model = devc->model_config;
412         }
413
414         switch (key) {
415         case SR_CONF_SCAN_OPTIONS:
416                 *data = std_gvar_array_u32(ARRAY_AND_SIZE(scanopts));
417                 break;
418         case SR_CONF_DEVICE_OPTIONS:
419                 if (cg_type == CG_NONE) {
420                         if (model)
421                                 *data = std_gvar_array_u32((const uint32_t *)model->devopts, model->num_devopts);
422                         else
423                                 *data = std_gvar_array_u32(ARRAY_AND_SIZE(drvopts));
424                 } else if (cg_type == CG_ANALOG) {
425                         *data = std_gvar_array_u32((const uint32_t *)model->devopts_cg_analog, model->num_devopts_cg_analog);
426                 } else {
427                         *data = std_gvar_array_u32(NULL, 0);
428                 }
429                 break;
430         case SR_CONF_COUPLING:
431                 if (cg_type == CG_NONE)
432                         return SR_ERR_CHANNEL_GROUP;
433                 *data = g_variant_new_strv(*model->coupling_options,
434                            g_strv_length((char **)*model->coupling_options));
435                 break;
436         case SR_CONF_TRIGGER_SOURCE:
437                 if (!model)
438                         return SR_ERR_ARG;
439                 *data = g_variant_new_strv(*model->trigger_sources,
440                            g_strv_length((char **)*model->trigger_sources));
441                 break;
442         case SR_CONF_TRIGGER_SLOPE:
443                 if (!model)
444                         return SR_ERR_ARG;
445                 *data = g_variant_new_strv(*model->trigger_slopes,
446                            g_strv_length((char **)*model->trigger_slopes));
447                 break;
448         case SR_CONF_TIMEBASE:
449                 if (!model)
450                         return SR_ERR_ARG;
451                 *data = std_gvar_tuple_array(*model->timebases, model->num_timebases);
452                 break;
453         case SR_CONF_VDIV:
454                 if (cg_type == CG_NONE)
455                         return SR_ERR_CHANNEL_GROUP;
456                 *data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs);
457                 break;
458         default:
459                 return SR_ERR_NA;
460         }
461
462         return SR_OK;
463 }
464
465 SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
466 {
467         char command[MAX_COMMAND_SIZE];
468         struct sr_channel *ch;
469         struct dev_context *devc;
470         const struct scope_config *model;
471
472         devc = sdi->priv;
473         model = devc->model_config;
474
475         ch = devc->current_channel->data;
476
477         switch (ch->type) {
478         case SR_CHANNEL_ANALOG:
479                 g_snprintf(command, sizeof(command),
480                            (*model->scpi_dialect)[SCPI_CMD_GET_ANALOG_DATA],
481 #ifdef WORDS_BIGENDIAN
482                            "MSBF",
483 #else
484                            "LSBF",
485 #endif
486                            ch->index + 1);
487                 break;
488         case SR_CHANNEL_LOGIC:
489                 g_snprintf(command, sizeof(command),
490                            (*model->scpi_dialect)[SCPI_CMD_GET_DIG_DATA],
491                            ch->index < 8 ? 1 : 2);
492                 break;
493         default:
494                 sr_err("Invalid channel type.");
495                 break;
496         }
497
498         return sr_scpi_send(sdi->conn, command);
499 }
500
501 static int hmo_check_channels(GSList *channels)
502 {
503         GSList *l;
504         struct sr_channel *ch;
505         gboolean enabled_chan[MAX_ANALOG_CHANNEL_COUNT];
506         gboolean enabled_pod[MAX_DIGITAL_GROUP_COUNT];
507         size_t idx;
508
509         /* Preset "not enabled" for all channels / pods. */
510         for (idx = 0; idx < ARRAY_SIZE(enabled_chan); idx++)
511                 enabled_chan[idx] = FALSE;
512         for (idx = 0; idx < ARRAY_SIZE(enabled_pod); idx++)
513                 enabled_pod[idx] = FALSE;
514
515         /*
516          * Determine which channels / pods are required for the caller's
517          * specified configuration.
518          */
519         for (l = channels; l; l = l->next) {
520                 ch = l->data;
521                 switch (ch->type) {
522                 case SR_CHANNEL_ANALOG:
523                         idx = ch->index;
524                         if (idx < ARRAY_SIZE(enabled_chan))
525                                 enabled_chan[idx] = TRUE;
526                         break;
527                 case SR_CHANNEL_LOGIC:
528                         idx = ch->index / 8;
529                         if (idx < ARRAY_SIZE(enabled_pod))
530                                 enabled_pod[idx] = TRUE;
531                         break;
532                 default:
533                         return SR_ERR;
534                 }
535         }
536
537         /*
538          * Check for resource conflicts. Some channels can be either
539          * analog or digital, but never both at the same time.
540          *
541          * Note that the constraints might depend on the specific model.
542          * These tests might need some adjustment when support for more
543          * models gets added to the driver.
544          */
545         if (enabled_pod[0] && enabled_chan[2])
546                 return SR_ERR;
547         if (enabled_pod[1] && enabled_chan[3])
548                 return SR_ERR;
549         return SR_OK;
550 }
551
552 static int hmo_setup_channels(const struct sr_dev_inst *sdi)
553 {
554         GSList *l;
555         unsigned int i;
556         gboolean *pod_enabled, setup_changed;
557         char command[MAX_COMMAND_SIZE];
558         struct scope_state *state;
559         const struct scope_config *model;
560         struct sr_channel *ch;
561         struct dev_context *devc;
562         struct sr_scpi_dev_inst *scpi;
563
564         devc = sdi->priv;
565         scpi = sdi->conn;
566         state = devc->model_state;
567         model = devc->model_config;
568         setup_changed = FALSE;
569
570         pod_enabled = g_try_malloc0(sizeof(gboolean) * model->digital_pods);
571
572         for (l = sdi->channels; l; l = l->next) {
573                 ch = l->data;
574                 switch (ch->type) {
575                 case SR_CHANNEL_ANALOG:
576                         if (ch->enabled == state->analog_channels[ch->index].state)
577                                 break;
578                         g_snprintf(command, sizeof(command),
579                                    (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE],
580                                    ch->index + 1, ch->enabled);
581
582                         if (sr_scpi_send(scpi, command) != SR_OK)
583                                 return SR_ERR;
584                         state->analog_channels[ch->index].state = ch->enabled;
585                         setup_changed = TRUE;
586                         break;
587                 case SR_CHANNEL_LOGIC:
588                         /*
589                          * A digital POD needs to be enabled for every group of
590                          * 8 channels.
591                          */
592                         if (ch->enabled)
593                                 pod_enabled[ch->index < 8 ? 0 : 1] = TRUE;
594
595                         if (ch->enabled == state->digital_channels[ch->index])
596                                 break;
597                         g_snprintf(command, sizeof(command),
598                                    (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
599                                    ch->index, ch->enabled);
600
601                         if (sr_scpi_send(scpi, command) != SR_OK)
602                                 return SR_ERR;
603
604                         state->digital_channels[ch->index] = ch->enabled;
605                         setup_changed = TRUE;
606                         break;
607                 default:
608                         return SR_ERR;
609                 }
610         }
611
612         for (i = 1; i <= model->digital_pods; i++) {
613                 if (state->digital_pods[i - 1] == pod_enabled[i - 1])
614                         continue;
615                 g_snprintf(command, sizeof(command),
616                            (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
617                            i, pod_enabled[i - 1]);
618                 if (sr_scpi_send(scpi, command) != SR_OK)
619                         return SR_ERR;
620                 state->digital_pods[i - 1] = pod_enabled[i - 1];
621                 setup_changed = TRUE;
622         }
623
624         g_free(pod_enabled);
625
626         if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
627                 return SR_ERR;
628
629         return SR_OK;
630 }
631
632 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
633 {
634         GSList *l;
635         gboolean digital_added[MAX_DIGITAL_GROUP_COUNT];
636         size_t group, pod_count;
637         struct sr_channel *ch;
638         struct dev_context *devc;
639         struct sr_scpi_dev_inst *scpi;
640         int ret;
641
642         scpi = sdi->conn;
643         devc = sdi->priv;
644
645         /* Preset empty results. */
646         for (group = 0; group < ARRAY_SIZE(digital_added); group++)
647                 digital_added[group] = FALSE;
648         g_slist_free(devc->enabled_channels);
649         devc->enabled_channels = NULL;
650
651         /*
652          * Contruct the list of enabled channels. Determine the highest
653          * number of digital pods involved in the acquisition.
654          */
655         pod_count = 0;
656         for (l = sdi->channels; l; l = l->next) {
657                 ch = l->data;
658                 if (!ch->enabled)
659                         continue;
660                 /* Only add a single digital channel per group (pod). */
661                 group = ch->index / 8;
662                 if (ch->type != SR_CHANNEL_LOGIC || !digital_added[group]) {
663                         devc->enabled_channels = g_slist_append(
664                                         devc->enabled_channels, ch);
665                         if (ch->type == SR_CHANNEL_LOGIC) {
666                                 digital_added[group] = TRUE;
667                                 if (pod_count < group + 1)
668                                         pod_count = group + 1;
669                         }
670                 }
671         }
672         if (!devc->enabled_channels)
673                 return SR_ERR;
674         devc->pod_count = pod_count;
675         devc->logic_data = NULL;
676
677         /*
678          * Check constraints. Some channels can be either analog or
679          * digital, but not both at the same time.
680          */
681         if (hmo_check_channels(devc->enabled_channels) != SR_OK) {
682                 sr_err("Invalid channel configuration specified!");
683                 ret = SR_ERR_NA;
684                 goto free_enabled;
685         }
686
687         /*
688          * Configure the analog and digital channels and the
689          * corresponding digital pods.
690          */
691         if (hmo_setup_channels(sdi) != SR_OK) {
692                 sr_err("Failed to setup channel configuration!");
693                 ret = SR_ERR;
694                 goto free_enabled;
695         }
696
697         /*
698          * Start acquisition on the first enabled channel. The
699          * receive routine will continue driving the acquisition.
700          */
701         sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
702                         hmo_receive_data, (void *)sdi);
703
704         std_session_send_df_header(sdi);
705
706         devc->current_channel = devc->enabled_channels;
707
708         return hmo_request_data(sdi);
709
710 free_enabled:
711         g_slist_free(devc->enabled_channels);
712         devc->enabled_channels = NULL;
713         return ret;
714 }
715
716 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
717 {
718         struct dev_context *devc;
719         struct sr_scpi_dev_inst *scpi;
720
721         std_session_send_df_end(sdi);
722
723         devc = sdi->priv;
724
725         devc->num_frames = 0;
726         g_slist_free(devc->enabled_channels);
727         devc->enabled_channels = NULL;
728         scpi = sdi->conn;
729         sr_scpi_source_remove(sdi->session, scpi);
730
731         return SR_OK;
732 }
733
734 static struct sr_dev_driver hameg_hmo_driver_info = {
735         .name = "hameg-hmo",
736         .longname = "Hameg HMO",
737         .api_version = 1,
738         .init = std_init,
739         .cleanup = std_cleanup,
740         .scan = scan,
741         .dev_list = std_dev_list,
742         .dev_clear = dev_clear,
743         .config_get = config_get,
744         .config_set = config_set,
745         .config_list = config_list,
746         .dev_open = dev_open,
747         .dev_close = dev_close,
748         .dev_acquisition_start = dev_acquisition_start,
749         .dev_acquisition_stop = dev_acquisition_stop,
750         .context = NULL,
751 };
752 SR_REGISTER_DEV_DRIVER(hameg_hmo_driver_info);