2 * This file is part of the libsigrok project.
4 * Copyright (C) 2012 Martin Ling <martin-git@earth.li>
5 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
6 * Copyright (C) 2013 Mathias Grimmberger <mgri@zaphod.sax.de>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "libsigrok.h"
28 #include "libsigrok-internal.h"
31 static const int32_t hwopts[] = {
36 static const int32_t hwcaps[] = {
39 SR_CONF_TRIGGER_SOURCE,
40 SR_CONF_TRIGGER_SLOPE,
41 SR_CONF_HORIZ_TRIGGERPOS,
45 static const int32_t analog_hwcaps[] = {
52 static const uint64_t timebases[][2] = {
91 /* { 1000, 1 }, Confuses other code? */
94 static const uint64_t vdivs[][2] = {
114 #define NUM_TIMEBASE ARRAY_SIZE(timebases)
115 #define NUM_VDIV ARRAY_SIZE(vdivs)
117 static const char *trigger_sources[] = {
140 static const char *coupling[] = {
146 /* Do not change the order of entries */
147 static const char *data_sources[] = {
154 * name, series, protocol flavor, min timebase, max timebase, min vdiv,
155 * digital channels, number of horizontal divs
157 static const struct rigol_ds_model supported_models[] = {
158 {"DS1052E", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, false, 12},
159 {"DS1102E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 12},
160 {"DS1152E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 12},
161 {"DS1052D", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, true, 12},
162 {"DS1102D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 12},
163 {"DS1152D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 12},
164 {"DS2072", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
165 {"DS2102", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
166 {"DS2202", RIGOL_DS2000, PROTOCOL_IEEE488_2, {2, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
167 {"VS5022", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, false, 14},
168 {"VS5022D", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, true, 14},
169 {"VS5042", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, false, 14},
170 {"VS5042D", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, true, 14},
171 {"VS5062", RIGOL_VS5000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, false, 14},
172 {"VS5062D", RIGOL_VS5000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, true, 14},
173 {"VS5102", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 14},
174 {"VS5102D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 14},
175 {"VS5202", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 14},
176 {"VS5202D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 14},
179 SR_PRIV struct sr_dev_driver rigol_ds_driver_info;
180 static struct sr_dev_driver *di = &rigol_ds_driver_info;
182 static void clear_helper(void *priv)
184 struct dev_context *devc;
188 g_free(devc->buffer);
189 g_free(devc->coupling[0]);
190 g_free(devc->coupling[1]);
191 g_free(devc->trigger_source);
192 g_free(devc->trigger_slope);
193 g_slist_free(devc->analog_groups[0].probes);
194 g_slist_free(devc->analog_groups[1].probes);
195 g_slist_free(devc->digital_group.probes);
198 static int dev_clear(void)
200 return std_dev_clear(di, clear_helper);
203 static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
208 va_start(args, format);
209 ret = sr_scpi_send_variadic(sdi->conn, format, args);
215 /* When setting a bunch of parameters in a row, the DS1052E scrambles
216 * some of them unless there is at least 100ms delay in between. */
217 sr_spew("delay %dms", 100);
223 static int init(struct sr_context *sr_ctx)
225 return std_init(sr_ctx, di, LOG_PREFIX);
228 static int probe_port(const char *resource, const char *serialcomm, GSList **devices)
230 struct dev_context *devc;
231 struct sr_dev_inst *sdi;
232 const char *usbtmc_prefix = "/dev/usbtmc";
233 const char *tcp_prefix = "tcp/";
234 gchar **tokens, *address, *port;
235 struct sr_scpi_dev_inst *scpi;
236 struct sr_scpi_hw_info *hw_info;
237 struct sr_probe *probe;
239 const struct rigol_ds_model *model = NULL;
244 if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) {
245 sr_dbg("Opening USBTMC device %s.", resource);
246 if (!(scpi = scpi_usbtmc_dev_inst_new(resource)))
247 return SR_ERR_MALLOC;
248 } else if (strncmp(resource, tcp_prefix, strlen(tcp_prefix)) == 0) {
249 sr_dbg("Opening TCP connection %s.", resource);
250 tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
253 if (!address || !port || tokens[2]) {
254 sr_err("Invalid parameters.");
258 scpi = scpi_tcp_dev_inst_new(address, port);
261 return SR_ERR_MALLOC;
263 sr_dbg("Opening serial device %s.", resource);
264 if (!(scpi = scpi_serial_dev_inst_new(resource, serialcomm)))
265 return SR_ERR_MALLOC;
268 if (sr_scpi_open(scpi) != SR_OK) {
273 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
274 sr_info("Couldn't get IDN response.");
280 if (strcasecmp(hw_info->manufacturer, "Rigol Technologies")) {
281 sr_scpi_hw_info_free(hw_info);
286 for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
287 if (!strcmp(hw_info->model, supported_models[i].name)) {
288 model = &supported_models[i];
293 if (!model || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
294 hw_info->manufacturer, hw_info->model,
295 hw_info->firmware_version))) {
296 sr_scpi_hw_info_free(hw_info);
301 sr_scpi_hw_info_free(hw_info);
306 sdi->inst_type = SR_INST_SCPI;
308 if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
309 return SR_ERR_MALLOC;
311 devc->limit_frames = 0;
314 for (i = 0; i < 2; i++) {
315 channel_name = (i == 0 ? "CH1" : "CH2");
316 if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, channel_name)))
317 return SR_ERR_MALLOC;
318 sdi->probes = g_slist_append(sdi->probes, probe);
319 devc->analog_groups[i].name = channel_name;
320 devc->analog_groups[i].probes = g_slist_append(NULL, probe);
321 sdi->probe_groups = g_slist_append(sdi->probe_groups,
322 &devc->analog_groups[i]);
325 if (devc->model->has_digital) {
326 for (i = 0; i < 16; i++) {
327 if (!(channel_name = g_strdup_printf("D%d", i)))
328 return SR_ERR_MALLOC;
329 probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name);
330 g_free(channel_name);
332 return SR_ERR_MALLOC;
333 sdi->probes = g_slist_append(sdi->probes, probe);
334 devc->digital_group.probes = g_slist_append(
335 devc->digital_group.probes, probe);
337 devc->digital_group.name = "LA";
338 sdi->probe_groups = g_slist_append(sdi->probe_groups,
339 &devc->digital_group);
342 for (i = 0; i < NUM_TIMEBASE; i++) {
343 if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
344 devc->timebases = &timebases[i];
345 if (!memcmp(&devc->model->max_timebase, &timebases[i], sizeof(uint64_t[2])))
346 devc->num_timebases = &timebases[i] - devc->timebases + 1;
349 for (i = 0; i < NUM_VDIV; i++) {
350 if (!memcmp(&devc->model->min_vdiv, &vdivs[i], sizeof(uint64_t[2]))) {
351 devc->vdivs = &vdivs[i];
352 devc->num_vdivs = NUM_VDIV - (&vdivs[i] - &vdivs[0]);
356 if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE)))
357 return SR_ERR_MALLOC;
358 if (!(devc->data = g_try_malloc(ACQ_BUFFER_SIZE * sizeof(float))))
359 return SR_ERR_MALLOC;
361 devc->data_source = DATA_SOURCE_LIVE;
365 *devices = g_slist_append(NULL, sdi);
370 static GSList *scan(GSList *options)
372 struct drv_context *drvc;
373 struct sr_config *src;
377 const gchar *dev_name;
379 gchar *serialcomm = NULL;
383 for (l = options; l; l = l->next) {
387 port = (char *)g_variant_get_string(src->data, NULL);
389 case SR_CONF_SERIALCOMM:
390 serialcomm = (char *)g_variant_get_string(src->data, NULL);
397 if (probe_port(port, serialcomm, &devices) == SR_ERR_MALLOC) {
404 if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL)))
405 if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL)))
407 while ((dev_name = g_dir_read_name(dir))) {
408 if (strncmp(dev_name, "usbtmc", 6))
410 port = g_strconcat("/dev/", dev_name, NULL);
411 ret = probe_port(port, serialcomm, &devices);
415 if (ret == SR_ERR_MALLOC) {
423 /* Tack a copy of the newly found devices onto the driver list. */
424 l = g_slist_copy(devices);
425 drvc->instances = g_slist_concat(drvc->instances, l);
430 static GSList *dev_list(void)
432 return ((struct drv_context *)(di->priv))->instances;
435 static int dev_open(struct sr_dev_inst *sdi)
437 struct sr_scpi_dev_inst *scpi = sdi->conn;
439 if (sr_scpi_open(scpi) < 0)
442 if (rigol_ds_get_dev_cfg(sdi) != SR_OK)
445 sdi->status = SR_ST_ACTIVE;
450 static int dev_close(struct sr_dev_inst *sdi)
452 struct sr_scpi_dev_inst *scpi;
457 if (sr_scpi_close(scpi) < 0)
459 sdi->status = SR_ST_INACTIVE;
465 static int cleanup(void)
470 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
471 const struct sr_probe_group *probe_group)
473 struct dev_context *devc;
476 if (!sdi || !(devc = sdi->priv))
479 /* If a probe group is specified, it must be a valid one. */
481 if (probe_group != &devc->analog_groups[0]
482 && probe_group != &devc->analog_groups[1]) {
483 sr_err("Invalid probe group specified.");
489 case SR_CONF_NUM_TIMEBASE:
490 *data = g_variant_new_int32(devc->num_timebases);
492 case SR_CONF_NUM_VDIV:
494 sr_err("No probe group specified.");
495 return SR_ERR_PROBE_GROUP;
497 for (i = 0; i < 2; i++) {
498 if (probe_group == &devc->analog_groups[i]) {
499 *data = g_variant_new_int32(devc->num_vdivs);
504 case SR_CONF_DATA_SOURCE:
505 if (devc->data_source == DATA_SOURCE_LIVE)
506 *data = g_variant_new_string("Live");
507 else if (devc->data_source == DATA_SOURCE_MEMORY)
508 *data = g_variant_new_string("Memory");
510 *data = g_variant_new_string("Segmented");
519 static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
520 const struct sr_probe_group *probe_group)
522 struct dev_context *devc;
523 uint64_t tmp_u64, p, q;
529 if (!(devc = sdi->priv))
532 if (sdi->status != SR_ST_ACTIVE)
533 return SR_ERR_DEV_CLOSED;
535 /* If a probe group is specified, it must be a valid one. */
537 if (probe_group != &devc->analog_groups[0]
538 && probe_group != &devc->analog_groups[1]) {
539 sr_err("Invalid probe group specified.");
546 case SR_CONF_LIMIT_FRAMES:
547 devc->limit_frames = g_variant_get_uint64(data);
549 case SR_CONF_TRIGGER_SLOPE:
550 tmp_u64 = g_variant_get_uint64(data);
551 if (tmp_u64 != 0 && tmp_u64 != 1)
553 g_free(devc->trigger_slope);
554 devc->trigger_slope = g_strdup(tmp_u64 ? "POS" : "NEG");
555 ret = set_cfg(sdi, ":TRIG:EDGE:SLOP %s", devc->trigger_slope);
557 case SR_CONF_HORIZ_TRIGGERPOS:
558 t_dbl = g_variant_get_double(data);
559 if (t_dbl < 0.0 || t_dbl > 1.0)
561 devc->horiz_triggerpos = t_dbl;
562 /* We have the trigger offset as a percentage of the frame, but
563 * need to express this in seconds. */
564 t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * devc->num_timebases;
565 ret = set_cfg(sdi, ":TIM:OFFS %.6f", t_dbl);
567 case SR_CONF_TIMEBASE:
568 g_variant_get(data, "(tt)", &p, &q);
569 for (i = 0; i < devc->num_timebases; i++) {
570 if (devc->timebases[i][0] == p && devc->timebases[i][1] == q) {
571 devc->timebase = (float)p / q;
572 ret = set_cfg(sdi, ":TIM:SCAL %.9f", devc->timebase);
576 if (i == devc->num_timebases)
579 case SR_CONF_TRIGGER_SOURCE:
580 tmp_str = g_variant_get_string(data, NULL);
581 for (i = 0; i < ARRAY_SIZE(trigger_sources); i++) {
582 if (!strcmp(trigger_sources[i], tmp_str)) {
583 g_free(devc->trigger_source);
584 devc->trigger_source = g_strdup(trigger_sources[i]);
585 if (!strcmp(devc->trigger_source, "AC Line"))
587 else if (!strcmp(devc->trigger_source, "CH1"))
589 else if (!strcmp(devc->trigger_source, "CH2"))
592 tmp_str = (char *)devc->trigger_source;
593 ret = set_cfg(sdi, ":TRIG:EDGE:SOUR %s", tmp_str);
597 if (i == ARRAY_SIZE(trigger_sources))
602 sr_err("No probe group specified.");
603 return SR_ERR_PROBE_GROUP;
605 g_variant_get(data, "(tt)", &p, &q);
606 for (i = 0; i < 2; i++) {
607 if (probe_group == &devc->analog_groups[i]) {
608 for (j = 0; j < ARRAY_SIZE(vdivs); j++) {
609 if (vdivs[j][0] != p || vdivs[j][1] != q)
611 devc->vdiv[i] = (float)p / q;
612 return set_cfg(sdi, ":CHAN%d:SCAL %.3f", i + 1,
619 case SR_CONF_COUPLING:
621 sr_err("No probe group specified.");
622 return SR_ERR_PROBE_GROUP;
624 tmp_str = g_variant_get_string(data, NULL);
625 for (i = 0; i < 2; i++) {
626 if (probe_group == &devc->analog_groups[i]) {
627 for (j = 0; j < ARRAY_SIZE(coupling); j++) {
628 if (!strcmp(tmp_str, coupling[j])) {
629 g_free(devc->coupling[i]);
630 devc->coupling[i] = g_strdup(coupling[j]);
631 return set_cfg(sdi, ":CHAN%d:COUP %s", i + 1,
639 case SR_CONF_DATA_SOURCE:
640 tmp_str = g_variant_get_string(data, NULL);
641 if (!strcmp(tmp_str, "Live"))
642 devc->data_source = DATA_SOURCE_LIVE;
643 else if (!strcmp(tmp_str, "Memory"))
644 devc->data_source = DATA_SOURCE_MEMORY;
645 else if (devc->model->protocol == PROTOCOL_IEEE488_2
646 && !strcmp(tmp_str, "Segmented"))
647 devc->data_source = DATA_SOURCE_SEGMENTED;
659 static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
660 const struct sr_probe_group *probe_group)
662 GVariant *tuple, *rational[2];
665 struct dev_context *devc = NULL;
670 if (key == SR_CONF_SCAN_OPTIONS) {
671 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
672 hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
674 } else if (key == SR_CONF_DEVICE_OPTIONS && probe_group == NULL) {
675 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
676 hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
680 /* Every other option requires a valid device instance. */
681 if (!sdi || !(devc = sdi->priv))
684 /* If a probe group is specified, it must be a valid one. */
686 if (probe_group != &devc->analog_groups[0]
687 && probe_group != &devc->analog_groups[1]) {
688 sr_err("Invalid probe group specified.");
695 case SR_CONF_DEVICE_OPTIONS:
697 sr_err("No probe group specified.");
698 return SR_ERR_PROBE_GROUP;
700 if (probe_group == &devc->digital_group) {
701 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
702 NULL, 0, sizeof(int32_t));
705 for (i = 0; i < 2; i++) {
706 if (probe_group == &devc->analog_groups[i]) {
707 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
708 analog_hwcaps, ARRAY_SIZE(analog_hwcaps), sizeof(int32_t));
715 case SR_CONF_COUPLING:
717 sr_err("No probe group specified.");
718 return SR_ERR_PROBE_GROUP;
720 *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
724 /* Can't know this until we have the exact model. */
727 sr_err("No probe group specified.");
728 return SR_ERR_PROBE_GROUP;
730 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
731 for (i = 0; i < devc->num_vdivs; i++) {
732 rational[0] = g_variant_new_uint64(devc->vdivs[i][0]);
733 rational[1] = g_variant_new_uint64(devc->vdivs[i][1]);
734 tuple = g_variant_new_tuple(rational, 2);
735 g_variant_builder_add_value(&gvb, tuple);
737 *data = g_variant_builder_end(&gvb);
739 case SR_CONF_TIMEBASE:
741 /* Can't know this until we have the exact model. */
743 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
744 for (i = 0; i < devc->num_timebases; i++) {
745 rational[0] = g_variant_new_uint64(devc->timebases[i][0]);
746 rational[1] = g_variant_new_uint64(devc->timebases[i][1]);
747 tuple = g_variant_new_tuple(rational, 2);
748 g_variant_builder_add_value(&gvb, tuple);
750 *data = g_variant_builder_end(&gvb);
752 case SR_CONF_TRIGGER_SOURCE:
754 /* Can't know this until we have the exact model. */
756 *data = g_variant_new_strv(trigger_sources,
757 devc->model->has_digital ? ARRAY_SIZE(trigger_sources) : 4);
759 case SR_CONF_DATA_SOURCE:
761 /* Can't know this until we have the exact model. */
763 /* This needs tweaking by series/model! */
764 if (devc->model->series == RIGOL_DS2000)
765 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
767 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 1);
776 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
778 struct sr_scpi_dev_inst *scpi;
779 struct dev_context *devc;
780 struct sr_probe *probe;
784 if (sdi->status != SR_ST_ACTIVE)
785 return SR_ERR_DEV_CLOSED;
790 if (devc->data_source == DATA_SOURCE_LIVE) {
791 if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK)
793 } else if (devc->data_source == DATA_SOURCE_MEMORY) {
794 if (devc->model->series != RIGOL_DS2000) {
795 sr_err("Data source 'Memory' not supported for this device");
798 } else if (devc->data_source == DATA_SOURCE_SEGMENTED) {
799 sr_err("Data source 'Segmented' not yet supported");
803 for (l = sdi->probes; l; l = l->next) {
805 sr_dbg("handling probe %s", probe->name);
806 if (probe->type == SR_PROBE_ANALOG) {
808 devc->enabled_analog_probes = g_slist_append(
809 devc->enabled_analog_probes, probe);
810 if (probe->enabled != devc->analog_channels[probe->index]) {
811 /* Enabled channel is currently disabled, or vice versa. */
812 sprintf(cmd, ":CHAN%d:DISP %s", probe->index + 1,
813 probe->enabled ? "ON" : "OFF");
814 if (sr_scpi_send(sdi->conn, cmd) != SR_OK)
817 } else if (probe->type == SR_PROBE_LOGIC) {
819 devc->enabled_digital_probes = g_slist_append(
820 devc->enabled_digital_probes, probe);
821 if (probe->enabled != devc->digital_channels[probe->index]) {
822 /* Enabled channel is currently disabled, or vice versa. */
823 sprintf(cmd, ":DIG%d:TURN %s", probe->index,
824 probe->enabled ? "ON" : "OFF");
825 if (sr_scpi_send(sdi->conn, cmd) != SR_OK)
830 if (!devc->enabled_analog_probes && !devc->enabled_digital_probes)
833 sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi);
835 /* Send header packet to the session bus. */
836 std_session_send_df_header(cb_data, LOG_PREFIX);
838 if (devc->model->protocol == PROTOCOL_LEGACY) {
839 /* Fetch the first frame. */
840 if (devc->enabled_analog_probes) {
841 devc->analog_frame_size = DS1000_ANALOG_LIVE_WAVEFORM_SIZE;
842 devc->channel_frame = devc->enabled_analog_probes->data;
843 if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d",
844 devc->channel_frame->index + 1) != SR_OK)
847 devc->channel_frame = devc->enabled_digital_probes->data;
848 if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK)
852 devc->num_frame_bytes = 0;
854 if (devc->enabled_analog_probes) {
855 if (devc->data_source == DATA_SOURCE_MEMORY)
857 if (g_slist_length(devc->enabled_analog_probes) == 1)
858 devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C;
860 devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C;
861 /* Apparently for the DS2000 the memory
862 * depth can only be set in Running state -
863 * this matches the behaviour of the UI. */
864 if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK)
866 if (sr_scpi_send(sdi->conn, "ACQ:MDEP %d", devc->analog_frame_size) != SR_OK)
868 if (sr_scpi_send(sdi->conn, ":STOP") != SR_OK)
871 devc->analog_frame_size = DS2000_ANALOG_LIVE_WAVEFORM_SIZE;
872 devc->channel_frame = devc->enabled_analog_probes->data;
873 if (rigol_ds_capture_start(sdi) != SR_OK)
881 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
883 struct dev_context *devc;
884 struct sr_scpi_dev_inst *scpi;
890 if (sdi->status != SR_ST_ACTIVE) {
891 sr_err("Device inactive, can't stop acquisition.");
895 g_slist_free(devc->enabled_analog_probes);
896 g_slist_free(devc->enabled_digital_probes);
897 devc->enabled_analog_probes = NULL;
898 devc->enabled_digital_probes = NULL;
900 sr_scpi_source_remove(scpi);
905 SR_PRIV struct sr_dev_driver rigol_ds_driver_info = {
907 .longname = "Rigol DS",
912 .dev_list = dev_list,
913 .dev_clear = dev_clear,
914 .config_get = config_get,
915 .config_set = config_set,
916 .config_list = config_list,
917 .dev_open = dev_open,
918 .dev_close = dev_close,
919 .dev_acquisition_start = dev_acquisition_start,
920 .dev_acquisition_stop = dev_acquisition_stop,