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/>.
31 #include <libsigrok/libsigrok.h>
32 #include "libsigrok-internal.h"
37 * This is a unified protocol driver for the DS1000 and DS2000 series.
39 * DS1000 support tested with a Rigol DS1102D.
41 * DS2000 support tested with a Rigol DS2072 using firmware version 01.01.00.02.
43 * The Rigol DS2000 series scopes try to adhere to the IEEE 488.2 (I think)
44 * standard. If you want to read it - it costs real money...
46 * Every response from the scope has a linefeed appended because the
47 * standard says so. In principle this could be ignored because sending the
48 * next command clears the output queue of the scope. This driver tries to
49 * avoid doing that because it may cause an error being generated inside the
50 * scope and who knows what bugs the firmware has WRT this.
52 * Waveform data is transferred in a format called "arbitrary block program
53 * data" specified in IEEE 488.2. See Agilents programming manuals for their
54 * 2000/3000 series scopes for a nice description.
56 * Each data block from the scope has a header, e.g. "#900000001400".
57 * The '#' marks the start of a block.
58 * Next is one ASCII decimal digit between 1 and 9, this gives the number of
59 * ASCII decimal digits following.
60 * Last are the ASCII decimal digits giving the number of bytes (not
61 * samples!) in the block.
63 * After this header as many data bytes as indicated follow.
65 * Each data block has a trailing linefeed too.
68 static int parse_int(const char *str, int *ret)
74 tmp = strtol(str, &e, 10);
75 if (e == str || *e != '\0') {
76 sr_dbg("Failed to parse integer: '%s'", str);
80 sr_dbg("Failed to parse integer: '%s', numerical overflow", str);
83 if (tmp > INT_MAX || tmp < INT_MIN) {
84 sr_dbg("Failed to parse integer: '%s', value to large/small", str);
92 /* Set the next event to wait for in rigol_ds_receive */
93 static void rigol_ds_set_wait_event(struct dev_context *devc, enum wait_events event)
95 if (event == WAIT_STOP)
96 devc->wait_status = 2;
98 devc->wait_status = 1;
99 devc->wait_event = event;
103 * Waiting for a event will return a timeout after 2 to 3 seconds in order
104 * to not block the application.
106 static int rigol_ds_event_wait(const struct sr_dev_inst *sdi, char status1, char status2)
109 struct dev_context *devc;
112 if (!(devc = sdi->priv))
118 * Trigger status may return:
119 * "TD" or "T'D" - triggered
120 * "AUTO" - autotriggered
122 * "WAIT" - waiting for trigger
126 if (devc->wait_status == 1) {
128 if (time(NULL) - start >= 3) {
129 sr_dbg("Timeout waiting for trigger");
130 return SR_ERR_TIMEOUT;
133 if (sr_scpi_get_string(sdi->conn, ":TRIG:STAT?", &buf) != SR_OK)
135 } while (buf[0] == status1 || buf[0] == status2);
137 devc->wait_status = 2;
139 if (devc->wait_status == 2) {
141 if (time(NULL) - start >= 3) {
142 sr_dbg("Timeout waiting for trigger");
143 return SR_ERR_TIMEOUT;
146 if (sr_scpi_get_string(sdi->conn, ":TRIG:STAT?", &buf) != SR_OK)
148 } while (buf[0] != status1 && buf[0] != status2);
150 rigol_ds_set_wait_event(devc, WAIT_NONE);
157 * For live capture we need to wait for a new trigger event to ensure that
158 * sample data is not returned twice.
160 * Unfortunately this will never really work because for sufficiently fast
161 * timebases and trigger rates it just can't catch the status changes.
163 * What would be needed is a trigger event register with autoreset like the
164 * Agilents have. The Rigols don't seem to have anything like this.
166 * The workaround is to only wait for the trigger when the timebase is slow
167 * enough. Of course this means that for faster timebases sample data can be
168 * returned multiple times, this effect is mitigated somewhat by sleeping
169 * for about one sweep time in that case.
171 static int rigol_ds_trigger_wait(const struct sr_dev_inst *sdi)
173 struct dev_context *devc;
176 if (!(devc = sdi->priv))
180 * If timebase < 50 msecs/DIV just sleep about one sweep time except
181 * for really fast sweeps.
183 if (devc->timebase < 0.0499) {
184 if (devc->timebase > 0.99e-6) {
186 * Timebase * num hor. divs * 85(%) * 1e6(usecs) / 100
187 * -> 85 percent of sweep time
189 s = (devc->timebase * devc->model->series->num_horizontal_divs
191 sr_spew("Sleeping for %ld usecs instead of trigger-wait", s);
194 rigol_ds_set_wait_event(devc, WAIT_NONE);
197 return rigol_ds_event_wait(sdi, 'T', 'A');
201 /* Wait for scope to got to "Stop" in single shot mode */
202 static int rigol_ds_stop_wait(const struct sr_dev_inst *sdi)
204 return rigol_ds_event_wait(sdi, 'S', 'S');
207 /* Check that a single shot acquisition actually succeeded on the DS2000 */
208 static int rigol_ds_check_stop(const struct sr_dev_inst *sdi)
210 struct dev_context *devc;
211 struct sr_channel *ch;
214 if (!(devc = sdi->priv))
217 ch = devc->channel_entry->data;
219 if (devc->model->series->protocol != PROTOCOL_V3)
222 if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
223 ch->index + 1) != SR_OK)
225 /* Check that the number of samples will be accepted */
226 if (rigol_ds_config_set(sdi, ":WAV:POIN %d", devc->analog_frame_size) != SR_OK)
228 if (sr_scpi_get_int(sdi->conn, "*ESR?", &tmp) != SR_OK)
231 * If we get an "Execution error" the scope went from "Single" to
232 * "Stop" without actually triggering. There is no waveform
233 * displayed and trying to download one will fail - the scope thinks
234 * it has 1400 samples (like display memory) and the driver thinks
235 * it has a different number of samples.
237 * In that case just try to capture something again. Might still
238 * fail in interesting ways.
240 * Ain't firmware fun?
243 sr_warn("Single shot acquisition failed, retrying...");
244 /* Sleep a bit, otherwise the single shot will often fail */
245 g_usleep(500 * 1000);
246 rigol_ds_config_set(sdi, ":SING");
247 rigol_ds_set_wait_event(devc, WAIT_STOP);
254 /* Wait for enough data becoming available in scope output buffer */
255 static int rigol_ds_block_wait(const struct sr_dev_inst *sdi)
258 struct dev_context *devc;
262 if (!(devc = sdi->priv))
265 if (devc->model->series->protocol == PROTOCOL_V3) {
270 if (time(NULL) - start >= 3) {
271 sr_dbg("Timeout waiting for data block");
272 return SR_ERR_TIMEOUT;
276 * The scope copies data really slowly from sample
277 * memory to its output buffer, so try not to bother
278 * it too much with SCPI requests but don't wait too
279 * long for short sample frame sizes.
281 g_usleep(devc->analog_frame_size < (15 * 1000) ? (100 * 1000) : (1000 * 1000));
283 /* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */
284 if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK)
287 if (parse_int(buf + 5, &len) != SR_OK)
289 } while (buf[0] == 'R' && len < (1000 * 1000));
292 rigol_ds_set_wait_event(devc, WAIT_NONE);
297 /* Send a configuration setting. */
298 SR_PRIV int rigol_ds_config_set(const struct sr_dev_inst *sdi, const char *format, ...)
300 struct dev_context *devc = sdi->priv;
304 va_start(args, format);
305 ret = sr_scpi_send_variadic(sdi->conn, format, args);
311 if (devc->model->series->protocol == PROTOCOL_V2) {
312 /* The DS1000 series needs this stupid delay, *OPC? doesn't work. */
313 sr_spew("delay %dms", 100);
314 g_usleep(100 * 1000);
317 return sr_scpi_get_opc(sdi->conn);
321 /* Start capturing a new frameset */
322 SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi)
324 struct dev_context *devc;
326 unsigned int num_channels, i, j;
328 if (!(devc = sdi->priv))
331 sr_dbg("Starting data capture for frameset %lu of %lu",
332 devc->num_frames + 1, devc->limit_frames);
334 switch (devc->model->series->protocol) {
336 rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
339 if (devc->data_source == DATA_SOURCE_LIVE) {
340 if (rigol_ds_config_set(sdi, ":WAV:POIN:MODE NORMAL") != SR_OK)
342 rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
344 if (rigol_ds_config_set(sdi, ":STOP") != SR_OK)
346 if (rigol_ds_config_set(sdi, ":WAV:POIN:MODE RAW") != SR_OK)
348 if (sr_scpi_get_string(sdi->conn, ":TRIG:MODE?", &trig_mode) != SR_OK)
350 if (rigol_ds_config_set(sdi, ":TRIG:%s:SWE SING", trig_mode) != SR_OK)
352 if (rigol_ds_config_set(sdi, ":RUN") != SR_OK)
354 rigol_ds_set_wait_event(devc, WAIT_STOP);
359 if (rigol_ds_config_set(sdi, ":WAV:FORM BYTE") != SR_OK)
361 if (devc->data_source == DATA_SOURCE_LIVE) {
362 if (rigol_ds_config_set(sdi, ":WAV:MODE NORM") != SR_OK)
364 devc->analog_frame_size = devc->model->series->live_samples;
365 devc->digital_frame_size = devc->model->series->live_samples;
366 rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
368 if (devc->model->series->protocol == PROTOCOL_V3) {
369 if (rigol_ds_config_set(sdi, ":WAV:MODE RAW") != SR_OK)
371 } else if (devc->model->series->protocol == PROTOCOL_V4) {
374 /* Channels 3 and 4 are multiplexed with D0-7 and D8-15 */
375 for (i = 0; i < devc->model->analog_channels; i++) {
376 if (devc->analog_channels[i]) {
378 } else if (i >= 2 && devc->model->has_digital) {
379 for (j = 0; j < 8; j++) {
380 if (devc->digital_channels[8 * (i - 2) + j]) {
388 devc->analog_frame_size = devc->digital_frame_size =
390 devc->model->series->buffer_samples :
392 devc->model->series->buffer_samples / 2 :
393 devc->model->series->buffer_samples / 4;
396 if (rigol_ds_config_set(sdi, ":SING") != SR_OK)
398 rigol_ds_set_wait_event(devc, WAIT_STOP);
406 /* Start reading data from the current channel */
407 SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi)
409 struct dev_context *devc;
410 struct sr_channel *ch;
412 if (!(devc = sdi->priv))
415 ch = devc->channel_entry->data;
417 sr_dbg("Starting reading data from channel %d", ch->index + 1);
419 switch (devc->model->series->protocol) {
422 if (ch->type == SR_CHANNEL_LOGIC) {
423 if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK)
426 if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d",
427 ch->index + 1) != SR_OK)
430 rigol_ds_set_wait_event(devc, WAIT_NONE);
433 if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
434 ch->index + 1) != SR_OK)
436 if (devc->data_source != DATA_SOURCE_LIVE) {
437 if (rigol_ds_config_set(sdi, ":WAV:RES") != SR_OK)
439 if (rigol_ds_config_set(sdi, ":WAV:BEG") != SR_OK)
444 if (ch->type == SR_CHANNEL_ANALOG) {
445 if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
446 ch->index + 1) != SR_OK)
449 if (rigol_ds_config_set(sdi, ":WAV:SOUR D%d",
454 if (rigol_ds_config_set(sdi,
455 devc->data_source == DATA_SOURCE_LIVE ?
456 ":WAV:MODE NORM" :":WAV:MODE RAW") != SR_OK)
461 if (devc->model->series->protocol >= PROTOCOL_V3 &&
462 ch->type == SR_CHANNEL_ANALOG) {
463 /* Vertical reference. */
464 if (sr_scpi_get_int(sdi->conn, ":WAV:YREF?",
465 &devc->vert_reference[ch->index]) != SR_OK)
469 rigol_ds_set_wait_event(devc, WAIT_BLOCK);
471 devc->num_channel_bytes = 0;
472 devc->num_header_bytes = 0;
473 devc->num_block_bytes = 0;
478 /* Read the header of a data block */
479 static int rigol_ds_read_header(struct sr_dev_inst *sdi)
481 struct sr_scpi_dev_inst *scpi = sdi->conn;
482 struct dev_context *devc = sdi->priv;
483 char *buf = (char *) devc->buffer;
484 size_t header_length;
487 /* Try to read the hashsign and length digit. */
488 if (devc->num_header_bytes < 2) {
489 ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
490 2 - devc->num_header_bytes);
492 sr_err("Read error while reading data header.");
495 devc->num_header_bytes += ret;
498 if (devc->num_header_bytes < 2)
501 if (buf[0] != '#' || !isdigit(buf[1]) || buf[1] == '0') {
502 sr_err("Received invalid data block header '%c%c'.", buf[0], buf[1]);
506 header_length = 2 + buf[1] - '0';
508 /* Try to read the length. */
509 if (devc->num_header_bytes < header_length) {
510 ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
511 header_length - devc->num_header_bytes);
513 sr_err("Read error while reading data header.");
516 devc->num_header_bytes += ret;
519 if (devc->num_header_bytes < header_length)
522 /* Read the data length. */
523 buf[header_length] = '\0';
525 if (parse_int(buf + 2, &ret) != SR_OK) {
526 sr_err("Received invalid data block length '%s'.", buf + 2);
530 sr_dbg("Received data block header: '%s' -> block length %d", buf, ret);
535 SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
537 struct sr_dev_inst *sdi;
538 struct sr_scpi_dev_inst *scpi;
539 struct dev_context *devc;
540 struct sr_datafeed_packet packet;
541 struct sr_datafeed_analog analog;
542 struct sr_datafeed_logic logic;
545 struct sr_channel *ch;
546 gsize expected_data_bytes;
550 if (!(sdi = cb_data))
553 if (!(devc = sdi->priv))
558 if (!(revents == G_IO_IN || revents == 0))
561 switch (devc->wait_event) {
565 if (rigol_ds_trigger_wait(sdi) != SR_OK)
567 if (rigol_ds_channel_start(sdi) != SR_OK)
571 if (rigol_ds_block_wait(sdi) != SR_OK)
575 if (rigol_ds_stop_wait(sdi) != SR_OK)
577 if (rigol_ds_check_stop(sdi) != SR_OK)
579 if (rigol_ds_channel_start(sdi) != SR_OK)
583 sr_err("BUG: Unknown event target encountered");
587 ch = devc->channel_entry->data;
589 expected_data_bytes = ch->type == SR_CHANNEL_ANALOG ?
590 devc->analog_frame_size : devc->digital_frame_size;
592 if (devc->num_block_bytes == 0) {
593 if (devc->model->series->protocol >= PROTOCOL_V4) {
594 if (sr_scpi_send(sdi->conn, ":WAV:START %d",
595 devc->num_channel_bytes + 1) != SR_OK)
597 if (sr_scpi_send(sdi->conn, ":WAV:STOP %d",
598 MIN(devc->num_channel_bytes + ACQ_BLOCK_SIZE,
599 devc->analog_frame_size)) != SR_OK)
603 if (devc->model->series->protocol >= PROTOCOL_V3)
604 if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
607 if (sr_scpi_read_begin(scpi) != SR_OK)
610 if (devc->format == FORMAT_IEEE488_2) {
611 sr_dbg("New block header expected");
612 len = rigol_ds_read_header(sdi);
614 /* Still reading the header. */
617 sr_err("Read error, aborting capture.");
618 packet.type = SR_DF_FRAME_END;
619 sr_session_send(cb_data, &packet);
620 sdi->driver->dev_acquisition_stop(sdi, cb_data);
623 /* At slow timebases in live capture the DS2072
624 * sometimes returns "short" data blocks, with
625 * apparently no way to get the rest of the data.
626 * Discard these, the complete data block will
629 if (devc->data_source == DATA_SOURCE_LIVE
630 && (unsigned)len < expected_data_bytes) {
631 sr_dbg("Discarding short data block");
632 sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1);
635 devc->num_block_bytes = len;
637 devc->num_block_bytes = expected_data_bytes;
639 devc->num_block_read = 0;
642 len = devc->num_block_bytes - devc->num_block_read;
643 if (len > ACQ_BUFFER_SIZE)
644 len = ACQ_BUFFER_SIZE;
645 sr_dbg("Requesting read of %d bytes", len);
647 len = sr_scpi_read_data(scpi, (char *)devc->buffer, len);
650 sr_err("Read error, aborting capture.");
651 packet.type = SR_DF_FRAME_END;
652 sr_session_send(cb_data, &packet);
653 sdi->driver->dev_acquisition_stop(sdi, cb_data);
657 sr_dbg("Received %d bytes.", len);
659 devc->num_block_read += len;
661 if (ch->type == SR_CHANNEL_ANALOG) {
662 vref = devc->vert_reference[ch->index];
663 vdiv = devc->vdiv[ch->index] / 25.6;
664 offset = devc->vert_offset[ch->index];
665 if (devc->model->series->protocol >= PROTOCOL_V3)
666 for (i = 0; i < len; i++)
667 devc->data[i] = ((int)devc->buffer[i] - vref) * vdiv - offset;
669 for (i = 0; i < len; i++)
670 devc->data[i] = (128 - devc->buffer[i]) * vdiv - offset;
671 analog.channels = g_slist_append(NULL, ch);
672 analog.num_samples = len;
673 analog.data = devc->data;
674 analog.mq = SR_MQ_VOLTAGE;
675 analog.unit = SR_UNIT_VOLT;
677 packet.type = SR_DF_ANALOG;
678 packet.payload = &analog;
679 sr_session_send(cb_data, &packet);
680 g_slist_free(analog.channels);
683 // TODO: For the MSO1000Z series, we need a way to express that
684 // this data is in fact just for a single channel, with the valid
685 // data for that channel in the LSB of each byte.
686 logic.unitsize = devc->model->series->protocol == PROTOCOL_V4 ? 1 : 2;
687 logic.data = devc->buffer;
688 packet.type = SR_DF_LOGIC;
689 packet.payload = &logic;
690 sr_session_send(cb_data, &packet);
693 if (devc->num_block_read == devc->num_block_bytes) {
694 sr_dbg("Block has been completed");
695 if (devc->model->series->protocol >= PROTOCOL_V3) {
696 /* Discard the terminating linefeed */
697 sr_scpi_read_data(scpi, (char *)devc->buffer, 1);
699 if (devc->format == FORMAT_IEEE488_2) {
700 /* Prepare for possible next block */
701 devc->num_header_bytes = 0;
702 devc->num_block_bytes = 0;
703 if (devc->data_source != DATA_SOURCE_LIVE)
704 rigol_ds_set_wait_event(devc, WAIT_BLOCK);
706 if (!sr_scpi_read_complete(scpi)) {
707 sr_err("Read should have been completed");
708 packet.type = SR_DF_FRAME_END;
709 sr_session_send(cb_data, &packet);
710 sdi->driver->dev_acquisition_stop(sdi, cb_data);
713 devc->num_block_read = 0;
715 sr_dbg("%d of %d block bytes read", devc->num_block_read, devc->num_block_bytes);
718 devc->num_channel_bytes += len;
720 if (devc->num_channel_bytes < expected_data_bytes)
721 /* Don't have the full data for this channel yet, re-run. */
724 /* End of data for this channel. */
725 if (devc->model->series->protocol == PROTOCOL_V3) {
726 /* Signal end of data download to scope */
727 if (devc->data_source != DATA_SOURCE_LIVE)
729 * This causes a query error, without it switching
730 * to the next channel causes an error. Fun with
733 rigol_ds_config_set(sdi, ":WAV:END");
736 if (devc->channel_entry->next) {
737 /* We got the frame for this channel, now get the next channel. */
738 devc->channel_entry = devc->channel_entry->next;
739 rigol_ds_channel_start(sdi);
741 /* Done with this frame. */
742 packet.type = SR_DF_FRAME_END;
743 sr_session_send(cb_data, &packet);
745 if (++devc->num_frames == devc->limit_frames) {
746 /* Last frame, stop capture. */
747 sdi->driver->dev_acquisition_stop(sdi, cb_data);
749 /* Get the next frame, starting with the first channel. */
750 devc->channel_entry = devc->enabled_channels;
752 rigol_ds_capture_start(sdi);
754 /* Start of next frame. */
755 packet.type = SR_DF_FRAME_BEGIN;
756 sr_session_send(cb_data, &packet);
763 SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi)
765 struct dev_context *devc;
772 /* Analog channel state. */
773 for (i = 0; i < devc->model->analog_channels; i++) {
774 cmd = g_strdup_printf(":CHAN%d:DISP?", i + 1);
775 res = sr_scpi_get_bool(sdi->conn, cmd, &devc->analog_channels[i]);
780 sr_dbg("Current analog channel state:");
781 for (i = 0; i < devc->model->analog_channels; i++)
782 sr_dbg("CH%d %s", i + 1, devc->analog_channels[i] ? "on" : "off");
784 /* Digital channel state. */
785 if (devc->model->has_digital) {
786 if (sr_scpi_get_bool(sdi->conn,
787 devc->model->series->protocol >= PROTOCOL_V4 ?
788 ":LA:STAT?" : ":LA:DISP?",
789 &devc->la_enabled) != SR_OK)
791 sr_dbg("Logic analyzer %s, current digital channel state:",
792 devc->la_enabled ? "enabled" : "disabled");
793 for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) {
794 cmd = g_strdup_printf(
795 devc->model->series->protocol >= PROTOCOL_V4 ?
796 ":LA:DIG%d:DISP?" : ":DIG%d:TURN?", i);
797 res = sr_scpi_get_bool(sdi->conn, cmd, &devc->digital_channels[i]);
801 sr_dbg("D%d: %s", i, devc->digital_channels[i] ? "on" : "off");
806 if (sr_scpi_get_float(sdi->conn, ":TIM:SCAL?", &devc->timebase) != SR_OK)
808 sr_dbg("Current timebase %g", devc->timebase);
811 for (i = 0; i < devc->model->analog_channels; i++) {
812 cmd = g_strdup_printf(":CHAN%d:SCAL?", i + 1);
813 res = sr_scpi_get_float(sdi->conn, cmd, &devc->vdiv[i]);
818 sr_dbg("Current vertical gain:");
819 for (i = 0; i < devc->model->analog_channels; i++)
820 sr_dbg("CH%d %g", i + 1, devc->vdiv[i]);
822 /* Vertical offset. */
823 for (i = 0; i < devc->model->analog_channels; i++) {
824 cmd = g_strdup_printf(":CHAN%d:OFFS?", i + 1);
825 res = sr_scpi_get_float(sdi->conn, cmd, &devc->vert_offset[i]);
830 sr_dbg("Current vertical offset:");
831 for (i = 0; i < devc->model->analog_channels; i++)
832 sr_dbg("CH%d %g", i + 1, devc->vert_offset[i]);
835 for (i = 0; i < devc->model->analog_channels; i++) {
836 cmd = g_strdup_printf(":CHAN%d:COUP?", i + 1);
837 res = sr_scpi_get_string(sdi->conn, cmd, &devc->coupling[i]);
842 sr_dbg("Current coupling:");
843 for (i = 0; i < devc->model->analog_channels; i++)
844 sr_dbg("CH%d %s", i + 1, devc->coupling[i]);
846 /* Trigger source. */
847 if (sr_scpi_get_string(sdi->conn, ":TRIG:EDGE:SOUR?", &devc->trigger_source) != SR_OK)
849 sr_dbg("Current trigger source %s", devc->trigger_source);
851 /* Horizontal trigger position. */
852 if (sr_scpi_get_float(sdi->conn, ":TIM:OFFS?", &devc->horiz_triggerpos) != SR_OK)
854 sr_dbg("Current horizontal trigger position %g", devc->horiz_triggerpos);
857 if (sr_scpi_get_string(sdi->conn, ":TRIG:EDGE:SLOP?", &devc->trigger_slope) != SR_OK)
859 sr_dbg("Current trigger slope %s", devc->trigger_slope);