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/>.
28 #include "libsigrok.h"
29 #include "libsigrok-internal.h"
32 static const int32_t hwopts[] = {
37 static const int32_t hwcaps[] = {
40 SR_CONF_TRIGGER_SOURCE,
41 SR_CONF_TRIGGER_SLOPE,
42 SR_CONF_HORIZ_TRIGGERPOS,
48 static const int32_t analog_hwcaps[] = {
55 static const uint64_t timebases[][2] = {
98 static const uint64_t vdivs[][2] = {
118 #define NUM_TIMEBASE ARRAY_SIZE(timebases)
119 #define NUM_VDIV ARRAY_SIZE(vdivs)
121 static const char *trigger_sources[] = {
146 static const char *coupling[] = {
152 /* Do not change the order of entries */
153 static const char *data_sources[] = {
172 /* short name, full name */
173 static const struct rigol_ds_vendor supported_vendors[] = {
174 [RIGOL] = {"Rigol", "Rigol Technologies"},
175 [AGILENT] = {"Agilent", "Rigol Technologies"},
178 #define VENDOR(x) &supported_vendors[x]
179 /* vendor, series, protocol, max timebase, min vdiv, number of horizontal divs,
180 * live waveform samples, memory buffer samples */
181 static const struct rigol_ds_series supported_series[] = {
182 [VS5000] = {VENDOR(RIGOL), "VS5000", PROTOCOL_V1, FORMAT_RAW,
183 {50, 1}, {2, 1000}, 14, 2048, 0},
184 [DS1000] = {VENDOR(RIGOL), "DS1000", PROTOCOL_V2, FORMAT_IEEE488_2,
185 {50, 1}, {2, 1000}, 12, 600, 1048576},
186 [DS2000] = {VENDOR(RIGOL), "DS2000", PROTOCOL_V3, FORMAT_IEEE488_2,
187 {500, 1}, {2, 1000}, 14, 1400, 14000},
188 [DS2000A] = {VENDOR(RIGOL), "DS2000A", PROTOCOL_V3, FORMAT_IEEE488_2,
189 {1000, 1}, {500, 1000000}, 14, 1400, 14000},
190 [DSO1000] = {VENDOR(AGILENT), "DSO1000", PROTOCOL_V3, FORMAT_IEEE488_2,
191 {50, 1}, {2, 1000}, 12, 600, 20480},
194 #define SERIES(x) &supported_series[x]
195 /* series, model, min timebase, analog channels, digital */
196 static const struct rigol_ds_model supported_models[] = {
197 {SERIES(VS5000), "VS5022", {20, 1000000000}, 2, false},
198 {SERIES(VS5000), "VS5042", {10, 1000000000}, 2, false},
199 {SERIES(VS5000), "VS5062", {5, 1000000000}, 2, false},
200 {SERIES(VS5000), "VS5102", {2, 1000000000}, 2, false},
201 {SERIES(VS5000), "VS5202", {2, 1000000000}, 2, false},
202 {SERIES(VS5000), "VS5022D", {20, 1000000000}, 2, true},
203 {SERIES(VS5000), "VS5042D", {10, 1000000000}, 2, true},
204 {SERIES(VS5000), "VS5062D", {5, 1000000000}, 2, true},
205 {SERIES(VS5000), "VS5102D", {2, 1000000000}, 2, true},
206 {SERIES(VS5000), "VS5202D", {2, 1000000000}, 2, true},
207 {SERIES(DS1000), "DS1052E", {5, 1000000000}, 2, false},
208 {SERIES(DS1000), "DS1102E", {2, 1000000000}, 2, false},
209 {SERIES(DS1000), "DS1152E", {2, 1000000000}, 2, false},
210 {SERIES(DS1000), "DS1052D", {5, 1000000000}, 2, true},
211 {SERIES(DS1000), "DS1102D", {2, 1000000000}, 2, true},
212 {SERIES(DS1000), "DS1152D", {2, 1000000000}, 2, true},
213 {SERIES(DS2000), "DS2072", {5, 1000000000}, 2, false},
214 {SERIES(DS2000), "DS2102", {5, 1000000000}, 2, false},
215 {SERIES(DS2000), "DS2202", {2, 1000000000}, 2, false},
216 {SERIES(DS2000), "DS2302", {1, 1000000000}, 2, false},
217 {SERIES(DS2000A), "DS2072A", {5, 1000000000}, 2, false},
218 {SERIES(DS2000A), "DS2102A", {5, 1000000000}, 2, false},
219 {SERIES(DS2000A), "DS2202A", {2, 1000000000}, 2, false},
220 {SERIES(DS2000A), "DS2302A", {1, 1000000000}, 2, false},
221 {SERIES(DSO1000), "DSO1002A", {5, 1000000000}, 2, false},
222 {SERIES(DSO1000), "DSO1004A", {5, 1000000000}, 4, false},
223 {SERIES(DSO1000), "DSO1012A", {2, 1000000000}, 2, false},
224 {SERIES(DSO1000), "DSO1014A", {2, 1000000000}, 4, false},
225 {SERIES(DSO1000), "DSO1022A", {2, 1000000000}, 2, false},
226 {SERIES(DSO1000), "DSO1024A", {2, 1000000000}, 4, false},
229 SR_PRIV struct sr_dev_driver rigol_ds_driver_info;
230 static struct sr_dev_driver *di = &rigol_ds_driver_info;
232 static void clear_helper(void *priv)
234 struct dev_context *devc;
238 g_free(devc->buffer);
239 g_free(devc->coupling[0]);
240 g_free(devc->coupling[1]);
241 g_free(devc->trigger_source);
242 g_free(devc->trigger_slope);
243 g_slist_free(devc->analog_groups[0].channels);
244 g_slist_free(devc->analog_groups[1].channels);
245 g_slist_free(devc->digital_group.channels);
248 static int dev_clear(void)
250 return std_dev_clear(di, clear_helper);
253 static int init(struct sr_context *sr_ctx)
255 return std_init(sr_ctx, di, LOG_PREFIX);
258 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
260 struct dev_context *devc;
261 struct sr_dev_inst *sdi;
262 struct sr_scpi_hw_info *hw_info;
263 struct sr_probe *probe;
266 const struct rigol_ds_model *model = NULL;
267 gchar *channel_name, **version;
269 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
270 sr_info("Couldn't get IDN response.");
276 for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
277 if (!strcasecmp(hw_info->manufacturer,
278 supported_models[i].series->vendor->full_name) &&
279 !strcmp(hw_info->model, supported_models[i].name)) {
280 model = &supported_models[i];
285 if (!model || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
286 model->series->vendor->name,
288 hw_info->firmware_version))) {
289 sr_scpi_hw_info_free(hw_info);
300 sdi->inst_type = SR_INST_SCPI;
302 if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
305 devc->limit_frames = 0;
307 devc->format = model->series->format;
309 /* DS1000 models with firmware before 0.2.4 used the old data format. */
310 if (model->series == SERIES(DS1000)) {
311 version = g_strsplit(hw_info->firmware_version, ".", 0);
313 if (!version[0] || !version[1] || !version[2])
315 if (version[0][0] == 0 || version[1][0] == 0 || version[2][0] == 0)
317 for (i = 0; i < 3; i++) {
318 if (sr_atol(version[i], &n[i]) != SR_OK)
323 if (n[0] != 0 || n[1] > 2)
325 if (n[1] == 2 && n[2] > 3)
327 sr_dbg("Found DS1000 firmware < 0.2.4, using raw data format.");
328 devc->format = FORMAT_RAW;
333 sr_scpi_hw_info_free(hw_info);
335 for (i = 0; i < model->analog_channels; i++) {
336 if (!(channel_name = g_strdup_printf("CH%d", i + 1)))
338 probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, channel_name);
339 sdi->probes = g_slist_append(sdi->probes, probe);
340 devc->analog_groups[i].name = channel_name;
341 devc->analog_groups[i].channels = g_slist_append(NULL, probe);
342 sdi->channel_groups = g_slist_append(sdi->channel_groups,
343 &devc->analog_groups[i]);
346 if (devc->model->has_digital) {
347 for (i = 0; i < 16; i++) {
348 if (!(channel_name = g_strdup_printf("D%d", i)))
350 probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name);
351 g_free(channel_name);
354 sdi->probes = g_slist_append(sdi->probes, probe);
355 devc->digital_group.channels = g_slist_append(
356 devc->digital_group.channels, probe);
358 devc->digital_group.name = "LA";
359 sdi->channel_groups = g_slist_append(sdi->channel_groups,
360 &devc->digital_group);
363 for (i = 0; i < NUM_TIMEBASE; i++) {
364 if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
365 devc->timebases = &timebases[i];
366 if (!memcmp(&devc->model->series->max_timebase, &timebases[i], sizeof(uint64_t[2])))
367 devc->num_timebases = &timebases[i] - devc->timebases + 1;
370 for (i = 0; i < NUM_VDIV; i++)
371 if (!memcmp(&devc->model->series->min_vdiv, &vdivs[i], sizeof(uint64_t[2])))
372 devc->vdivs = &vdivs[i];
374 if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE)))
376 if (!(devc->data = g_try_malloc(ACQ_BUFFER_SIZE * sizeof(float))))
379 devc->data_source = DATA_SOURCE_LIVE;
386 static GSList *scan(GSList *options)
388 return sr_scpi_scan(di->priv, options, probe_device);
391 static GSList *dev_list(void)
393 return ((struct drv_context *)(di->priv))->instances;
396 static int dev_open(struct sr_dev_inst *sdi)
398 struct sr_scpi_dev_inst *scpi = sdi->conn;
400 if (sr_scpi_open(scpi) < 0)
403 if (rigol_ds_get_dev_cfg(sdi) != SR_OK)
406 sdi->status = SR_ST_ACTIVE;
411 static int dev_close(struct sr_dev_inst *sdi)
413 struct sr_scpi_dev_inst *scpi;
414 struct dev_context *devc;
416 if (sdi->status != SR_ST_ACTIVE)
417 return SR_ERR_DEV_CLOSED;
422 if (devc->model->series->protocol == PROTOCOL_V2)
423 rigol_ds_config_set(sdi, ":KEY:LOCK DISABLE");
426 if (sr_scpi_close(scpi) < 0)
428 sdi->status = SR_ST_INACTIVE;
434 static int cleanup(void)
439 static int analog_frame_size(const struct sr_dev_inst *sdi)
441 struct dev_context *devc = sdi->priv;
442 struct sr_probe *probe;
443 int analog_probes = 0;
446 for (l = sdi->probes; l; l = l->next) {
448 if (probe->type == SR_PROBE_ANALOG && probe->enabled)
452 if (analog_probes == 0)
455 switch (devc->data_source) {
456 case DATA_SOURCE_LIVE:
457 return devc->model->series->live_samples;
458 case DATA_SOURCE_MEMORY:
459 return devc->model->series->buffer_samples / analog_probes;
465 static int digital_frame_size(const struct sr_dev_inst *sdi)
467 struct dev_context *devc = sdi->priv;
469 switch (devc->data_source) {
470 case DATA_SOURCE_LIVE:
471 return devc->model->series->live_samples * 2;
472 case DATA_SOURCE_MEMORY:
473 return devc->model->series->buffer_samples * 2;
479 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
480 const struct sr_channel_group *channel_group)
482 struct dev_context *devc;
483 struct sr_probe *probe;
486 int analog_channel = -1;
487 float smallest_diff = 0.0000000001;
491 if (!sdi || !(devc = sdi->priv))
494 /* If a channel group is specified, it must be a valid one. */
495 if (channel_group && !g_slist_find(sdi->channel_groups, channel_group)) {
496 sr_err("Invalid channel group specified.");
501 probe = g_slist_nth_data(channel_group->channels, 0);
504 if (probe->type == SR_PROBE_ANALOG) {
505 if (probe->name[2] < '1' || probe->name[2] > '4')
507 analog_channel = probe->name[2] - '1';
512 case SR_CONF_NUM_TIMEBASE:
513 *data = g_variant_new_int32(devc->model->series->num_horizontal_divs);
515 case SR_CONF_NUM_VDIV:
516 *data = g_variant_new_int32(NUM_VDIV);
517 case SR_CONF_DATA_SOURCE:
518 if (devc->data_source == DATA_SOURCE_LIVE)
519 *data = g_variant_new_string("Live");
520 else if (devc->data_source == DATA_SOURCE_MEMORY)
521 *data = g_variant_new_string("Memory");
523 *data = g_variant_new_string("Segmented");
525 case SR_CONF_SAMPLERATE:
526 if (devc->data_source == DATA_SOURCE_LIVE) {
527 samplerate = analog_frame_size(sdi) /
528 (devc->timebase * devc->model->series->num_horizontal_divs);
529 *data = g_variant_new_uint64(samplerate);
534 case SR_CONF_TRIGGER_SOURCE:
535 if (!strcmp(devc->trigger_source, "ACL"))
537 else if (!strcmp(devc->trigger_source, "CHAN1"))
539 else if (!strcmp(devc->trigger_source, "CHAN2"))
541 else if (!strcmp(devc->trigger_source, "CHAN3"))
543 else if (!strcmp(devc->trigger_source, "CHAN4"))
546 tmp_str = devc->trigger_source;
547 *data = g_variant_new_string(tmp_str);
549 case SR_CONF_TIMEBASE:
550 for (i = 0; i < devc->num_timebases; i++) {
551 float tb = (float)devc->timebases[i][0] / devc->timebases[i][1];
552 float diff = fabs(devc->timebase - tb);
553 if (diff < smallest_diff) {
554 smallest_diff = diff;
560 *data = g_variant_new("(tt)", devc->timebases[idx][0],
561 devc->timebases[idx][1]);
564 if (analog_channel < 0)
566 for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
567 float vdiv = (float)vdivs[i][0] / vdivs[i][1];
568 float diff = fabs(devc->vdiv[analog_channel] - vdiv);
569 if (diff < smallest_diff) {
570 smallest_diff = diff;
576 *data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]);
578 case SR_CONF_COUPLING:
579 if (analog_channel < 0)
581 *data = g_variant_new_string(devc->coupling[analog_channel]);
590 static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
591 const struct sr_channel_group *channel_group)
593 struct dev_context *devc;
601 if (!(devc = sdi->priv))
604 if (sdi->status != SR_ST_ACTIVE)
605 return SR_ERR_DEV_CLOSED;
607 /* If a channel group is specified, it must be a valid one. */
608 if (channel_group && !g_slist_find(sdi->channel_groups, channel_group)) {
609 sr_err("Invalid channel group specified.");
615 case SR_CONF_LIMIT_FRAMES:
616 devc->limit_frames = g_variant_get_uint64(data);
618 case SR_CONF_TRIGGER_SLOPE:
619 tmp_str = g_variant_get_string(data, NULL);
621 if (!tmp_str || !(tmp_str[0] == 'f' || tmp_str[0] == 'r'))
624 g_free(devc->trigger_slope);
625 devc->trigger_slope = g_strdup((tmp_str[0] == 'r') ? "POS" : "NEG");
626 ret = rigol_ds_config_set(sdi, ":TRIG:EDGE:SLOP %s", devc->trigger_slope);
628 case SR_CONF_HORIZ_TRIGGERPOS:
629 t_dbl = g_variant_get_double(data);
630 if (t_dbl < 0.0 || t_dbl > 1.0)
632 devc->horiz_triggerpos = t_dbl;
633 /* We have the trigger offset as a percentage of the frame, but
634 * need to express this in seconds. */
635 t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * devc->num_timebases;
636 g_ascii_formatd(buffer, sizeof(buffer), "%.6f", t_dbl);
637 ret = rigol_ds_config_set(sdi, ":TIM:OFFS %s", buffer);
639 case SR_CONF_TIMEBASE:
640 g_variant_get(data, "(tt)", &p, &q);
641 for (i = 0; i < devc->num_timebases; i++) {
642 if (devc->timebases[i][0] == p && devc->timebases[i][1] == q) {
643 devc->timebase = (float)p / q;
644 g_ascii_formatd(buffer, sizeof(buffer), "%.9f",
646 ret = rigol_ds_config_set(sdi, ":TIM:SCAL %s", buffer);
650 if (i == devc->num_timebases)
653 case SR_CONF_TRIGGER_SOURCE:
654 tmp_str = g_variant_get_string(data, NULL);
655 for (i = 0; i < ARRAY_SIZE(trigger_sources); i++) {
656 if (!strcmp(trigger_sources[i], tmp_str)) {
657 g_free(devc->trigger_source);
658 devc->trigger_source = g_strdup(trigger_sources[i]);
659 if (!strcmp(devc->trigger_source, "AC Line"))
661 else if (!strcmp(devc->trigger_source, "CH1"))
663 else if (!strcmp(devc->trigger_source, "CH2"))
665 else if (!strcmp(devc->trigger_source, "CH3"))
667 else if (!strcmp(devc->trigger_source, "CH4"))
670 tmp_str = (char *)devc->trigger_source;
671 ret = rigol_ds_config_set(sdi, ":TRIG:EDGE:SOUR %s", tmp_str);
675 if (i == ARRAY_SIZE(trigger_sources))
679 if (!channel_group) {
680 sr_err("No channel group specified.");
681 return SR_ERR_CHANNEL_GROUP;
683 g_variant_get(data, "(tt)", &p, &q);
684 for (i = 0; i < 2; i++) {
685 if (channel_group == &devc->analog_groups[i]) {
686 for (j = 0; j < ARRAY_SIZE(vdivs); j++) {
687 if (vdivs[j][0] != p || vdivs[j][1] != q)
689 devc->vdiv[i] = (float)p / q;
690 g_ascii_formatd(buffer, sizeof(buffer), "%.3f",
692 return rigol_ds_config_set(sdi, ":CHAN%d:SCAL %s", i + 1,
699 case SR_CONF_COUPLING:
700 if (!channel_group) {
701 sr_err("No channel group specified.");
702 return SR_ERR_CHANNEL_GROUP;
704 tmp_str = g_variant_get_string(data, NULL);
705 for (i = 0; i < 2; i++) {
706 if (channel_group == &devc->analog_groups[i]) {
707 for (j = 0; j < ARRAY_SIZE(coupling); j++) {
708 if (!strcmp(tmp_str, coupling[j])) {
709 g_free(devc->coupling[i]);
710 devc->coupling[i] = g_strdup(coupling[j]);
711 return rigol_ds_config_set(sdi, ":CHAN%d:COUP %s", i + 1,
719 case SR_CONF_DATA_SOURCE:
720 tmp_str = g_variant_get_string(data, NULL);
721 if (!strcmp(tmp_str, "Live"))
722 devc->data_source = DATA_SOURCE_LIVE;
723 else if (devc->model->series->protocol >= PROTOCOL_V2
724 && !strcmp(tmp_str, "Memory"))
725 devc->data_source = DATA_SOURCE_MEMORY;
726 else if (devc->model->series->protocol >= PROTOCOL_V3
727 && !strcmp(tmp_str, "Segmented"))
728 devc->data_source = DATA_SOURCE_SEGMENTED;
740 static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
741 const struct sr_channel_group *channel_group)
743 GVariant *tuple, *rational[2];
746 struct dev_context *devc = NULL;
751 if (key == SR_CONF_SCAN_OPTIONS) {
752 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
753 hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
755 } else if (key == SR_CONF_DEVICE_OPTIONS && channel_group == NULL) {
756 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
757 hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
761 /* Every other option requires a valid device instance. */
762 if (!sdi || !(devc = sdi->priv))
765 /* If a channel group is specified, it must be a valid one. */
767 if (channel_group != &devc->analog_groups[0]
768 && channel_group != &devc->analog_groups[1]) {
769 sr_err("Invalid channel group specified.");
775 case SR_CONF_DEVICE_OPTIONS:
776 if (!channel_group) {
777 sr_err("No channel group specified.");
778 return SR_ERR_CHANNEL_GROUP;
780 if (channel_group == &devc->digital_group) {
781 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
782 NULL, 0, sizeof(int32_t));
785 for (i = 0; i < 2; i++) {
786 if (channel_group == &devc->analog_groups[i]) {
787 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
788 analog_hwcaps, ARRAY_SIZE(analog_hwcaps), sizeof(int32_t));
795 case SR_CONF_COUPLING:
796 if (!channel_group) {
797 sr_err("No channel group specified.");
798 return SR_ERR_CHANNEL_GROUP;
800 *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
804 /* Can't know this until we have the exact model. */
806 if (!channel_group) {
807 sr_err("No channel group specified.");
808 return SR_ERR_CHANNEL_GROUP;
810 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
811 for (i = 0; i < NUM_VDIV; i++) {
812 rational[0] = g_variant_new_uint64(devc->vdivs[i][0]);
813 rational[1] = g_variant_new_uint64(devc->vdivs[i][1]);
814 tuple = g_variant_new_tuple(rational, 2);
815 g_variant_builder_add_value(&gvb, tuple);
817 *data = g_variant_builder_end(&gvb);
819 case SR_CONF_TIMEBASE:
821 /* Can't know this until we have the exact model. */
823 if (devc->num_timebases <= 0)
825 g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
826 for (i = 0; i < devc->num_timebases; i++) {
827 rational[0] = g_variant_new_uint64(devc->timebases[i][0]);
828 rational[1] = g_variant_new_uint64(devc->timebases[i][1]);
829 tuple = g_variant_new_tuple(rational, 2);
830 g_variant_builder_add_value(&gvb, tuple);
832 *data = g_variant_builder_end(&gvb);
834 case SR_CONF_TRIGGER_SOURCE:
836 /* Can't know this until we have the exact model. */
838 *data = g_variant_new_strv(trigger_sources,
839 devc->model->has_digital ? ARRAY_SIZE(trigger_sources) : 4);
841 case SR_CONF_DATA_SOURCE:
843 /* Can't know this until we have the exact model. */
845 switch (devc->model->series->protocol) {
847 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 2);
850 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 1);
853 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
864 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
866 struct sr_scpi_dev_inst *scpi;
867 struct dev_context *devc;
868 struct sr_probe *probe;
869 struct sr_datafeed_packet packet;
872 if (sdi->status != SR_ST_ACTIVE)
873 return SR_ERR_DEV_CLOSED;
878 devc->num_frames = 0;
880 for (l = sdi->probes; l; l = l->next) {
882 sr_dbg("handling probe %s", probe->name);
883 if (probe->type == SR_PROBE_ANALOG) {
885 devc->enabled_analog_probes = g_slist_append(
886 devc->enabled_analog_probes, probe);
887 if (probe->enabled != devc->analog_channels[probe->index]) {
888 /* Enabled channel is currently disabled, or vice versa. */
889 if (rigol_ds_config_set(sdi, ":CHAN%d:DISP %s", probe->index + 1,
890 probe->enabled ? "ON" : "OFF") != SR_OK)
892 devc->analog_channels[probe->index] = probe->enabled;
894 } else if (probe->type == SR_PROBE_LOGIC) {
895 if (probe->enabled) {
896 devc->enabled_digital_probes = g_slist_append(
897 devc->enabled_digital_probes, probe);
898 /* Turn on LA module if currently off. */
899 if (!devc->la_enabled) {
900 if (rigol_ds_config_set(sdi, ":LA:DISP ON") != SR_OK)
902 devc->la_enabled = TRUE;
905 if (probe->enabled != devc->digital_channels[probe->index]) {
906 /* Enabled channel is currently disabled, or vice versa. */
907 if (rigol_ds_config_set(sdi, ":DIG%d:TURN %s", probe->index,
908 probe->enabled ? "ON" : "OFF") != SR_OK)
910 devc->digital_channels[probe->index] = probe->enabled;
915 if (!devc->enabled_analog_probes && !devc->enabled_digital_probes)
918 /* Turn off LA module if on and no digital probes selected. */
919 if (devc->la_enabled && !devc->enabled_digital_probes)
920 if (rigol_ds_config_set(sdi, ":LA:DISP OFF") != SR_OK)
923 /* Set memory mode. */
924 if (devc->data_source == DATA_SOURCE_SEGMENTED) {
925 sr_err("Data source 'Segmented' not yet supported");
929 devc->analog_frame_size = analog_frame_size(sdi);
930 devc->digital_frame_size = digital_frame_size(sdi);
932 switch (devc->model->series->protocol) {
934 if (rigol_ds_config_set(sdi, ":ACQ:MDEP LONG") != SR_OK)
938 /* Apparently for the DS2000 the memory
939 * depth can only be set in Running state -
940 * this matches the behaviour of the UI. */
941 if (rigol_ds_config_set(sdi, ":RUN") != SR_OK)
943 if (rigol_ds_config_set(sdi, ":ACQ:MDEP %d",
944 devc->analog_frame_size) != SR_OK)
946 if (rigol_ds_config_set(sdi, ":STOP") != SR_OK)
953 if (devc->data_source == DATA_SOURCE_LIVE)
954 if (rigol_ds_config_set(sdi, ":RUN") != SR_OK)
957 sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi);
959 /* Send header packet to the session bus. */
960 std_session_send_df_header(cb_data, LOG_PREFIX);
962 if (devc->enabled_analog_probes)
963 devc->channel_entry = devc->enabled_analog_probes;
965 devc->channel_entry = devc->enabled_digital_probes;
967 if (rigol_ds_capture_start(sdi) != SR_OK)
970 /* Start of first frame. */
971 packet.type = SR_DF_FRAME_BEGIN;
972 sr_session_send(cb_data, &packet);
977 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
979 struct dev_context *devc;
980 struct sr_scpi_dev_inst *scpi;
981 struct sr_datafeed_packet packet;
987 if (sdi->status != SR_ST_ACTIVE) {
988 sr_err("Device inactive, can't stop acquisition.");
992 /* End of last frame. */
993 packet.type = SR_DF_END;
994 sr_session_send(sdi, &packet);
996 g_slist_free(devc->enabled_analog_probes);
997 g_slist_free(devc->enabled_digital_probes);
998 devc->enabled_analog_probes = NULL;
999 devc->enabled_digital_probes = NULL;
1001 sr_scpi_source_remove(scpi);
1006 SR_PRIV struct sr_dev_driver rigol_ds_driver_info = {
1008 .longname = "Rigol DS",
1013 .dev_list = dev_list,
1014 .dev_clear = dev_clear,
1015 .config_get = config_get,
1016 .config_set = config_set,
1017 .config_list = config_list,
1018 .dev_open = dev_open,
1019 .dev_close = dev_close,
1020 .dev_acquisition_start = dev_acquisition_start,
1021 .dev_acquisition_stop = dev_acquisition_stop,