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/>.
32 #include <libsigrok/libsigrok.h>
33 #include "libsigrok-internal.h"
38 * This is a unified protocol driver for the DS1000 and DS2000 series.
40 * DS1000 support tested with a Rigol DS1102D.
42 * DS2000 support tested with a Rigol DS2072 using firmware version 01.01.00.02.
44 * The Rigol DS2000 series scopes try to adhere to the IEEE 488.2 (I think)
45 * standard. If you want to read it - it costs real money...
47 * Every response from the scope has a linefeed appended because the
48 * standard says so. In principle this could be ignored because sending the
49 * next command clears the output queue of the scope. This driver tries to
50 * avoid doing that because it may cause an error being generated inside the
51 * scope and who knows what bugs the firmware has WRT this.
53 * Waveform data is transferred in a format called "arbitrary block program
54 * data" specified in IEEE 488.2. See Agilents programming manuals for their
55 * 2000/3000 series scopes for a nice description.
57 * Each data block from the scope has a header, e.g. "#900000001400".
58 * The '#' marks the start of a block.
59 * Next is one ASCII decimal digit between 1 and 9, this gives the number of
60 * ASCII decimal digits following.
61 * Last are the ASCII decimal digits giving the number of bytes (not
62 * samples!) in the block.
64 * After this header as many data bytes as indicated follow.
66 * Each data block has a trailing linefeed too.
69 static int parse_int(const char *str, int *ret)
75 tmp = strtol(str, &e, 10);
76 if (e == str || *e != '\0') {
77 sr_dbg("Failed to parse integer: '%s'", str);
81 sr_dbg("Failed to parse integer: '%s', numerical overflow", str);
84 if (tmp > INT_MAX || tmp < INT_MIN) {
85 sr_dbg("Failed to parse integer: '%s', value to large/small", str);
93 /* Set the next event to wait for in rigol_ds_receive */
94 static void rigol_ds_set_wait_event(struct dev_context *devc, enum wait_events event)
96 if (event == WAIT_STOP)
97 devc->wait_status = 2;
99 devc->wait_status = 1;
100 devc->wait_event = event;
104 * Waiting for a event will return a timeout after 2 to 3 seconds in order
105 * to not block the application.
107 static int rigol_ds_event_wait(const struct sr_dev_inst *sdi, char status1, char status2)
110 struct dev_context *devc;
113 if (!(devc = sdi->priv))
119 * Trigger status may return:
120 * "TD" or "T'D" - triggered
121 * "AUTO" - autotriggered
123 * "WAIT" - waiting for trigger
127 if (devc->wait_status == 1) {
129 if (time(NULL) - start >= 3) {
130 sr_dbg("Timeout waiting for trigger");
131 return SR_ERR_TIMEOUT;
134 if (sr_scpi_get_string(sdi->conn, ":TRIG:STAT?", &buf) != SR_OK)
136 } while (buf[0] == status1 || buf[0] == status2);
138 devc->wait_status = 2;
140 if (devc->wait_status == 2) {
142 if (time(NULL) - start >= 3) {
143 sr_dbg("Timeout waiting for trigger");
144 return SR_ERR_TIMEOUT;
147 if (sr_scpi_get_string(sdi->conn, ":TRIG:STAT?", &buf) != SR_OK)
149 } while (buf[0] != status1 && buf[0] != status2);
151 rigol_ds_set_wait_event(devc, WAIT_NONE);
158 * For live capture we need to wait for a new trigger event to ensure that
159 * sample data is not returned twice.
161 * Unfortunately this will never really work because for sufficiently fast
162 * timebases and trigger rates it just can't catch the status changes.
164 * What would be needed is a trigger event register with autoreset like the
165 * Agilents have. The Rigols don't seem to have anything like this.
167 * The workaround is to only wait for the trigger when the timebase is slow
168 * enough. Of course this means that for faster timebases sample data can be
169 * returned multiple times, this effect is mitigated somewhat by sleeping
170 * for about one sweep time in that case.
172 static int rigol_ds_trigger_wait(const struct sr_dev_inst *sdi)
174 struct dev_context *devc;
177 if (!(devc = sdi->priv))
181 * If timebase < 50 msecs/DIV just sleep about one sweep time except
182 * for really fast sweeps.
184 if (devc->timebase < 0.0499) {
185 if (devc->timebase > 0.99e-6) {
187 * Timebase * num hor. divs * 85(%) * 1e6(usecs) / 100
188 * -> 85 percent of sweep time
190 s = (devc->timebase * devc->model->series->num_horizontal_divs
192 sr_spew("Sleeping for %ld usecs instead of trigger-wait", s);
195 rigol_ds_set_wait_event(devc, WAIT_NONE);
198 return rigol_ds_event_wait(sdi, 'T', 'A');
202 /* Wait for scope to got to "Stop" in single shot mode */
203 static int rigol_ds_stop_wait(const struct sr_dev_inst *sdi)
205 return rigol_ds_event_wait(sdi, 'S', 'S');
208 /* Check that a single shot acquisition actually succeeded on the DS2000 */
209 static int rigol_ds_check_stop(const struct sr_dev_inst *sdi)
211 struct dev_context *devc;
212 struct sr_channel *ch;
215 if (!(devc = sdi->priv))
218 ch = devc->channel_entry->data;
220 if (devc->model->series->protocol != PROTOCOL_V3)
223 if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
224 ch->index + 1) != SR_OK)
226 /* Check that the number of samples will be accepted */
227 if (rigol_ds_config_set(sdi, ":WAV:POIN %d", devc->analog_frame_size) != SR_OK)
229 if (sr_scpi_get_int(sdi->conn, "*ESR?", &tmp) != SR_OK)
232 * If we get an "Execution error" the scope went from "Single" to
233 * "Stop" without actually triggering. There is no waveform
234 * displayed and trying to download one will fail - the scope thinks
235 * it has 1400 samples (like display memory) and the driver thinks
236 * it has a different number of samples.
238 * In that case just try to capture something again. Might still
239 * fail in interesting ways.
241 * Ain't firmware fun?
244 sr_warn("Single shot acquisition failed, retrying...");
245 /* Sleep a bit, otherwise the single shot will often fail */
246 g_usleep(500 * 1000);
247 rigol_ds_config_set(sdi, ":SING");
248 rigol_ds_set_wait_event(devc, WAIT_STOP);
255 /* Wait for enough data becoming available in scope output buffer */
256 static int rigol_ds_block_wait(const struct sr_dev_inst *sdi)
259 struct dev_context *devc;
263 if (!(devc = sdi->priv))
266 if (devc->model->series->protocol == PROTOCOL_V3) {
271 if (time(NULL) - start >= 3) {
272 sr_dbg("Timeout waiting for data block");
273 return SR_ERR_TIMEOUT;
277 * The scope copies data really slowly from sample
278 * memory to its output buffer, so try not to bother
279 * it too much with SCPI requests but don't wait too
280 * long for short sample frame sizes.
282 g_usleep(devc->analog_frame_size < (15 * 1000) ? (100 * 1000) : (1000 * 1000));
284 /* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */
285 if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK)
288 if (parse_int(buf + 5, &len) != SR_OK)
290 } while (buf[0] == 'R' && len < (1000 * 1000));
293 rigol_ds_set_wait_event(devc, WAIT_NONE);
298 /* Send a configuration setting. */
299 SR_PRIV int rigol_ds_config_set(const struct sr_dev_inst *sdi, const char *format, ...)
301 struct dev_context *devc = sdi->priv;
305 va_start(args, format);
306 ret = sr_scpi_send_variadic(sdi->conn, format, args);
312 if (devc->model->series->protocol == PROTOCOL_V2) {
313 /* The DS1000 series needs this stupid delay, *OPC? doesn't work. */
314 sr_spew("delay %dms", 100);
315 g_usleep(100 * 1000);
318 return sr_scpi_get_opc(sdi->conn);
322 /* Start capturing a new frameset */
323 SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi)
325 struct dev_context *devc;
327 unsigned int num_channels, i, j;
329 if (!(devc = sdi->priv))
332 sr_dbg("Starting data capture for frameset %" PRIu64 " of %" PRIu64,
333 devc->num_frames + 1, devc->limit_frames);
335 switch (devc->model->series->protocol) {
337 rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
340 if (devc->data_source == DATA_SOURCE_LIVE) {
341 if (rigol_ds_config_set(sdi, ":WAV:POIN:MODE NORMAL") != SR_OK)
343 rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
345 if (rigol_ds_config_set(sdi, ":STOP") != SR_OK)
347 if (rigol_ds_config_set(sdi, ":WAV:POIN:MODE RAW") != SR_OK)
349 if (sr_scpi_get_string(sdi->conn, ":TRIG:MODE?", &trig_mode) != SR_OK)
351 if (rigol_ds_config_set(sdi, ":TRIG:%s:SWE SING", trig_mode) != SR_OK)
353 if (rigol_ds_config_set(sdi, ":RUN") != SR_OK)
355 rigol_ds_set_wait_event(devc, WAIT_STOP);
360 if (rigol_ds_config_set(sdi, ":WAV:FORM BYTE") != SR_OK)
362 if (devc->data_source == DATA_SOURCE_LIVE) {
363 if (rigol_ds_config_set(sdi, ":WAV:MODE NORM") != SR_OK)
365 devc->analog_frame_size = devc->model->series->live_samples;
366 devc->digital_frame_size = devc->model->series->live_samples;
367 rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
369 if (devc->model->series->protocol == PROTOCOL_V3) {
370 if (rigol_ds_config_set(sdi, ":WAV:MODE RAW") != SR_OK)
372 } else if (devc->model->series->protocol == PROTOCOL_V4) {
375 /* Channels 3 and 4 are multiplexed with D0-7 and D8-15 */
376 for (i = 0; i < devc->model->analog_channels; i++) {
377 if (devc->analog_channels[i]) {
379 } else if (i >= 2 && devc->model->has_digital) {
380 for (j = 0; j < 8; j++) {
381 if (devc->digital_channels[8 * (i - 2) + j]) {
389 devc->analog_frame_size = devc->digital_frame_size =
391 devc->model->series->buffer_samples :
393 devc->model->series->buffer_samples / 2 :
394 devc->model->series->buffer_samples / 4;
397 if (rigol_ds_config_set(sdi, ":SING") != SR_OK)
399 rigol_ds_set_wait_event(devc, WAIT_STOP);
407 /* Start reading data from the current channel */
408 SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi)
410 struct dev_context *devc;
411 struct sr_channel *ch;
413 if (!(devc = sdi->priv))
416 ch = devc->channel_entry->data;
418 sr_dbg("Starting reading data from channel %d", ch->index + 1);
420 switch (devc->model->series->protocol) {
423 if (ch->type == SR_CHANNEL_LOGIC) {
424 if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK)
427 if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d",
428 ch->index + 1) != SR_OK)
431 rigol_ds_set_wait_event(devc, WAIT_NONE);
434 if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
435 ch->index + 1) != SR_OK)
437 if (devc->data_source != DATA_SOURCE_LIVE) {
438 if (rigol_ds_config_set(sdi, ":WAV:RES") != SR_OK)
440 if (rigol_ds_config_set(sdi, ":WAV:BEG") != SR_OK)
445 if (ch->type == SR_CHANNEL_ANALOG) {
446 if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
447 ch->index + 1) != SR_OK)
450 if (rigol_ds_config_set(sdi, ":WAV:SOUR D%d",
455 if (rigol_ds_config_set(sdi,
456 devc->data_source == DATA_SOURCE_LIVE ?
457 ":WAV:MODE NORM" :":WAV:MODE RAW") != SR_OK)
462 if (devc->model->series->protocol >= PROTOCOL_V3 &&
463 ch->type == SR_CHANNEL_ANALOG) {
464 /* Vertical reference. */
465 if (sr_scpi_get_int(sdi->conn, ":WAV:YREF?",
466 &devc->vert_reference[ch->index]) != SR_OK)
470 rigol_ds_set_wait_event(devc, WAIT_BLOCK);
472 devc->num_channel_bytes = 0;
473 devc->num_header_bytes = 0;
474 devc->num_block_bytes = 0;
479 /* Read the header of a data block */
480 static int rigol_ds_read_header(struct sr_dev_inst *sdi)
482 struct sr_scpi_dev_inst *scpi = sdi->conn;
483 struct dev_context *devc = sdi->priv;
484 char *buf = (char *) devc->buffer;
485 size_t header_length;
488 /* Try to read the hashsign and length digit. */
489 if (devc->num_header_bytes < 2) {
490 ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
491 2 - devc->num_header_bytes);
493 sr_err("Read error while reading data header.");
496 devc->num_header_bytes += ret;
499 if (devc->num_header_bytes < 2)
502 if (buf[0] != '#' || !isdigit(buf[1]) || buf[1] == '0') {
503 sr_err("Received invalid data block header '%c%c'.", buf[0], buf[1]);
507 header_length = 2 + buf[1] - '0';
509 /* Try to read the length. */
510 if (devc->num_header_bytes < header_length) {
511 ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
512 header_length - devc->num_header_bytes);
514 sr_err("Read error while reading data header.");
517 devc->num_header_bytes += ret;
520 if (devc->num_header_bytes < header_length)
523 /* Read the data length. */
524 buf[header_length] = '\0';
526 if (parse_int(buf + 2, &ret) != SR_OK) {
527 sr_err("Received invalid data block length '%s'.", buf + 2);
531 sr_dbg("Received data block header: '%s' -> block length %d", buf, ret);
536 SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
538 struct sr_dev_inst *sdi;
539 struct sr_scpi_dev_inst *scpi;
540 struct dev_context *devc;
541 struct sr_datafeed_packet packet;
542 struct sr_datafeed_analog analog;
543 struct sr_analog_encoding encoding;
544 struct sr_analog_meaning meaning;
545 struct sr_analog_spec spec;
546 struct sr_datafeed_logic logic;
549 struct sr_channel *ch;
550 gsize expected_data_bytes;
554 if (!(sdi = cb_data))
557 if (!(devc = sdi->priv))
562 if (!(revents == G_IO_IN || revents == 0))
565 switch (devc->wait_event) {
569 if (rigol_ds_trigger_wait(sdi) != SR_OK)
571 if (rigol_ds_channel_start(sdi) != SR_OK)
575 if (rigol_ds_block_wait(sdi) != SR_OK)
579 if (rigol_ds_stop_wait(sdi) != SR_OK)
581 if (rigol_ds_check_stop(sdi) != SR_OK)
583 if (rigol_ds_channel_start(sdi) != SR_OK)
587 sr_err("BUG: Unknown event target encountered");
591 ch = devc->channel_entry->data;
593 expected_data_bytes = ch->type == SR_CHANNEL_ANALOG ?
594 devc->analog_frame_size : devc->digital_frame_size;
596 if (devc->num_block_bytes == 0) {
597 if (devc->model->series->protocol >= PROTOCOL_V4) {
598 if (rigol_ds_config_set(sdi, ":WAV:START %d",
599 devc->num_channel_bytes + 1) != SR_OK)
601 if (rigol_ds_config_set(sdi, ":WAV:STOP %d",
602 MIN(devc->num_channel_bytes + ACQ_BLOCK_SIZE,
603 devc->analog_frame_size)) != SR_OK)
607 if (devc->model->series->protocol >= PROTOCOL_V3)
608 if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
611 if (sr_scpi_read_begin(scpi) != SR_OK)
614 if (devc->format == FORMAT_IEEE488_2) {
615 sr_dbg("New block header expected");
616 len = rigol_ds_read_header(sdi);
618 /* Still reading the header. */
621 sr_err("Read error, aborting capture.");
622 packet.type = SR_DF_FRAME_END;
623 sr_session_send(sdi, &packet);
624 sdi->driver->dev_acquisition_stop(sdi);
627 /* At slow timebases in live capture the DS2072
628 * sometimes returns "short" data blocks, with
629 * apparently no way to get the rest of the data.
630 * Discard these, the complete data block will
633 if (devc->data_source == DATA_SOURCE_LIVE
634 && (unsigned)len < expected_data_bytes) {
635 sr_dbg("Discarding short data block");
636 sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1);
639 devc->num_block_bytes = len;
641 devc->num_block_bytes = expected_data_bytes;
643 devc->num_block_read = 0;
646 len = devc->num_block_bytes - devc->num_block_read;
647 if (len > ACQ_BUFFER_SIZE)
648 len = ACQ_BUFFER_SIZE;
649 sr_dbg("Requesting read of %d bytes", len);
651 len = sr_scpi_read_data(scpi, (char *)devc->buffer, len);
654 sr_err("Read error, aborting capture.");
655 packet.type = SR_DF_FRAME_END;
656 sr_session_send(sdi, &packet);
657 sdi->driver->dev_acquisition_stop(sdi);
661 sr_dbg("Received %d bytes.", len);
663 devc->num_block_read += len;
665 if (ch->type == SR_CHANNEL_ANALOG) {
666 vref = devc->vert_reference[ch->index];
667 vdiv = devc->vdiv[ch->index] / 25.6;
668 offset = devc->vert_offset[ch->index];
669 if (devc->model->series->protocol >= PROTOCOL_V3)
670 for (i = 0; i < len; i++)
671 devc->data[i] = ((int)devc->buffer[i] - vref) * vdiv - offset;
673 for (i = 0; i < len; i++)
674 devc->data[i] = (128 - devc->buffer[i]) * vdiv - offset;
675 float vdivlog = log10f(vdiv);
676 int digits = -(int)vdivlog + (vdivlog < 0.0);
677 sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
678 analog.meaning->channels = g_slist_append(NULL, ch);
679 analog.num_samples = len;
680 analog.data = devc->data;
681 analog.meaning->mq = SR_MQ_VOLTAGE;
682 analog.meaning->unit = SR_UNIT_VOLT;
683 analog.meaning->mqflags = 0;
684 packet.type = SR_DF_ANALOG;
685 packet.payload = &analog;
686 sr_session_send(sdi, &packet);
687 g_slist_free(analog.meaning->channels);
690 // TODO: For the MSO1000Z series, we need a way to express that
691 // this data is in fact just for a single channel, with the valid
692 // data for that channel in the LSB of each byte.
693 logic.unitsize = devc->model->series->protocol == PROTOCOL_V4 ? 1 : 2;
694 logic.data = devc->buffer;
695 packet.type = SR_DF_LOGIC;
696 packet.payload = &logic;
697 sr_session_send(sdi, &packet);
700 if (devc->num_block_read == devc->num_block_bytes) {
701 sr_dbg("Block has been completed");
702 if (devc->model->series->protocol >= PROTOCOL_V3) {
703 /* Discard the terminating linefeed */
704 sr_scpi_read_data(scpi, (char *)devc->buffer, 1);
706 if (devc->format == FORMAT_IEEE488_2) {
707 /* Prepare for possible next block */
708 devc->num_header_bytes = 0;
709 devc->num_block_bytes = 0;
710 if (devc->data_source != DATA_SOURCE_LIVE)
711 rigol_ds_set_wait_event(devc, WAIT_BLOCK);
713 if (!sr_scpi_read_complete(scpi)) {
714 sr_err("Read should have been completed");
715 packet.type = SR_DF_FRAME_END;
716 sr_session_send(sdi, &packet);
717 sdi->driver->dev_acquisition_stop(sdi);
720 devc->num_block_read = 0;
722 sr_dbg("%" PRIu64 " of %" PRIu64 " block bytes read",
723 devc->num_block_read, devc->num_block_bytes);
726 devc->num_channel_bytes += len;
728 if (devc->num_channel_bytes < expected_data_bytes)
729 /* Don't have the full data for this channel yet, re-run. */
732 /* End of data for this channel. */
733 if (devc->model->series->protocol == PROTOCOL_V3) {
734 /* Signal end of data download to scope */
735 if (devc->data_source != DATA_SOURCE_LIVE)
737 * This causes a query error, without it switching
738 * to the next channel causes an error. Fun with
741 rigol_ds_config_set(sdi, ":WAV:END");
744 if (devc->channel_entry->next) {
745 /* We got the frame for this channel, now get the next channel. */
746 devc->channel_entry = devc->channel_entry->next;
747 rigol_ds_channel_start(sdi);
749 /* Done with this frame. */
750 packet.type = SR_DF_FRAME_END;
751 sr_session_send(sdi, &packet);
753 if (++devc->num_frames == devc->limit_frames) {
754 /* Last frame, stop capture. */
755 sdi->driver->dev_acquisition_stop(sdi);
757 /* Get the next frame, starting with the first channel. */
758 devc->channel_entry = devc->enabled_channels;
760 rigol_ds_capture_start(sdi);
762 /* Start of next frame. */
763 packet.type = SR_DF_FRAME_BEGIN;
764 sr_session_send(sdi, &packet);
771 SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi)
773 struct dev_context *devc;
774 struct sr_channel *ch;
781 /* Analog channel state. */
782 for (i = 0; i < devc->model->analog_channels; i++) {
783 cmd = g_strdup_printf(":CHAN%d:DISP?", i + 1);
784 res = sr_scpi_get_bool(sdi->conn, cmd, &devc->analog_channels[i]);
788 ch = g_slist_nth_data(sdi->channels, i);
789 ch->enabled = devc->analog_channels[i];
791 sr_dbg("Current analog channel state:");
792 for (i = 0; i < devc->model->analog_channels; i++)
793 sr_dbg("CH%d %s", i + 1, devc->analog_channels[i] ? "on" : "off");
795 /* Digital channel state. */
796 if (devc->model->has_digital) {
797 if (sr_scpi_get_bool(sdi->conn,
798 devc->model->series->protocol >= PROTOCOL_V4 ?
799 ":LA:STAT?" : ":LA:DISP?",
800 &devc->la_enabled) != SR_OK)
802 sr_dbg("Logic analyzer %s, current digital channel state:",
803 devc->la_enabled ? "enabled" : "disabled");
804 for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) {
805 cmd = g_strdup_printf(
806 devc->model->series->protocol >= PROTOCOL_V4 ?
807 ":LA:DIG%d:DISP?" : ":DIG%d:TURN?", i);
808 res = sr_scpi_get_bool(sdi->conn, cmd, &devc->digital_channels[i]);
812 ch = g_slist_nth_data(sdi->channels, i + devc->model->analog_channels);
813 ch->enabled = devc->digital_channels[i];
814 sr_dbg("D%d: %s", i, devc->digital_channels[i] ? "on" : "off");
819 if (sr_scpi_get_float(sdi->conn, ":TIM:SCAL?", &devc->timebase) != SR_OK)
821 sr_dbg("Current timebase %g", devc->timebase);
823 /* Probe attenuation. */
824 for (i = 0; i < devc->model->analog_channels; i++) {
825 cmd = g_strdup_printf(":CHAN%d:PROB?", i + 1);
826 res = sr_scpi_get_float(sdi->conn, cmd, &devc->attenuation[i]);
831 sr_dbg("Current probe attenuation:");
832 for (i = 0; i < devc->model->analog_channels; i++)
833 sr_dbg("CH%d %g", i + 1, devc->attenuation[i]);
835 /* Vertical gain and offset. */
836 if (rigol_ds_get_dev_cfg_vertical(sdi) != SR_OK)
840 for (i = 0; i < devc->model->analog_channels; i++) {
841 cmd = g_strdup_printf(":CHAN%d:COUP?", i + 1);
842 res = sr_scpi_get_string(sdi->conn, cmd, &devc->coupling[i]);
847 sr_dbg("Current coupling:");
848 for (i = 0; i < devc->model->analog_channels; i++)
849 sr_dbg("CH%d %s", i + 1, devc->coupling[i]);
851 /* Trigger source. */
852 if (sr_scpi_get_string(sdi->conn, ":TRIG:EDGE:SOUR?", &devc->trigger_source) != SR_OK)
854 sr_dbg("Current trigger source %s", devc->trigger_source);
856 /* Horizontal trigger position. */
857 if (sr_scpi_get_float(sdi->conn, ":TIM:OFFS?", &devc->horiz_triggerpos) != SR_OK)
859 sr_dbg("Current horizontal trigger position %g", devc->horiz_triggerpos);
862 if (sr_scpi_get_string(sdi->conn, ":TRIG:EDGE:SLOP?", &devc->trigger_slope) != SR_OK)
864 sr_dbg("Current trigger slope %s", devc->trigger_slope);
867 if (sr_scpi_get_float(sdi->conn, ":TRIG:EDGE:LEV?", &devc->trigger_level) != SR_OK)
869 sr_dbg("Current trigger level %g", devc->trigger_level);
874 SR_PRIV int rigol_ds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi)
876 struct dev_context *devc;
884 for (i = 0; i < devc->model->analog_channels; i++) {
885 cmd = g_strdup_printf(":CHAN%d:SCAL?", i + 1);
886 res = sr_scpi_get_float(sdi->conn, cmd, &devc->vdiv[i]);
891 sr_dbg("Current vertical gain:");
892 for (i = 0; i < devc->model->analog_channels; i++)
893 sr_dbg("CH%d %g", i + 1, devc->vdiv[i]);
895 /* Vertical offset. */
896 for (i = 0; i < devc->model->analog_channels; i++) {
897 cmd = g_strdup_printf(":CHAN%d:OFFS?", i + 1);
898 res = sr_scpi_get_float(sdi->conn, cmd, &devc->vert_offset[i]);
903 sr_dbg("Current vertical offset:");
904 for (i = 0; i < devc->model->analog_channels; i++)
905 sr_dbg("CH%d %g", i + 1, devc->vert_offset[i]);