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[] = {
142 static const char *coupling[] = {
148 /* Do not change the order of entries */
149 static const char *data_sources[] = {
156 * name, series, protocol flavor, min timebase, max timebase, min vdiv,
157 * digital channels, number of horizontal divs
160 #define RIGOL "Rigol Technologies"
161 #define AGILENT "Agilent Technologies"
163 static const struct rigol_ds_model supported_models[] = {
164 {RIGOL, "DS1052E", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, 2, false, 12},
165 {RIGOL, "DS1102E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, false, 12},
166 {RIGOL, "DS1152E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, false, 12},
167 {RIGOL, "DS1052D", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, 2, true, 12},
168 {RIGOL, "DS1102D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, true, 12},
169 {RIGOL, "DS1152D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, true, 12},
170 {RIGOL, "DS2072", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, 2, false, 14},
171 {RIGOL, "DS2102", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, 2, false, 14},
172 {RIGOL, "DS2202", RIGOL_DS2000, PROTOCOL_IEEE488_2, {2, 1000000000}, {500, 1}, {500, 1000000}, 2, false, 14},
173 {RIGOL, "VS5022", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, 2, false, 14},
174 {RIGOL, "VS5022D", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, 2, true, 14},
175 {RIGOL, "VS5042", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, 2, false, 14},
176 {RIGOL, "VS5042D", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, 2, true, 14},
177 {RIGOL, "VS5062", RIGOL_VS5000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, 2, false, 14},
178 {RIGOL, "VS5062D", RIGOL_VS5000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, 2, true, 14},
179 {RIGOL, "VS5102", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, false, 14},
180 {RIGOL, "VS5102D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, true, 14},
181 {RIGOL, "VS5202", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, false, 14},
182 {RIGOL, "VS5202D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, 2, true, 14},
183 {AGILENT, "DSO1014A", AGILENT_DSO1000, PROTOCOL_IEEE488_2, {2, 1000000000}, {50, 1}, {2, 1000}, 4, false, 12},
186 SR_PRIV struct sr_dev_driver rigol_ds_driver_info;
187 static struct sr_dev_driver *di = &rigol_ds_driver_info;
189 static void clear_helper(void *priv)
191 struct dev_context *devc;
195 g_free(devc->buffer);
196 g_free(devc->coupling[0]);
197 g_free(devc->coupling[1]);
198 g_free(devc->trigger_source);
199 g_free(devc->trigger_slope);
200 g_slist_free(devc->analog_groups[0].probes);
201 g_slist_free(devc->analog_groups[1].probes);
202 g_slist_free(devc->digital_group.probes);
205 static int dev_clear(void)
207 return std_dev_clear(di, clear_helper);
210 static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
215 va_start(args, format);
216 ret = sr_scpi_send_variadic(sdi->conn, format, args);
222 /* When setting a bunch of parameters in a row, the DS1052E scrambles
223 * some of them unless there is at least 100ms delay in between. */
224 sr_spew("delay %dms", 100);
230 static int init(struct sr_context *sr_ctx)
232 return std_init(sr_ctx, di, LOG_PREFIX);
235 static int probe_port(const char *resource, const char *serialcomm, GSList **devices)
237 struct dev_context *devc;
238 struct sr_dev_inst *sdi;
239 const char *usbtmc_prefix = "/dev/usbtmc";
240 const char *tcp_prefix = "tcp/";
241 gchar **tokens, *address, *port;
242 struct sr_scpi_dev_inst *scpi;
243 struct sr_scpi_hw_info *hw_info;
244 struct sr_probe *probe;
246 const struct rigol_ds_model *model = NULL;
251 if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) {
252 sr_dbg("Opening USBTMC device %s.", resource);
253 if (!(scpi = scpi_usbtmc_dev_inst_new(resource)))
254 return SR_ERR_MALLOC;
255 } else if (strncmp(resource, tcp_prefix, strlen(tcp_prefix)) == 0) {
256 sr_dbg("Opening TCP connection %s.", resource);
257 tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
260 if (!address || !port || tokens[2]) {
261 sr_err("Invalid parameters.");
265 scpi = scpi_tcp_dev_inst_new(address, port);
268 return SR_ERR_MALLOC;
270 sr_dbg("Opening serial device %s.", resource);
271 if (!(scpi = scpi_serial_dev_inst_new(resource, serialcomm)))
272 return SR_ERR_MALLOC;
275 if (sr_scpi_open(scpi) != SR_OK) {
276 sr_info("Couldn't open SCPI device.");
281 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
282 sr_info("Couldn't get IDN response.");
288 for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
289 if (!strcasecmp(hw_info->manufacturer, supported_models[i].vendor) &&
290 !strcmp(hw_info->model, supported_models[i].name)) {
291 model = &supported_models[i];
296 if (!model || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
297 hw_info->manufacturer, hw_info->model,
298 hw_info->firmware_version))) {
299 sr_scpi_hw_info_free(hw_info);
305 sr_scpi_hw_info_free(hw_info);
311 sdi->inst_type = SR_INST_SCPI;
313 if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
314 return SR_ERR_MALLOC;
316 devc->limit_frames = 0;
319 for (i = 0; i < model->analog_channels; i++) {
320 if (!(channel_name = g_strdup_printf("CH%d", i + 1)))
321 return SR_ERR_MALLOC;
322 probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, channel_name);
323 sdi->probes = g_slist_append(sdi->probes, probe);
324 devc->analog_groups[i].name = channel_name;
325 devc->analog_groups[i].probes = g_slist_append(NULL, probe);
326 sdi->probe_groups = g_slist_append(sdi->probe_groups,
327 &devc->analog_groups[i]);
330 if (devc->model->has_digital) {
331 for (i = 0; i < 16; i++) {
332 if (!(channel_name = g_strdup_printf("D%d", i)))
333 return SR_ERR_MALLOC;
334 probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name);
335 g_free(channel_name);
337 return SR_ERR_MALLOC;
338 sdi->probes = g_slist_append(sdi->probes, probe);
339 devc->digital_group.probes = g_slist_append(
340 devc->digital_group.probes, probe);
342 devc->digital_group.name = "LA";
343 sdi->probe_groups = g_slist_append(sdi->probe_groups,
344 &devc->digital_group);
347 for (i = 0; i < NUM_TIMEBASE; i++) {
348 if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
349 devc->timebases = &timebases[i];
350 if (!memcmp(&devc->model->max_timebase, &timebases[i], sizeof(uint64_t[2])))
351 devc->num_timebases = &timebases[i] - devc->timebases + 1;
354 for (i = 0; i < NUM_VDIV; i++) {
355 if (!memcmp(&devc->model->min_vdiv, &vdivs[i], sizeof(uint64_t[2]))) {
356 devc->vdivs = &vdivs[i];
357 devc->num_vdivs = NUM_VDIV - (&vdivs[i] - &vdivs[0]);
361 if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE)))
362 return SR_ERR_MALLOC;
363 if (!(devc->data = g_try_malloc(ACQ_BUFFER_SIZE * sizeof(float))))
364 return SR_ERR_MALLOC;
366 devc->data_source = DATA_SOURCE_LIVE;
370 *devices = g_slist_append(NULL, sdi);
375 static GSList *scan(GSList *options)
377 struct drv_context *drvc;
378 struct sr_config *src;
382 const gchar *dev_name;
384 gchar *serialcomm = NULL;
388 for (l = options; l; l = l->next) {
392 port = (char *)g_variant_get_string(src->data, NULL);
394 case SR_CONF_SERIALCOMM:
395 serialcomm = (char *)g_variant_get_string(src->data, NULL);
402 if (probe_port(port, serialcomm, &devices) == SR_ERR_MALLOC) {
409 if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL)))
410 if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL)))
412 while ((dev_name = g_dir_read_name(dir))) {
413 if (strncmp(dev_name, "usbtmc", 6))
415 port = g_strconcat("/dev/", dev_name, NULL);
416 ret = probe_port(port, serialcomm, &devices);
420 if (ret == SR_ERR_MALLOC) {
428 /* Tack a copy of the newly found devices onto the driver list. */
429 l = g_slist_copy(devices);
430 drvc->instances = g_slist_concat(drvc->instances, l);
435 static GSList *dev_list(void)
437 return ((struct drv_context *)(di->priv))->instances;
440 static int dev_open(struct sr_dev_inst *sdi)
442 struct sr_scpi_dev_inst *scpi = sdi->conn;
444 if (sr_scpi_open(scpi) < 0)
447 if (rigol_ds_get_dev_cfg(sdi) != SR_OK)
450 sdi->status = SR_ST_ACTIVE;
455 static int dev_close(struct sr_dev_inst *sdi)
457 struct sr_scpi_dev_inst *scpi;
462 if (sr_scpi_close(scpi) < 0)
464 sdi->status = SR_ST_INACTIVE;
470 static int cleanup(void)
475 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
476 const struct sr_probe_group *probe_group)
478 struct dev_context *devc;
481 if (!sdi || !(devc = sdi->priv))
484 /* If a probe group is specified, it must be a valid one. */
486 if (probe_group != &devc->analog_groups[0]
487 && probe_group != &devc->analog_groups[1]) {
488 sr_err("Invalid probe group specified.");
494 case SR_CONF_NUM_TIMEBASE:
495 *data = g_variant_new_int32(devc->num_timebases);
497 case SR_CONF_NUM_VDIV:
499 sr_err("No probe group specified.");
500 return SR_ERR_PROBE_GROUP;
502 for (i = 0; i < 2; i++) {
503 if (probe_group == &devc->analog_groups[i]) {
504 *data = g_variant_new_int32(devc->num_vdivs);
509 case SR_CONF_DATA_SOURCE:
510 if (devc->data_source == DATA_SOURCE_LIVE)
511 *data = g_variant_new_string("Live");
512 else if (devc->data_source == DATA_SOURCE_MEMORY)
513 *data = g_variant_new_string("Memory");
515 *data = g_variant_new_string("Segmented");
524 static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
525 const struct sr_probe_group *probe_group)
527 struct dev_context *devc;
528 uint64_t tmp_u64, p, q;
534 if (!(devc = sdi->priv))
537 if (sdi->status != SR_ST_ACTIVE)
538 return SR_ERR_DEV_CLOSED;
540 /* If a probe group is specified, it must be a valid one. */
542 if (probe_group != &devc->analog_groups[0]
543 && probe_group != &devc->analog_groups[1]) {
544 sr_err("Invalid probe group specified.");
551 case SR_CONF_LIMIT_FRAMES:
552 devc->limit_frames = g_variant_get_uint64(data);
554 case SR_CONF_TRIGGER_SLOPE:
555 tmp_u64 = g_variant_get_uint64(data);
556 if (tmp_u64 != 0 && tmp_u64 != 1)
558 g_free(devc->trigger_slope);
559 devc->trigger_slope = g_strdup(tmp_u64 ? "POS" : "NEG");
560 ret = set_cfg(sdi, ":TRIG:EDGE:SLOP %s", devc->trigger_slope);
562 case SR_CONF_HORIZ_TRIGGERPOS:
563 t_dbl = g_variant_get_double(data);
564 if (t_dbl < 0.0 || t_dbl > 1.0)
566 devc->horiz_triggerpos = t_dbl;
567 /* We have the trigger offset as a percentage of the frame, but
568 * need to express this in seconds. */
569 t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * devc->num_timebases;
570 ret = set_cfg(sdi, ":TIM:OFFS %.6f", t_dbl);
572 case SR_CONF_TIMEBASE:
573 g_variant_get(data, "(tt)", &p, &q);
574 for (i = 0; i < devc->num_timebases; i++) {
575 if (devc->timebases[i][0] == p && devc->timebases[i][1] == q) {
576 devc->timebase = (float)p / q;
577 ret = set_cfg(sdi, ":TIM:SCAL %.9f", devc->timebase);
581 if (i == devc->num_timebases)
584 case SR_CONF_TRIGGER_SOURCE:
585 tmp_str = g_variant_get_string(data, NULL);
586 for (i = 0; i < ARRAY_SIZE(trigger_sources); i++) {
587 if (!strcmp(trigger_sources[i], tmp_str)) {
588 g_free(devc->trigger_source);
589 devc->trigger_source = g_strdup(trigger_sources[i]);
590 if (!strcmp(devc->trigger_source, "AC Line"))
592 else if (!strcmp(devc->trigger_source, "CH1"))
594 else if (!strcmp(devc->trigger_source, "CH2"))
596 else if (!strcmp(devc->trigger_source, "CH3"))
598 else if (!strcmp(devc->trigger_source, "CH4"))
601 tmp_str = (char *)devc->trigger_source;
602 ret = set_cfg(sdi, ":TRIG:EDGE:SOUR %s", tmp_str);
606 if (i == ARRAY_SIZE(trigger_sources))
611 sr_err("No probe group specified.");
612 return SR_ERR_PROBE_GROUP;
614 g_variant_get(data, "(tt)", &p, &q);
615 for (i = 0; i < 2; i++) {
616 if (probe_group == &devc->analog_groups[i]) {
617 for (j = 0; j < ARRAY_SIZE(vdivs); j++) {
618 if (vdivs[j][0] != p || vdivs[j][1] != q)
620 devc->vdiv[i] = (float)p / q;
621 return set_cfg(sdi, ":CHAN%d:SCAL %.3f", i + 1,
628 case SR_CONF_COUPLING:
630 sr_err("No probe group specified.");
631 return SR_ERR_PROBE_GROUP;
633 tmp_str = g_variant_get_string(data, NULL);
634 for (i = 0; i < 2; i++) {
635 if (probe_group == &devc->analog_groups[i]) {
636 for (j = 0; j < ARRAY_SIZE(coupling); j++) {
637 if (!strcmp(tmp_str, coupling[j])) {
638 g_free(devc->coupling[i]);
639 devc->coupling[i] = g_strdup(coupling[j]);
640 return set_cfg(sdi, ":CHAN%d:COUP %s", i + 1,
648 case SR_CONF_DATA_SOURCE:
649 tmp_str = g_variant_get_string(data, NULL);
650 if (!strcmp(tmp_str, "Live"))
651 devc->data_source = DATA_SOURCE_LIVE;
652 else if (!strcmp(tmp_str, "Memory"))
653 devc->data_source = DATA_SOURCE_MEMORY;
654 else if (devc->model->protocol == PROTOCOL_IEEE488_2
655 && !strcmp(tmp_str, "Segmented"))
656 devc->data_source = DATA_SOURCE_SEGMENTED;
668 static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
669 const struct sr_probe_group *probe_group)
671 GVariant *tuple, *rational[2];
674 struct dev_context *devc = NULL;
679 if (key == SR_CONF_SCAN_OPTIONS) {
680 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
681 hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
683 } else if (key == SR_CONF_DEVICE_OPTIONS && probe_group == NULL) {
684 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
685 hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
689 /* Every other option requires a valid device instance. */
690 if (!sdi || !(devc = sdi->priv))
693 /* If a probe group is specified, it must be a valid one. */
695 if (probe_group != &devc->analog_groups[0]
696 && probe_group != &devc->analog_groups[1]) {
697 sr_err("Invalid probe group specified.");
704 case SR_CONF_DEVICE_OPTIONS:
706 sr_err("No probe group specified.");
707 return SR_ERR_PROBE_GROUP;
709 if (probe_group == &devc->digital_group) {
710 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
711 NULL, 0, sizeof(int32_t));
714 for (i = 0; i < 2; i++) {
715 if (probe_group == &devc->analog_groups[i]) {
716 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
717 analog_hwcaps, ARRAY_SIZE(analog_hwcaps), sizeof(int32_t));
724 case SR_CONF_COUPLING:
726 sr_err("No probe group specified.");
727 return SR_ERR_PROBE_GROUP;
729 *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
733 /* Can't know this until we have the exact model. */
736 sr_err("No probe group specified.");
737 return SR_ERR_PROBE_GROUP;
739 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
740 for (i = 0; i < devc->num_vdivs; i++) {
741 rational[0] = g_variant_new_uint64(devc->vdivs[i][0]);
742 rational[1] = g_variant_new_uint64(devc->vdivs[i][1]);
743 tuple = g_variant_new_tuple(rational, 2);
744 g_variant_builder_add_value(&gvb, tuple);
746 *data = g_variant_builder_end(&gvb);
748 case SR_CONF_TIMEBASE:
750 /* Can't know this until we have the exact model. */
752 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
753 for (i = 0; i < devc->num_timebases; i++) {
754 rational[0] = g_variant_new_uint64(devc->timebases[i][0]);
755 rational[1] = g_variant_new_uint64(devc->timebases[i][1]);
756 tuple = g_variant_new_tuple(rational, 2);
757 g_variant_builder_add_value(&gvb, tuple);
759 *data = g_variant_builder_end(&gvb);
761 case SR_CONF_TRIGGER_SOURCE:
763 /* Can't know this until we have the exact model. */
765 *data = g_variant_new_strv(trigger_sources,
766 devc->model->has_digital ? ARRAY_SIZE(trigger_sources) : 4);
768 case SR_CONF_DATA_SOURCE:
770 /* Can't know this until we have the exact model. */
772 /* This needs tweaking by series/model! */
773 if (devc->model->series == RIGOL_DS2000)
774 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
776 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 1);
785 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
787 struct sr_scpi_dev_inst *scpi;
788 struct dev_context *devc;
789 struct sr_probe *probe;
792 if (sdi->status != SR_ST_ACTIVE)
793 return SR_ERR_DEV_CLOSED;
798 for (l = sdi->probes; l; l = l->next) {
800 sr_dbg("handling probe %s", probe->name);
801 if (probe->type == SR_PROBE_ANALOG) {
803 devc->enabled_analog_probes = g_slist_append(
804 devc->enabled_analog_probes, probe);
805 if (probe->enabled != devc->analog_channels[probe->index]) {
806 /* Enabled channel is currently disabled, or vice versa. */
807 if (set_cfg(sdi, ":CHAN%d:DISP %s", probe->index + 1,
808 probe->enabled ? "ON" : "OFF") != SR_OK)
811 } else if (probe->type == SR_PROBE_LOGIC) {
813 devc->enabled_digital_probes = g_slist_append(
814 devc->enabled_digital_probes, probe);
815 if (probe->enabled != devc->digital_channels[probe->index]) {
816 /* Enabled channel is currently disabled, or vice versa. */
817 if (set_cfg(sdi, ":DIG%d:TURN %s", probe->index,
818 probe->enabled ? "ON" : "OFF") != SR_OK)
824 if (!devc->enabled_analog_probes && !devc->enabled_digital_probes)
827 if (devc->data_source == DATA_SOURCE_LIVE) {
828 if (set_cfg(sdi, ":RUN") != SR_OK)
830 } else if (devc->data_source == DATA_SOURCE_MEMORY) {
831 if (devc->model->series != RIGOL_DS2000) {
832 sr_err("Data source 'Memory' not supported for this device");
835 } else if (devc->data_source == DATA_SOURCE_SEGMENTED) {
836 sr_err("Data source 'Segmented' not yet supported");
840 sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi);
842 /* Send header packet to the session bus. */
843 std_session_send_df_header(cb_data, LOG_PREFIX);
845 if (devc->enabled_analog_probes)
846 devc->channel_entry = devc->enabled_analog_probes;
848 devc->channel_entry = devc->enabled_digital_probes;
850 if (devc->model->protocol == PROTOCOL_LEGACY) {
851 devc->analog_frame_size = (devc->model->series == RIGOL_VS5000 ?
852 VS5000_ANALOG_LIVE_WAVEFORM_SIZE :
853 DS1000_ANALOG_LIVE_WAVEFORM_SIZE);
854 /* Fetch the first frame. */
855 if (rigol_ds_channel_start(sdi) != SR_OK)
858 if (devc->enabled_analog_probes) {
859 if (devc->data_source == DATA_SOURCE_MEMORY)
861 if (g_slist_length(devc->enabled_analog_probes) == 1)
862 devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C;
864 devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C;
865 /* Apparently for the DS2000 the memory
866 * depth can only be set in Running state -
867 * this matches the behaviour of the UI. */
868 if (set_cfg(sdi, ":RUN") != SR_OK)
870 if (set_cfg(sdi, "ACQ:MDEP %d", devc->analog_frame_size) != SR_OK)
872 if (set_cfg(sdi, ":STOP") != SR_OK)
875 if (devc->model->series == AGILENT_DSO1000)
876 devc->analog_frame_size = DSO1000_ANALOG_LIVE_WAVEFORM_SIZE;
878 devc->analog_frame_size = DS2000_ANALOG_LIVE_WAVEFORM_SIZE;
880 if (rigol_ds_capture_start(sdi) != SR_OK)
888 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
890 struct dev_context *devc;
891 struct sr_scpi_dev_inst *scpi;
897 if (sdi->status != SR_ST_ACTIVE) {
898 sr_err("Device inactive, can't stop acquisition.");
902 g_slist_free(devc->enabled_analog_probes);
903 g_slist_free(devc->enabled_digital_probes);
904 devc->enabled_analog_probes = NULL;
905 devc->enabled_digital_probes = NULL;
907 sr_scpi_source_remove(scpi);
912 SR_PRIV struct sr_dev_driver rigol_ds_driver_info = {
914 .longname = "Rigol DS",
919 .dev_list = dev_list,
920 .dev_clear = dev_clear,
921 .config_get = config_get,
922 .config_set = config_set,
923 .config_list = config_list,
924 .dev_open = dev_open,
925 .dev_close = dev_close,
926 .dev_acquisition_start = dev_acquisition_start,
927 .dev_acquisition_stop = dev_acquisition_stop,