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