]> sigrok.org Git - libsigrok.git/blob - src/hardware/hameg-hmo/api.c
hameg-hmo: Add SR_CONF_LIMIT_SAMPLES support.
[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         const struct scope_config *model;
134
135         model = devc->model_config;
136
137         if (!cg)
138                 return CG_NONE;
139
140         if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) >= 0)
141                 return CG_ANALOG;
142
143         if (std_cg_idx(cg, devc->digital_groups, model->digital_pods) >= 0)
144                 return CG_DIGITAL;
145
146         sr_err("Invalid channel group specified.");
147
148         return CG_INVALID;
149 }
150
151 static int config_get(uint32_t key, GVariant **data,
152         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
153 {
154         int cg_type, idx;
155         struct dev_context *devc;
156         const struct scope_config *model;
157         struct scope_state *state;
158
159         if (!sdi)
160                 return SR_ERR_ARG;
161
162         devc = sdi->priv;
163
164         if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
165                 return SR_ERR;
166
167         model = devc->model_config;
168         state = devc->model_state;
169
170         switch (key) {
171         case SR_CONF_NUM_HDIV:
172                 *data = g_variant_new_int32(model->num_xdivs);
173                 break;
174         case SR_CONF_TIMEBASE:
175                 *data = g_variant_new("(tt)", (*model->timebases)[state->timebase][0],
176                                       (*model->timebases)[state->timebase][1]);
177                 break;
178         case SR_CONF_NUM_VDIV:
179                 if (!cg)
180                         return SR_ERR_CHANNEL_GROUP;
181                 if (cg_type != CG_ANALOG)
182                         return SR_ERR_NA;
183                 if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0)
184                         return SR_ERR_ARG;
185                 *data = g_variant_new_int32(model->num_ydivs);
186                 break;
187         case SR_CONF_VDIV:
188                 if (!cg)
189                         return SR_ERR_CHANNEL_GROUP;
190                 if (cg_type != CG_ANALOG)
191                         return SR_ERR_NA;
192                 if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
193                         return SR_ERR_ARG;
194                 *data = g_variant_new("(tt)",
195                                       (*model->vdivs)[state->analog_channels[idx].vdiv][0],
196                                       (*model->vdivs)[state->analog_channels[idx].vdiv][1]);
197                 break;
198         case SR_CONF_TRIGGER_SOURCE:
199                 *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
200                 break;
201         case SR_CONF_TRIGGER_SLOPE:
202                 *data = g_variant_new_string((*model->trigger_slopes)[state->trigger_slope]);
203                 break;
204         case SR_CONF_HORIZ_TRIGGERPOS:
205                 *data = g_variant_new_double(state->horiz_triggerpos);
206                 break;
207         case SR_CONF_COUPLING:
208                 if (!cg)
209                         return SR_ERR_CHANNEL_GROUP;
210                 if (cg_type != CG_ANALOG)
211                         return SR_ERR_NA;
212                 if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
213                         return SR_ERR_ARG;
214                 *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]);
215                 break;
216         case SR_CONF_SAMPLERATE:
217                 *data = g_variant_new_uint64(state->sample_rate);
218                 break;
219         default:
220                 return SR_ERR_NA;
221         }
222
223         return SR_OK;
224 }
225
226 static int config_set(uint32_t key, GVariant *data,
227         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
228 {
229         int ret, cg_type, idx, j;
230         char command[MAX_COMMAND_SIZE], float_str[30];
231         struct dev_context *devc;
232         const struct scope_config *model;
233         struct scope_state *state;
234         double tmp_d;
235         gboolean update_sample_rate;
236
237         if (!sdi)
238                 return SR_ERR_ARG;
239
240         devc = sdi->priv;
241
242         if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
243                 return SR_ERR;
244
245         model = devc->model_config;
246         state = devc->model_state;
247         update_sample_rate = FALSE;
248
249         switch (key) {
250         case SR_CONF_LIMIT_SAMPLES:
251                 devc->samples_limit = g_variant_get_uint64(data);
252                 ret = SR_OK;
253                 break;
254         case SR_CONF_LIMIT_FRAMES:
255                 devc->frame_limit = g_variant_get_uint64(data);
256                 ret = SR_OK;
257                 break;
258         case SR_CONF_TRIGGER_SOURCE:
259                 if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0)
260                         return SR_ERR_ARG;
261                 state->trigger_source = idx;
262                 g_snprintf(command, sizeof(command),
263                            (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
264                            (*model->trigger_sources)[idx]);
265                 ret = sr_scpi_send(sdi->conn, command);
266                 break;
267         case SR_CONF_VDIV:
268                 if (!cg)
269                         return SR_ERR_CHANNEL_GROUP;
270                 if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
271                         return SR_ERR_ARG;
272                 if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
273                         return SR_ERR_ARG;
274                 state->analog_channels[j].vdiv = idx;
275                 g_ascii_formatd(float_str, sizeof(float_str), "%E",
276                         (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]);
277                 g_snprintf(command, sizeof(command),
278                            (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
279                            j + 1, float_str);
280                 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
281                     sr_scpi_get_opc(sdi->conn) != SR_OK)
282                         return SR_ERR;
283                 ret = SR_OK;
284                 break;
285         case SR_CONF_TIMEBASE:
286                 if ((idx = std_u64_tuple_idx(data, *model->timebases, model->num_timebases)) < 0)
287                         return SR_ERR_ARG;
288                 state->timebase = idx;
289                 g_ascii_formatd(float_str, sizeof(float_str), "%E",
290                         (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]);
291                 g_snprintf(command, sizeof(command),
292                            (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
293                            float_str);
294                 ret = sr_scpi_send(sdi->conn, command);
295                 update_sample_rate = TRUE;
296                 break;
297         case SR_CONF_HORIZ_TRIGGERPOS:
298                 tmp_d = g_variant_get_double(data);
299                 if (tmp_d < 0.0 || tmp_d > 1.0)
300                         return SR_ERR;
301                 state->horiz_triggerpos = tmp_d;
302                 tmp_d = -(tmp_d - 0.5) *
303                         ((double) (*model->timebases)[state->timebase][0] /
304                         (*model->timebases)[state->timebase][1])
305                          * model->num_xdivs;
306                 g_ascii_formatd(float_str, sizeof(float_str), "%E", tmp_d);
307                 g_snprintf(command, sizeof(command),
308                            (*model->scpi_dialect)[SCPI_CMD_SET_HORIZ_TRIGGERPOS],
309                            float_str);
310                 ret = sr_scpi_send(sdi->conn, command);
311                 break;
312         case SR_CONF_TRIGGER_SLOPE:
313                 if ((idx = std_str_idx(data, *model->trigger_slopes, model->num_trigger_slopes)) < 0)
314                         return SR_ERR_ARG;
315                 state->trigger_slope = idx;
316                 g_snprintf(command, sizeof(command),
317                            (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
318                            (*model->trigger_slopes)[idx]);
319                 ret = sr_scpi_send(sdi->conn, command);
320                 break;
321         case SR_CONF_COUPLING:
322                 if (!cg)
323                         return SR_ERR_CHANNEL_GROUP;
324                 if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
325                         return SR_ERR_ARG;
326                 if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
327                         return SR_ERR_ARG;
328                 state->analog_channels[j].coupling = idx;
329                 g_snprintf(command, sizeof(command),
330                            (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING],
331                            j + 1, (*model->coupling_options)[idx]);
332                 if (sr_scpi_send(sdi->conn, command) != SR_OK ||
333                     sr_scpi_get_opc(sdi->conn) != SR_OK)
334                         return SR_ERR;
335                 ret = SR_OK;
336                 break;
337         default:
338                 ret = SR_ERR_NA;
339                 break;
340         }
341
342         if (ret == SR_OK)
343                 ret = sr_scpi_get_opc(sdi->conn);
344
345         if (ret == SR_OK && update_sample_rate)
346                 ret = hmo_update_sample_rate(sdi);
347
348         return ret;
349 }
350
351 static int config_list(uint32_t key, GVariant **data,
352         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
353 {
354         int cg_type = CG_NONE;
355         struct dev_context *devc = NULL;
356         const struct scope_config *model = NULL;
357
358         if (sdi) {
359                 devc = sdi->priv;
360                 if ((cg_type = check_channel_group(devc, cg)) == CG_INVALID)
361                         return SR_ERR;
362
363                 model = devc->model_config;
364         }
365
366         switch (key) {
367         case SR_CONF_SCAN_OPTIONS:
368                 *data = std_gvar_array_u32(ARRAY_AND_SIZE(scanopts));
369                 break;
370         case SR_CONF_DEVICE_OPTIONS:
371                 if (!cg) {
372                         if (model)
373                                 *data = std_gvar_array_u32(*model->devopts, model->num_devopts);
374                         else
375                                 *data = std_gvar_array_u32(ARRAY_AND_SIZE(drvopts));
376                 } else if (cg_type == CG_ANALOG) {
377                         *data = std_gvar_array_u32(*model->devopts_cg_analog, model->num_devopts_cg_analog);
378                 } else {
379                         *data = std_gvar_array_u32(NULL, 0);
380                 }
381                 break;
382         case SR_CONF_COUPLING:
383                 if (!cg)
384                         return SR_ERR_CHANNEL_GROUP;
385                 if (!model)
386                         return SR_ERR_ARG;
387                 *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
388                 break;
389         case SR_CONF_TRIGGER_SOURCE:
390                 if (!model)
391                         return SR_ERR_ARG;
392                 *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
393                 break;
394         case SR_CONF_TRIGGER_SLOPE:
395                 if (!model)
396                         return SR_ERR_ARG;
397                 *data = g_variant_new_strv(*model->trigger_slopes, model->num_trigger_slopes);
398                 break;
399         case SR_CONF_TIMEBASE:
400                 if (!model)
401                         return SR_ERR_ARG;
402                 *data = std_gvar_tuple_array(*model->timebases, model->num_timebases);
403                 break;
404         case SR_CONF_VDIV:
405                 if (!cg)
406                         return SR_ERR_CHANNEL_GROUP;
407                 if (!model)
408                         return SR_ERR_ARG;
409                 *data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs);
410                 break;
411         default:
412                 return SR_ERR_NA;
413         }
414
415         return SR_OK;
416 }
417
418 SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
419 {
420         char command[MAX_COMMAND_SIZE];
421         struct sr_channel *ch;
422         struct dev_context *devc;
423         const struct scope_config *model;
424
425         devc = sdi->priv;
426         model = devc->model_config;
427
428         ch = devc->current_channel->data;
429
430         switch (ch->type) {
431         case SR_CHANNEL_ANALOG:
432                 g_snprintf(command, sizeof(command),
433                            (*model->scpi_dialect)[SCPI_CMD_GET_ANALOG_DATA],
434 #ifdef WORDS_BIGENDIAN
435                            "MSBF",
436 #else
437                            "LSBF",
438 #endif
439                            ch->index + 1);
440                 break;
441         case SR_CHANNEL_LOGIC:
442                 g_snprintf(command, sizeof(command),
443                            (*model->scpi_dialect)[SCPI_CMD_GET_DIG_DATA],
444                            ch->index < 8 ? 1 : 2);
445                 break;
446         default:
447                 sr_err("Invalid channel type.");
448                 break;
449         }
450
451         return sr_scpi_send(sdi->conn, command);
452 }
453
454 static int hmo_check_channels(GSList *channels)
455 {
456         GSList *l;
457         struct sr_channel *ch;
458         gboolean enabled_chan[MAX_ANALOG_CHANNEL_COUNT];
459         gboolean enabled_pod[MAX_DIGITAL_GROUP_COUNT];
460         size_t idx;
461
462         /* Preset "not enabled" for all channels / pods. */
463         for (idx = 0; idx < ARRAY_SIZE(enabled_chan); idx++)
464                 enabled_chan[idx] = FALSE;
465         for (idx = 0; idx < ARRAY_SIZE(enabled_pod); idx++)
466                 enabled_pod[idx] = FALSE;
467
468         /*
469          * Determine which channels / pods are required for the caller's
470          * specified configuration.
471          */
472         for (l = channels; l; l = l->next) {
473                 ch = l->data;
474                 switch (ch->type) {
475                 case SR_CHANNEL_ANALOG:
476                         idx = ch->index;
477                         if (idx < ARRAY_SIZE(enabled_chan))
478                                 enabled_chan[idx] = TRUE;
479                         break;
480                 case SR_CHANNEL_LOGIC:
481                         idx = ch->index / 8;
482                         if (idx < ARRAY_SIZE(enabled_pod))
483                                 enabled_pod[idx] = TRUE;
484                         break;
485                 default:
486                         return SR_ERR;
487                 }
488         }
489
490         /*
491          * Check for resource conflicts. Some channels can be either
492          * analog or digital, but never both at the same time.
493          *
494          * Note that the constraints might depend on the specific model.
495          * These tests might need some adjustment when support for more
496          * models gets added to the driver.
497          */
498         if (enabled_pod[0] && enabled_chan[2])
499                 return SR_ERR;
500         if (enabled_pod[1] && enabled_chan[3])
501                 return SR_ERR;
502         return SR_OK;
503 }
504
505 static int hmo_setup_channels(const struct sr_dev_inst *sdi)
506 {
507         GSList *l;
508         unsigned int i;
509         gboolean *pod_enabled, setup_changed;
510         char command[MAX_COMMAND_SIZE];
511         struct scope_state *state;
512         const struct scope_config *model;
513         struct sr_channel *ch;
514         struct dev_context *devc;
515         struct sr_scpi_dev_inst *scpi;
516         int ret;
517
518         devc = sdi->priv;
519         scpi = sdi->conn;
520         state = devc->model_state;
521         model = devc->model_config;
522         setup_changed = FALSE;
523
524         pod_enabled = g_try_malloc0(sizeof(gboolean) * model->digital_pods);
525
526         for (l = sdi->channels; l; l = l->next) {
527                 ch = l->data;
528                 switch (ch->type) {
529                 case SR_CHANNEL_ANALOG:
530                         if (ch->enabled == state->analog_channels[ch->index].state)
531                                 break;
532                         g_snprintf(command, sizeof(command),
533                                    (*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE],
534                                    ch->index + 1, ch->enabled);
535
536                         if (sr_scpi_send(scpi, command) != SR_OK) {
537                                 g_free(pod_enabled);
538                                 return SR_ERR;
539                         }
540                         state->analog_channels[ch->index].state = ch->enabled;
541                         setup_changed = TRUE;
542                         break;
543                 case SR_CHANNEL_LOGIC:
544                         /*
545                          * A digital POD needs to be enabled for every group of
546                          * 8 channels.
547                          */
548                         if (ch->enabled)
549                                 pod_enabled[ch->index < 8 ? 0 : 1] = TRUE;
550
551                         if (ch->enabled == state->digital_channels[ch->index])
552                                 break;
553                         g_snprintf(command, sizeof(command),
554                                    (*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
555                                    ch->index, ch->enabled);
556
557                         if (sr_scpi_send(scpi, command) != SR_OK) {
558                                 g_free(pod_enabled);
559                                 return SR_ERR;
560                         }
561
562                         state->digital_channels[ch->index] = ch->enabled;
563                         setup_changed = TRUE;
564                         break;
565                 default:
566                         g_free(pod_enabled);
567                         return SR_ERR;
568                 }
569         }
570
571         ret = SR_OK;
572         for (i = 0; i < model->digital_pods; i++) {
573                 if (state->digital_pods[i] == pod_enabled[i])
574                         continue;
575                 g_snprintf(command, sizeof(command),
576                            (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
577                            i + 1, pod_enabled[i]);
578                 if (sr_scpi_send(scpi, command) != SR_OK) {
579                         ret = SR_ERR;
580                         break;
581                 }
582                 state->digital_pods[i] = pod_enabled[i];
583                 setup_changed = TRUE;
584         }
585         g_free(pod_enabled);
586         if (ret != SR_OK)
587                 return ret;
588
589         if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
590                 return SR_ERR;
591
592         return SR_OK;
593 }
594
595 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
596 {
597         GSList *l;
598         gboolean digital_added[MAX_DIGITAL_GROUP_COUNT];
599         size_t group, pod_count;
600         struct sr_channel *ch;
601         struct dev_context *devc;
602         struct sr_scpi_dev_inst *scpi;
603         int ret;
604
605         scpi = sdi->conn;
606         devc = sdi->priv;
607
608         devc->num_samples = 0;
609         devc->num_frames = 0;
610
611         /* Preset empty results. */
612         for (group = 0; group < ARRAY_SIZE(digital_added); group++)
613                 digital_added[group] = FALSE;
614         g_slist_free(devc->enabled_channels);
615         devc->enabled_channels = NULL;
616
617         /*
618          * Contruct the list of enabled channels. Determine the highest
619          * number of digital pods involved in the acquisition.
620          */
621         pod_count = 0;
622         for (l = sdi->channels; l; l = l->next) {
623                 ch = l->data;
624                 if (!ch->enabled)
625                         continue;
626                 /* Only add a single digital channel per group (pod). */
627                 group = ch->index / 8;
628                 if (ch->type != SR_CHANNEL_LOGIC || !digital_added[group]) {
629                         devc->enabled_channels = g_slist_append(
630                                         devc->enabled_channels, ch);
631                         if (ch->type == SR_CHANNEL_LOGIC) {
632                                 digital_added[group] = TRUE;
633                                 if (pod_count < group + 1)
634                                         pod_count = group + 1;
635                         }
636                 }
637         }
638         if (!devc->enabled_channels)
639                 return SR_ERR;
640         devc->pod_count = pod_count;
641         devc->logic_data = NULL;
642
643         /*
644          * Check constraints. Some channels can be either analog or
645          * digital, but not both at the same time.
646          */
647         if (hmo_check_channels(devc->enabled_channels) != SR_OK) {
648                 sr_err("Invalid channel configuration specified!");
649                 ret = SR_ERR_NA;
650                 goto free_enabled;
651         }
652
653         /*
654          * Configure the analog and digital channels and the
655          * corresponding digital pods.
656          */
657         if (hmo_setup_channels(sdi) != SR_OK) {
658                 sr_err("Failed to setup channel configuration!");
659                 ret = SR_ERR;
660                 goto free_enabled;
661         }
662
663         /*
664          * Start acquisition on the first enabled channel. The
665          * receive routine will continue driving the acquisition.
666          */
667         sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
668                         hmo_receive_data, (void *)sdi);
669
670         std_session_send_df_header(sdi);
671
672         devc->current_channel = devc->enabled_channels;
673
674         return hmo_request_data(sdi);
675
676 free_enabled:
677         g_slist_free(devc->enabled_channels);
678         devc->enabled_channels = NULL;
679         return ret;
680 }
681
682 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
683 {
684         struct dev_context *devc;
685         struct sr_scpi_dev_inst *scpi;
686
687         std_session_send_df_end(sdi);
688
689         devc = sdi->priv;
690
691         devc->num_samples = 0;
692         devc->num_frames = 0;
693         g_slist_free(devc->enabled_channels);
694         devc->enabled_channels = NULL;
695         scpi = sdi->conn;
696         sr_scpi_source_remove(sdi->session, scpi);
697
698         return SR_OK;
699 }
700
701 static struct sr_dev_driver hameg_hmo_driver_info = {
702         .name = "hameg-hmo",
703         .longname = "Hameg HMO",
704         .api_version = 1,
705         .init = std_init,
706         .cleanup = std_cleanup,
707         .scan = scan,
708         .dev_list = std_dev_list,
709         .dev_clear = dev_clear,
710         .config_get = config_get,
711         .config_set = config_set,
712         .config_list = config_list,
713         .dev_open = dev_open,
714         .dev_close = dev_close,
715         .dev_acquisition_start = dev_acquisition_start,
716         .dev_acquisition_stop = dev_acquisition_stop,
717         .context = NULL,
718 };
719 SR_REGISTER_DEV_DRIVER(hameg_hmo_driver_info);