2012-12-29 21:22:10 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the libsigrok project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Martin Ling <martin-git@earth.li>
|
2013-04-08 10:01:00 +00:00
|
|
|
* Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
|
2013-11-01 11:05:49 +00:00
|
|
|
* Copyright (C) 2013 Mathias Grimmberger <mgri@zaphod.sax.de>
|
2012-12-29 21:22:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2012-12-30 03:17:56 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2013-04-07 23:12:42 +00:00
|
|
|
#include <string.h>
|
2013-04-11 14:06:55 +00:00
|
|
|
#include <math.h>
|
2013-11-01 11:05:49 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <time.h>
|
2012-12-29 21:22:10 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include "libsigrok.h"
|
|
|
|
#include "libsigrok-internal.h"
|
|
|
|
#include "protocol.h"
|
|
|
|
|
2013-11-01 11:05:49 +00:00
|
|
|
/*
|
|
|
|
* This is a unified protocol driver for the DS1000 and DS2000 series.
|
|
|
|
*
|
|
|
|
* DS1000 support tested with a Rigol DS1102D.
|
|
|
|
*
|
|
|
|
* DS2000 support tested with a Rigol DS2072 using firmware version 01.01.00.02.
|
|
|
|
*
|
|
|
|
* The Rigol DS2000 series scopes try to adhere to the IEEE 488.2 (I think)
|
|
|
|
* standard. If you want to read it - it costs real money...
|
|
|
|
*
|
|
|
|
* Every response from the scope has a linefeed appended because the
|
|
|
|
* standard says so. In principle this could be ignored because sending the
|
|
|
|
* next command clears the output queue of the scope. This driver tries to
|
|
|
|
* avoid doing that because it may cause an error being generated inside the
|
|
|
|
* scope and who knows what bugs the firmware has WRT this.
|
|
|
|
*
|
|
|
|
* Waveform data is transferred in a format called "arbitrary block program
|
|
|
|
* data" specified in IEEE 488.2. See Agilents programming manuals for their
|
|
|
|
* 2000/3000 series scopes for a nice description.
|
|
|
|
*
|
|
|
|
* Each data block from the scope has a header, e.g. "#900000001400".
|
|
|
|
* The '#' marks the start of a block.
|
|
|
|
* Next is one ASCII decimal digit between 1 and 9, this gives the number of
|
|
|
|
* ASCII decimal digits following.
|
|
|
|
* Last are the ASCII decimal digits giving the number of bytes (not
|
|
|
|
* samples!) in the block.
|
|
|
|
*
|
|
|
|
* After this header as many data bytes as indicated follow.
|
|
|
|
*
|
|
|
|
* Each data block has a trailing linefeed too.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int parse_int(const char *str, int *ret)
|
|
|
|
{
|
|
|
|
char *e;
|
|
|
|
long tmp;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
tmp = strtol(str, &e, 10);
|
|
|
|
if (e == str || *e != '\0') {
|
|
|
|
sr_dbg("Failed to parse integer: '%s'", str);
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
if (errno) {
|
|
|
|
sr_dbg("Failed to parse integer: '%s', numerical overflow", str);
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
if (tmp > INT_MAX || tmp < INT_MIN) {
|
|
|
|
sr_dbg("Failed to parse integer: '%s', value to large/small", str);
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = (int)tmp;
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
/* Set the next event to wait for in rigol_ds_receive */
|
|
|
|
static void rigol_ds_set_wait_event(struct dev_context *devc, enum wait_events event)
|
|
|
|
{
|
|
|
|
if (event == WAIT_STOP)
|
|
|
|
devc->wait_status = 2;
|
|
|
|
else
|
|
|
|
devc->wait_status = 1;
|
|
|
|
devc->wait_event = event;
|
|
|
|
}
|
|
|
|
|
2013-11-01 11:05:49 +00:00
|
|
|
/*
|
2013-11-29 00:14:54 +00:00
|
|
|
* Waiting for a event will return a timeout after 2 to 3 seconds in order
|
|
|
|
* to not block the application.
|
2013-11-01 11:05:49 +00:00
|
|
|
*/
|
2013-11-29 00:14:54 +00:00
|
|
|
static int rigol_ds_event_wait(const struct sr_dev_inst *sdi, char status1, char status2)
|
2013-11-01 11:05:49 +00:00
|
|
|
{
|
2014-01-17 14:10:36 +00:00
|
|
|
char *buf;
|
2013-11-01 11:05:49 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
time_t start;
|
|
|
|
|
|
|
|
if (!(devc = sdi->priv))
|
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
start = time(NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trigger status may return:
|
2013-11-29 00:14:54 +00:00
|
|
|
* "TD" or "T'D" - triggered
|
|
|
|
* "AUTO" - autotriggered
|
|
|
|
* "RUN" - running
|
|
|
|
* "WAIT" - waiting for trigger
|
|
|
|
* "STOP" - stopped
|
2013-11-01 11:05:49 +00:00
|
|
|
*/
|
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
if (devc->wait_status == 1) {
|
2013-11-01 11:05:49 +00:00
|
|
|
do {
|
|
|
|
if (time(NULL) - start >= 3) {
|
|
|
|
sr_dbg("Timeout waiting for trigger");
|
|
|
|
return SR_ERR_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_string(sdi->conn, ":TRIG:STAT?", &buf) != SR_OK)
|
2013-11-01 11:05:49 +00:00
|
|
|
return SR_ERR;
|
2013-11-29 00:14:54 +00:00
|
|
|
} while (buf[0] == status1 || buf[0] == status2);
|
2013-11-01 11:05:49 +00:00
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
devc->wait_status = 2;
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
2013-11-29 00:14:54 +00:00
|
|
|
if (devc->wait_status == 2) {
|
2013-11-01 11:05:49 +00:00
|
|
|
do {
|
|
|
|
if (time(NULL) - start >= 3) {
|
|
|
|
sr_dbg("Timeout waiting for trigger");
|
|
|
|
return SR_ERR_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_string(sdi->conn, ":TRIG:STAT?", &buf) != SR_OK)
|
2013-11-01 11:05:49 +00:00
|
|
|
return SR_ERR;
|
2013-11-29 00:14:54 +00:00
|
|
|
} while (buf[0] != status1 && buf[0] != status2);
|
2013-11-01 11:05:49 +00:00
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
rigol_ds_set_wait_event(devc, WAIT_NONE);
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-11-29 00:14:54 +00:00
|
|
|
* For live capture we need to wait for a new trigger event to ensure that
|
|
|
|
* sample data is not returned twice.
|
2013-11-01 11:05:49 +00:00
|
|
|
*
|
|
|
|
* Unfortunately this will never really work because for sufficiently fast
|
2013-11-29 00:14:54 +00:00
|
|
|
* timebases and trigger rates it just can't catch the status changes.
|
2013-11-01 11:05:49 +00:00
|
|
|
*
|
|
|
|
* What would be needed is a trigger event register with autoreset like the
|
|
|
|
* Agilents have. The Rigols don't seem to have anything like this.
|
|
|
|
*
|
|
|
|
* The workaround is to only wait for the trigger when the timebase is slow
|
|
|
|
* enough. Of course this means that for faster timebases sample data can be
|
2013-11-29 00:14:54 +00:00
|
|
|
* returned multiple times, this effect is mitigated somewhat by sleeping
|
|
|
|
* for about one sweep time in that case.
|
2013-11-01 11:05:49 +00:00
|
|
|
*/
|
2013-11-29 00:14:54 +00:00
|
|
|
static int rigol_ds_trigger_wait(const struct sr_dev_inst *sdi)
|
2013-11-01 11:05:49 +00:00
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
2013-11-29 00:14:54 +00:00
|
|
|
long s;
|
2013-11-01 11:05:49 +00:00
|
|
|
|
|
|
|
if (!(devc = sdi->priv))
|
|
|
|
return SR_ERR;
|
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
/*
|
|
|
|
* If timebase < 50 msecs/DIV just sleep about one sweep time except
|
|
|
|
* for really fast sweeps.
|
|
|
|
*/
|
2014-01-17 00:57:09 +00:00
|
|
|
if (devc->timebase < 0.0499) {
|
2013-11-29 00:14:54 +00:00
|
|
|
if (devc->timebase > 0.99e-6) {
|
|
|
|
/*
|
|
|
|
* Timebase * num hor. divs * 85(%) * 1e6(usecs) / 100
|
|
|
|
* -> 85 percent of sweep time
|
|
|
|
*/
|
2014-01-22 04:08:00 +00:00
|
|
|
s = (devc->timebase * devc->model->series->num_horizontal_divs
|
2013-11-29 00:14:54 +00:00
|
|
|
* 85e6) / 100L;
|
|
|
|
sr_spew("Sleeping for %ld usecs instead of trigger-wait", s);
|
|
|
|
g_usleep(s);
|
|
|
|
}
|
|
|
|
rigol_ds_set_wait_event(devc, WAIT_NONE);
|
|
|
|
return SR_OK;
|
|
|
|
} else {
|
|
|
|
return rigol_ds_event_wait(sdi, 'T', 'A');
|
|
|
|
}
|
|
|
|
}
|
2013-11-01 11:05:49 +00:00
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
/* Wait for scope to got to "Stop" in single shot mode */
|
|
|
|
static int rigol_ds_stop_wait(const struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
return rigol_ds_event_wait(sdi, 'S', 'S');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that a single shot acquisition actually succeeded on the DS2000 */
|
|
|
|
static int rigol_ds_check_stop(const struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
2014-03-24 20:34:20 +00:00
|
|
|
struct sr_channel *ch;
|
2013-11-29 00:14:54 +00:00
|
|
|
int tmp;
|
|
|
|
|
|
|
|
if (!(devc = sdi->priv))
|
2013-11-01 11:05:49 +00:00
|
|
|
return SR_ERR;
|
2013-11-29 00:14:54 +00:00
|
|
|
|
2014-03-24 20:34:20 +00:00
|
|
|
ch = devc->channel_entry->data;
|
2013-12-29 00:34:58 +00:00
|
|
|
|
2014-01-22 04:08:00 +00:00
|
|
|
if (devc->model->series->protocol <= PROTOCOL_V2)
|
2014-01-22 00:25:32 +00:00
|
|
|
return SR_OK;
|
|
|
|
|
2014-01-22 00:22:41 +00:00
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
|
2014-03-24 20:34:20 +00:00
|
|
|
ch->index + 1) != SR_OK)
|
2013-11-29 00:14:54 +00:00
|
|
|
return SR_ERR;
|
|
|
|
/* Check that the number of samples will be accepted */
|
2014-01-22 00:22:41 +00:00
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:POIN %d", devc->analog_frame_size) != SR_OK)
|
2013-11-29 00:14:54 +00:00
|
|
|
return SR_ERR;
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_int(sdi->conn, "*ESR?", &tmp) != SR_OK)
|
2013-11-01 11:05:49 +00:00
|
|
|
return SR_ERR;
|
2013-11-29 00:14:54 +00:00
|
|
|
/*
|
|
|
|
* If we get an "Execution error" the scope went from "Single" to
|
|
|
|
* "Stop" without actually triggering. There is no waveform
|
|
|
|
* displayed and trying to download one will fail - the scope thinks
|
|
|
|
* it has 1400 samples (like display memory) and the driver thinks
|
|
|
|
* it has a different number of samples.
|
|
|
|
*
|
|
|
|
* In that case just try to capture something again. Might still
|
|
|
|
* fail in interesting ways.
|
|
|
|
*
|
|
|
|
* Ain't firmware fun?
|
|
|
|
*/
|
|
|
|
if (tmp & 0x10) {
|
|
|
|
sr_warn("Single shot acquisition failed, retrying...");
|
|
|
|
/* Sleep a bit, otherwise the single shot will often fail */
|
|
|
|
g_usleep(500000);
|
2014-01-22 00:22:41 +00:00
|
|
|
rigol_ds_config_set(sdi, ":SING");
|
2013-11-29 00:14:54 +00:00
|
|
|
rigol_ds_set_wait_event(devc, WAIT_STOP);
|
2013-11-01 11:05:49 +00:00
|
|
|
return SR_ERR;
|
2013-11-29 00:14:54 +00:00
|
|
|
}
|
2013-11-01 11:05:49 +00:00
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
return SR_OK;
|
|
|
|
}
|
2013-11-01 11:05:49 +00:00
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
/* Wait for enough data becoming available in scope output buffer */
|
|
|
|
static int rigol_ds_block_wait(const struct sr_dev_inst *sdi)
|
|
|
|
{
|
2014-01-17 14:10:36 +00:00
|
|
|
char *buf;
|
2013-11-29 00:14:54 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
time_t start;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!(devc = sdi->priv))
|
|
|
|
return SR_ERR;
|
|
|
|
|
2014-01-22 08:15:12 +00:00
|
|
|
if (devc->model->series->protocol >= PROTOCOL_V3) {
|
2013-11-29 00:14:54 +00:00
|
|
|
|
2014-01-22 08:15:12 +00:00
|
|
|
start = time(NULL);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (time(NULL) - start >= 3) {
|
|
|
|
sr_dbg("Timeout waiting for data block");
|
|
|
|
return SR_ERR_TIMEOUT;
|
|
|
|
}
|
2013-11-29 00:14:54 +00:00
|
|
|
|
2014-01-22 08:15:12 +00:00
|
|
|
/*
|
|
|
|
* The scope copies data really slowly from sample
|
|
|
|
* memory to its output buffer, so try not to bother
|
|
|
|
* it too much with SCPI requests but don't wait too
|
|
|
|
* long for short sample frame sizes.
|
|
|
|
*/
|
|
|
|
g_usleep(devc->analog_frame_size < 15000 ? 100000 : 1000000);
|
|
|
|
|
|
|
|
/* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */
|
|
|
|
if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
if (parse_int(buf + 5, &len) != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
} while (buf[0] == 'R' && len < 1000000);
|
|
|
|
}
|
2013-11-29 00:14:54 +00:00
|
|
|
|
|
|
|
rigol_ds_set_wait_event(devc, WAIT_NONE);
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-22 00:22:41 +00:00
|
|
|
/* Send a configuration setting. */
|
|
|
|
SR_PRIV int rigol_ds_config_set(const struct sr_dev_inst *sdi, const char *format, ...)
|
|
|
|
{
|
|
|
|
struct dev_context *devc = sdi->priv;
|
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
ret = sr_scpi_send_variadic(sdi->conn, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
if (ret != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
|
2014-01-22 04:08:00 +00:00
|
|
|
if (devc->model->series->protocol == PROTOCOL_V2) {
|
2014-01-22 00:22:41 +00:00
|
|
|
/* The DS1000 series needs this stupid delay, *OPC? doesn't work. */
|
|
|
|
sr_spew("delay %dms", 100);
|
|
|
|
g_usleep(100000);
|
|
|
|
return SR_OK;
|
|
|
|
} else {
|
|
|
|
return sr_scpi_get_opc(sdi->conn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
/* Start capturing a new frameset */
|
|
|
|
SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
2014-01-22 00:25:32 +00:00
|
|
|
gchar *trig_mode;
|
2013-11-29 00:14:54 +00:00
|
|
|
|
|
|
|
if (!(devc = sdi->priv))
|
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
sr_dbg("Starting data capture for frameset %lu of %lu",
|
|
|
|
devc->num_frames + 1, devc->limit_frames);
|
|
|
|
|
2014-01-22 04:08:00 +00:00
|
|
|
switch (devc->model->series->protocol) {
|
|
|
|
case PROTOCOL_V1:
|
|
|
|
rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
|
|
|
|
break;
|
|
|
|
case PROTOCOL_V2:
|
|
|
|
if (devc->data_source == DATA_SOURCE_LIVE) {
|
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:POIN:MODE NORMAL") != SR_OK)
|
2014-01-22 00:25:32 +00:00
|
|
|
return SR_ERR;
|
2014-01-22 04:08:00 +00:00
|
|
|
rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
|
2014-01-22 00:25:32 +00:00
|
|
|
} else {
|
|
|
|
if (rigol_ds_config_set(sdi, ":STOP") != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:POIN:MODE RAW") != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
if (sr_scpi_get_string(sdi->conn, ":TRIG:MODE?", &trig_mode) != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
if (rigol_ds_config_set(sdi, ":TRIG:%s:SWE SING", trig_mode) != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
if (rigol_ds_config_set(sdi, ":RUN") != SR_OK)
|
|
|
|
return SR_ERR;
|
2014-01-22 04:08:00 +00:00
|
|
|
rigol_ds_set_wait_event(devc, WAIT_STOP);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROTOCOL_V3:
|
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:FORM BYTE") != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
if (devc->data_source == DATA_SOURCE_LIVE) {
|
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:MODE NORM") != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
|
2014-01-22 00:25:32 +00:00
|
|
|
} else {
|
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:MODE RAW") != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
if (rigol_ds_config_set(sdi, ":SING") != SR_OK)
|
|
|
|
return SR_ERR;
|
2014-01-22 04:08:00 +00:00
|
|
|
rigol_ds_set_wait_event(devc, WAIT_STOP);
|
2014-01-22 00:25:32 +00:00
|
|
|
}
|
2014-01-22 04:08:00 +00:00
|
|
|
break;
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
/* Start reading data from the current channel */
|
|
|
|
SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
2014-03-24 20:34:20 +00:00
|
|
|
struct sr_channel *ch;
|
2013-11-29 00:14:54 +00:00
|
|
|
|
|
|
|
if (!(devc = sdi->priv))
|
|
|
|
return SR_ERR;
|
|
|
|
|
2014-03-24 20:34:20 +00:00
|
|
|
ch = devc->channel_entry->data;
|
2013-12-29 00:34:58 +00:00
|
|
|
|
2014-03-24 20:34:20 +00:00
|
|
|
sr_dbg("Starting reading data from channel %d", ch->index + 1);
|
2013-11-29 00:14:54 +00:00
|
|
|
|
2014-01-22 04:08:00 +00:00
|
|
|
if (devc->model->series->protocol <= PROTOCOL_V2) {
|
2014-03-24 21:39:42 +00:00
|
|
|
if (ch->type == SR_CHANNEL_LOGIC) {
|
2013-12-27 16:03:13 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
} else {
|
2013-12-29 00:34:58 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d",
|
2014-03-24 20:34:20 +00:00
|
|
|
ch->index + 1) != SR_OK)
|
2013-12-27 16:03:13 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2014-01-22 00:25:32 +00:00
|
|
|
rigol_ds_set_wait_event(devc, WAIT_NONE);
|
2013-12-27 16:03:13 +00:00
|
|
|
} else {
|
2014-01-22 00:22:41 +00:00
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
|
2014-03-24 20:34:20 +00:00
|
|
|
ch->index + 1) != SR_OK)
|
2013-11-29 00:14:54 +00:00
|
|
|
return SR_ERR;
|
2013-12-27 16:03:13 +00:00
|
|
|
if (devc->data_source != DATA_SOURCE_LIVE) {
|
2014-01-22 00:22:41 +00:00
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:RES") != SR_OK)
|
2013-12-27 16:03:13 +00:00
|
|
|
return SR_ERR;
|
2014-01-22 00:22:41 +00:00
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:BEG") != SR_OK)
|
2013-12-27 16:03:13 +00:00
|
|
|
return SR_ERR;
|
2014-01-22 08:13:27 +00:00
|
|
|
}
|
2013-12-27 16:03:13 +00:00
|
|
|
}
|
2013-11-29 00:14:54 +00:00
|
|
|
|
2014-01-22 08:13:27 +00:00
|
|
|
rigol_ds_set_wait_event(devc, WAIT_BLOCK);
|
|
|
|
|
2014-01-17 15:07:15 +00:00
|
|
|
devc->num_channel_bytes = 0;
|
2014-01-22 08:13:27 +00:00
|
|
|
devc->num_header_bytes = 0;
|
2013-11-29 00:14:54 +00:00
|
|
|
devc->num_block_bytes = 0;
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the header of a data block */
|
2014-01-22 08:13:27 +00:00
|
|
|
static int rigol_ds_read_header(struct sr_dev_inst *sdi)
|
2013-11-01 11:05:49 +00:00
|
|
|
{
|
2014-01-22 08:13:27 +00:00
|
|
|
struct sr_scpi_dev_inst *scpi = sdi->conn;
|
|
|
|
struct dev_context *devc = sdi->priv;
|
|
|
|
char *buf = (char *) devc->buffer;
|
2014-01-23 10:13:54 +00:00
|
|
|
size_t header_length;
|
|
|
|
int ret;
|
2014-01-22 08:13:27 +00:00
|
|
|
|
|
|
|
/* Try to read the hashsign and length digit. */
|
|
|
|
if (devc->num_header_bytes < 2) {
|
2014-01-23 10:13:54 +00:00
|
|
|
ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
|
2014-01-22 08:13:27 +00:00
|
|
|
2 - devc->num_header_bytes);
|
2014-01-23 10:13:54 +00:00
|
|
|
if (ret < 0) {
|
2014-01-22 08:13:27 +00:00
|
|
|
sr_err("Read error while reading data header.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
2014-01-23 10:13:54 +00:00
|
|
|
devc->num_header_bytes += ret;
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
2014-01-22 08:13:27 +00:00
|
|
|
|
|
|
|
if (devc->num_header_bytes < 2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (buf[0] != '#' || !isdigit(buf[1]) || buf[1] == '0') {
|
|
|
|
sr_err("Received invalid data block header '%c%c'.", buf[0], buf[1]);
|
|
|
|
return SR_ERR;
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
|
|
|
|
2014-01-23 10:13:54 +00:00
|
|
|
header_length = 2 + buf[1] - '0';
|
2014-01-22 08:13:27 +00:00
|
|
|
|
|
|
|
/* Try to read the length. */
|
2014-01-23 10:13:54 +00:00
|
|
|
if (devc->num_header_bytes < header_length) {
|
|
|
|
ret = sr_scpi_read_data(scpi, buf + devc->num_header_bytes,
|
|
|
|
header_length - devc->num_header_bytes);
|
|
|
|
if (ret < 0) {
|
2014-01-22 08:13:27 +00:00
|
|
|
sr_err("Read error while reading data header.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
2014-01-23 10:13:54 +00:00
|
|
|
devc->num_header_bytes += ret;
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
2014-01-22 08:13:27 +00:00
|
|
|
|
2014-01-23 10:13:54 +00:00
|
|
|
if (devc->num_header_bytes < header_length)
|
2014-01-22 08:13:27 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Read the data length. */
|
2014-01-23 10:13:54 +00:00
|
|
|
buf[header_length] = '\0';
|
2014-01-22 08:13:27 +00:00
|
|
|
|
2014-01-23 10:13:54 +00:00
|
|
|
if (parse_int(buf + 2, &ret) != SR_OK) {
|
2014-01-22 08:13:27 +00:00
|
|
|
sr_err("Received invalid data block length '%s'.", buf + 2);
|
2013-11-01 11:05:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-23 10:13:54 +00:00
|
|
|
sr_dbg("Received data block header: '%s' -> block length %d", buf, ret);
|
2013-11-01 11:05:49 +00:00
|
|
|
|
2014-01-23 10:13:54 +00:00
|
|
|
return ret;
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 17:31:39 +00:00
|
|
|
SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2012-12-30 03:17:56 +00:00
|
|
|
struct sr_dev_inst *sdi;
|
2013-12-03 23:19:40 +00:00
|
|
|
struct sr_scpi_dev_inst *scpi;
|
2012-12-29 21:22:10 +00:00
|
|
|
struct dev_context *devc;
|
2012-12-30 03:17:56 +00:00
|
|
|
struct sr_datafeed_packet packet;
|
|
|
|
struct sr_datafeed_analog analog;
|
2013-04-14 01:21:55 +00:00
|
|
|
struct sr_datafeed_logic logic;
|
2013-04-11 14:06:55 +00:00
|
|
|
double vdiv, offset;
|
2013-12-27 17:56:59 +00:00
|
|
|
int len, i, vref;
|
2014-03-24 20:34:20 +00:00
|
|
|
struct sr_channel *ch;
|
2014-01-17 14:46:10 +00:00
|
|
|
gsize expected_data_bytes;
|
2012-12-29 21:22:10 +00:00
|
|
|
|
2013-05-10 16:30:32 +00:00
|
|
|
(void)fd;
|
2013-04-22 15:12:06 +00:00
|
|
|
|
2012-12-29 21:22:10 +00:00
|
|
|
if (!(sdi = cb_data))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!(devc = sdi->priv))
|
|
|
|
return TRUE;
|
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
scpi = sdi->conn;
|
2013-04-22 15:12:06 +00:00
|
|
|
|
2014-01-09 22:44:35 +00:00
|
|
|
if (revents == G_IO_IN || revents == 0) {
|
2014-01-22 00:25:32 +00:00
|
|
|
switch(devc->wait_event) {
|
|
|
|
case WAIT_NONE:
|
|
|
|
break;
|
|
|
|
case WAIT_TRIGGER:
|
|
|
|
if (rigol_ds_trigger_wait(sdi) != SR_OK)
|
2013-11-01 11:05:49 +00:00
|
|
|
return TRUE;
|
2014-01-22 00:25:32 +00:00
|
|
|
if (rigol_ds_channel_start(sdi) != SR_OK)
|
|
|
|
return TRUE;
|
2014-02-02 20:44:26 +00:00
|
|
|
return TRUE;
|
2014-01-22 00:25:32 +00:00
|
|
|
case WAIT_BLOCK:
|
|
|
|
if (rigol_ds_block_wait(sdi) != SR_OK)
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
case WAIT_STOP:
|
|
|
|
if (rigol_ds_stop_wait(sdi) != SR_OK)
|
|
|
|
return TRUE;
|
|
|
|
if (rigol_ds_check_stop(sdi) != SR_OK)
|
|
|
|
return TRUE;
|
|
|
|
if (rigol_ds_channel_start(sdi) != SR_OK)
|
|
|
|
return TRUE;
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
sr_err("BUG: Unknown event target encountered");
|
2013-12-27 17:56:59 +00:00
|
|
|
}
|
|
|
|
|
2014-03-24 20:34:20 +00:00
|
|
|
ch = devc->channel_entry->data;
|
2014-01-17 14:46:10 +00:00
|
|
|
|
2014-03-24 21:39:42 +00:00
|
|
|
expected_data_bytes = ch->type == SR_CHANNEL_ANALOG ?
|
2014-01-17 14:46:10 +00:00
|
|
|
devc->analog_frame_size : devc->digital_frame_size;
|
2014-01-17 15:07:15 +00:00
|
|
|
|
2014-01-22 00:25:32 +00:00
|
|
|
if (devc->num_block_bytes == 0) {
|
2014-01-22 04:08:00 +00:00
|
|
|
if (devc->model->series->protocol >= PROTOCOL_V3)
|
2014-01-01 17:24:45 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
|
|
|
|
return TRUE;
|
2014-01-17 14:46:10 +00:00
|
|
|
|
2013-12-29 01:36:49 +00:00
|
|
|
if (sr_scpi_read_begin(scpi) != SR_OK)
|
|
|
|
return TRUE;
|
2014-01-17 14:46:10 +00:00
|
|
|
|
2014-01-22 04:08:00 +00:00
|
|
|
if (devc->format == FORMAT_IEEE488_2) {
|
2013-11-29 00:14:54 +00:00
|
|
|
sr_dbg("New block header expected");
|
2014-01-22 08:13:27 +00:00
|
|
|
len = rigol_ds_read_header(sdi);
|
|
|
|
if (len == 0)
|
|
|
|
/* Still reading the header. */
|
|
|
|
return TRUE;
|
|
|
|
if (len == -1) {
|
|
|
|
sr_err("Read error, aborting capture.");
|
|
|
|
packet.type = SR_DF_FRAME_END;
|
|
|
|
sr_session_send(cb_data, &packet);
|
|
|
|
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
2013-11-29 00:14:54 +00:00
|
|
|
return TRUE;
|
2014-01-22 08:13:27 +00:00
|
|
|
}
|
2013-11-29 00:14:54 +00:00
|
|
|
/* At slow timebases in live capture the DS2072
|
|
|
|
* sometimes returns "short" data blocks, with
|
|
|
|
* apparently no way to get the rest of the data.
|
|
|
|
* Discard these, the complete data block will
|
|
|
|
* appear eventually.
|
|
|
|
*/
|
|
|
|
if (devc->data_source == DATA_SOURCE_LIVE
|
2014-01-17 14:46:10 +00:00
|
|
|
&& (unsigned)len < expected_data_bytes) {
|
2013-11-29 00:14:54 +00:00
|
|
|
sr_dbg("Discarding short data block");
|
2013-12-29 01:36:49 +00:00
|
|
|
sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1);
|
2013-11-29 00:14:54 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
devc->num_block_bytes = len;
|
2013-12-27 17:56:59 +00:00
|
|
|
} else {
|
2014-01-17 14:46:10 +00:00
|
|
|
devc->num_block_bytes = expected_data_bytes;
|
2013-12-27 17:56:59 +00:00
|
|
|
}
|
|
|
|
devc->num_block_read = 0;
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
2013-12-27 17:56:59 +00:00
|
|
|
|
|
|
|
len = devc->num_block_bytes - devc->num_block_read;
|
2014-01-22 04:50:38 +00:00
|
|
|
if (len > ACQ_BUFFER_SIZE)
|
|
|
|
len = ACQ_BUFFER_SIZE;
|
|
|
|
sr_dbg("Requesting read of %d bytes", len);
|
|
|
|
|
|
|
|
len = sr_scpi_read_data(scpi, (char *)devc->buffer, len);
|
2013-12-27 17:56:59 +00:00
|
|
|
|
2014-01-22 04:57:48 +00:00
|
|
|
if (len == -1) {
|
|
|
|
sr_err("Read error, aborting capture.");
|
|
|
|
packet.type = SR_DF_FRAME_END;
|
|
|
|
sr_session_send(cb_data, &packet);
|
|
|
|
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-01-22 04:50:38 +00:00
|
|
|
|
|
|
|
sr_dbg("Received %d bytes.", len);
|
2013-04-07 22:38:58 +00:00
|
|
|
|
2013-12-27 18:50:48 +00:00
|
|
|
devc->num_block_read += len;
|
|
|
|
|
2014-03-24 21:39:42 +00:00
|
|
|
if (ch->type == SR_CHANNEL_ANALOG) {
|
2014-03-24 20:34:20 +00:00
|
|
|
vref = devc->vert_reference[ch->index];
|
|
|
|
vdiv = devc->vdiv[ch->index] / 25.6;
|
|
|
|
offset = devc->vert_offset[ch->index];
|
2014-01-22 04:08:00 +00:00
|
|
|
if (devc->model->series->protocol >= PROTOCOL_V3)
|
2013-11-01 11:05:49 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2013-11-29 00:14:54 +00:00
|
|
|
devc->data[i] = ((int)devc->buffer[i] - vref) * vdiv - offset;
|
2013-11-01 11:05:49 +00:00
|
|
|
else
|
|
|
|
for (i = 0; i < len; i++)
|
2013-11-29 00:14:54 +00:00
|
|
|
devc->data[i] = (128 - devc->buffer[i]) * vdiv - offset;
|
2014-03-24 20:34:20 +00:00
|
|
|
analog.channels = g_slist_append(NULL, ch);
|
2013-04-14 01:21:55 +00:00
|
|
|
analog.num_samples = len;
|
2013-11-29 00:14:54 +00:00
|
|
|
analog.data = devc->data;
|
2013-04-14 01:21:55 +00:00
|
|
|
analog.mq = SR_MQ_VOLTAGE;
|
|
|
|
analog.unit = SR_UNIT_VOLT;
|
|
|
|
analog.mqflags = 0;
|
|
|
|
packet.type = SR_DF_ANALOG;
|
|
|
|
packet.payload = &analog;
|
|
|
|
sr_session_send(cb_data, &packet);
|
2014-03-24 20:34:20 +00:00
|
|
|
g_slist_free(analog.channels);
|
2013-04-14 01:21:55 +00:00
|
|
|
} else {
|
2014-01-17 02:56:45 +00:00
|
|
|
logic.length = len;
|
2013-04-14 01:21:55 +00:00
|
|
|
logic.unitsize = 2;
|
2014-01-17 02:56:45 +00:00
|
|
|
logic.data = devc->buffer;
|
2013-04-14 01:21:55 +00:00
|
|
|
packet.type = SR_DF_LOGIC;
|
|
|
|
packet.payload = &logic;
|
|
|
|
sr_session_send(cb_data, &packet);
|
2013-12-27 18:50:48 +00:00
|
|
|
}
|
2013-04-14 01:21:55 +00:00
|
|
|
|
2013-12-27 18:50:48 +00:00
|
|
|
if (devc->num_block_read == devc->num_block_bytes) {
|
|
|
|
sr_dbg("Block has been completed");
|
2014-01-22 04:49:57 +00:00
|
|
|
if (devc->model->series->protocol >= PROTOCOL_V3) {
|
2014-01-17 02:56:45 +00:00
|
|
|
/* Discard the terminating linefeed */
|
2013-12-29 01:36:49 +00:00
|
|
|
sr_scpi_read_data(scpi, (char *)devc->buffer, 1);
|
2014-01-22 04:49:57 +00:00
|
|
|
}
|
|
|
|
if (devc->format == FORMAT_IEEE488_2) {
|
2014-01-17 02:56:45 +00:00
|
|
|
/* Prepare for possible next block */
|
2014-01-22 08:13:27 +00:00
|
|
|
devc->num_header_bytes = 0;
|
2013-12-27 18:50:48 +00:00
|
|
|
devc->num_block_bytes = 0;
|
|
|
|
if (devc->data_source != DATA_SOURCE_LIVE)
|
|
|
|
rigol_ds_set_wait_event(devc, WAIT_BLOCK);
|
|
|
|
}
|
2014-01-17 02:27:29 +00:00
|
|
|
if (!sr_scpi_read_complete(scpi)) {
|
|
|
|
sr_err("Read should have been completed");
|
2014-01-22 04:57:48 +00:00
|
|
|
packet.type = SR_DF_FRAME_END;
|
|
|
|
sr_session_send(cb_data, &packet);
|
2014-01-17 02:27:29 +00:00
|
|
|
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-27 18:50:48 +00:00
|
|
|
devc->num_block_read = 0;
|
|
|
|
} else {
|
|
|
|
sr_dbg("%d of %d block bytes read", devc->num_block_read, devc->num_block_bytes);
|
2013-04-14 00:58:35 +00:00
|
|
|
}
|
2013-04-07 22:38:58 +00:00
|
|
|
|
2014-01-17 15:07:15 +00:00
|
|
|
devc->num_channel_bytes += len;
|
2013-12-27 18:50:48 +00:00
|
|
|
|
2014-01-17 15:07:15 +00:00
|
|
|
if (devc->num_channel_bytes < expected_data_bytes)
|
|
|
|
/* Don't have the full data for this channel yet, re-run. */
|
2013-12-27 18:50:48 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2014-01-17 15:07:15 +00:00
|
|
|
/* End of data for this channel. */
|
2014-01-22 04:08:00 +00:00
|
|
|
if (devc->model->series->protocol >= PROTOCOL_V3) {
|
2013-11-29 00:14:54 +00:00
|
|
|
/* Signal end of data download to scope */
|
|
|
|
if (devc->data_source != DATA_SOURCE_LIVE)
|
|
|
|
/*
|
|
|
|
* This causes a query error, without it switching
|
|
|
|
* to the next channel causes an error. Fun with
|
|
|
|
* firmware...
|
|
|
|
*/
|
2014-01-22 00:22:41 +00:00
|
|
|
rigol_ds_config_set(sdi, ":WAV:END");
|
2013-11-29 00:14:54 +00:00
|
|
|
}
|
2013-04-11 14:06:55 +00:00
|
|
|
|
2014-03-24 21:39:42 +00:00
|
|
|
if (ch->type == SR_CHANNEL_ANALOG
|
2013-12-29 00:34:58 +00:00
|
|
|
&& devc->channel_entry->next != NULL) {
|
|
|
|
/* We got the frame for this analog channel, but
|
|
|
|
* there's another analog channel. */
|
|
|
|
devc->channel_entry = devc->channel_entry->next;
|
2013-12-27 16:03:13 +00:00
|
|
|
rigol_ds_channel_start(sdi);
|
2013-04-11 14:06:55 +00:00
|
|
|
} else {
|
2013-12-29 00:34:58 +00:00
|
|
|
/* Done with all analog channels in this frame. */
|
2014-03-24 20:34:20 +00:00
|
|
|
if (devc->enabled_digital_channels
|
|
|
|
&& devc->channel_entry != devc->enabled_digital_channels) {
|
2013-04-14 01:21:55 +00:00
|
|
|
/* Now we need to get the digital data. */
|
2014-03-24 20:34:20 +00:00
|
|
|
devc->channel_entry = devc->enabled_digital_channels;
|
2013-12-27 16:03:13 +00:00
|
|
|
rigol_ds_channel_start(sdi);
|
2013-04-11 14:06:55 +00:00
|
|
|
} else {
|
2014-01-17 15:07:15 +00:00
|
|
|
/* Done with this frame. */
|
|
|
|
packet.type = SR_DF_FRAME_END;
|
|
|
|
sr_session_send(cb_data, &packet);
|
|
|
|
|
|
|
|
if (++devc->num_frames == devc->limit_frames) {
|
|
|
|
/* Last frame, stop capture. */
|
|
|
|
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
|
|
|
} else {
|
|
|
|
/* Get the next frame, starting with the first analog channel. */
|
2014-03-24 20:34:20 +00:00
|
|
|
if (devc->enabled_analog_channels)
|
|
|
|
devc->channel_entry = devc->enabled_analog_channels;
|
2014-01-17 15:07:15 +00:00
|
|
|
else
|
2014-03-24 20:34:20 +00:00
|
|
|
devc->channel_entry = devc->enabled_digital_channels;
|
2014-01-17 15:07:15 +00:00
|
|
|
|
2014-01-22 00:25:32 +00:00
|
|
|
rigol_ds_capture_start(sdi);
|
2014-01-17 15:07:15 +00:00
|
|
|
|
|
|
|
/* Start of next frame. */
|
|
|
|
packet.type = SR_DF_FRAME_BEGIN;
|
|
|
|
sr_session_send(cb_data, &packet);
|
|
|
|
}
|
2013-04-11 14:06:55 +00:00
|
|
|
}
|
2013-04-07 22:38:58 +00:00
|
|
|
}
|
2012-12-29 21:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-12-30 03:17:56 +00:00
|
|
|
|
2013-10-31 17:31:39 +00:00
|
|
|
SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi)
|
2013-04-11 14:06:55 +00:00
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
2013-04-14 01:21:55 +00:00
|
|
|
char *t_s, *cmd;
|
2013-12-29 00:34:58 +00:00
|
|
|
unsigned int i;
|
|
|
|
int res;
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
devc = sdi->priv;
|
|
|
|
|
2013-04-14 01:21:55 +00:00
|
|
|
/* Analog channel state. */
|
2013-12-29 00:34:58 +00:00
|
|
|
for (i = 0; i < devc->model->analog_channels; i++) {
|
|
|
|
cmd = g_strdup_printf(":CHAN%d:DISP?", i + 1);
|
2014-01-17 14:10:36 +00:00
|
|
|
res = sr_scpi_get_string(sdi->conn, cmd, &t_s);
|
2013-12-29 00:34:58 +00:00
|
|
|
g_free(cmd);
|
|
|
|
if (res != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
devc->analog_channels[i] = !strcmp(t_s, "ON") || !strcmp(t_s, "1");
|
|
|
|
}
|
|
|
|
sr_dbg("Current analog channel state:");
|
|
|
|
for (i = 0; i < devc->model->analog_channels; i++)
|
|
|
|
sr_dbg("CH%d %s", i + 1, devc->analog_channels[i] ? "on" : "off");
|
2013-04-14 01:21:55 +00:00
|
|
|
|
|
|
|
/* Digital channel state. */
|
2013-11-01 11:05:49 +00:00
|
|
|
if (devc->model->has_digital) {
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_string(sdi->conn, ":LA:DISP?", &t_s) != SR_OK)
|
2014-01-16 23:25:59 +00:00
|
|
|
return SR_ERR;
|
|
|
|
devc->la_enabled = !strcmp(t_s, "ON") ? TRUE : FALSE;
|
|
|
|
sr_dbg("Logic analyzer %s, current digital channel state:",
|
|
|
|
devc->la_enabled ? "enabled" : "disabled");
|
2013-04-14 01:21:55 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
2014-01-14 18:25:08 +00:00
|
|
|
cmd = g_strdup_printf(":DIG%d:TURN?", i);
|
2014-01-17 14:10:36 +00:00
|
|
|
res = sr_scpi_get_string(sdi->conn, cmd, &t_s);
|
2013-04-14 01:21:55 +00:00
|
|
|
g_free(cmd);
|
|
|
|
if (res != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
devc->digital_channels[i] = !strcmp(t_s, "ON") ? TRUE : FALSE;
|
|
|
|
g_free(t_s);
|
2014-01-14 18:25:08 +00:00
|
|
|
sr_dbg("D%d: %s", i, devc->digital_channels[i] ? "on" : "off");
|
2013-04-14 01:21:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
/* Timebase. */
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_float(sdi->conn, ":TIM:SCAL?", &devc->timebase) != SR_OK)
|
2013-04-11 14:06:55 +00:00
|
|
|
return SR_ERR;
|
2013-11-01 11:05:49 +00:00
|
|
|
sr_dbg("Current timebase %g", devc->timebase);
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
/* Vertical gain. */
|
2013-12-29 00:34:58 +00:00
|
|
|
for (i = 0; i < devc->model->analog_channels; i++) {
|
|
|
|
cmd = g_strdup_printf(":CHAN%d:SCAL?", i + 1);
|
2014-01-17 14:10:36 +00:00
|
|
|
res = sr_scpi_get_float(sdi->conn, cmd, &devc->vdiv[i]);
|
2013-12-29 00:34:58 +00:00
|
|
|
g_free(cmd);
|
|
|
|
if (res != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
sr_dbg("Current vertical gain:");
|
|
|
|
for (i = 0; i < devc->model->analog_channels; i++)
|
|
|
|
sr_dbg("CH%d %g", i + 1, devc->vdiv[i]);
|
2013-11-01 11:05:49 +00:00
|
|
|
|
2013-12-29 00:34:58 +00:00
|
|
|
sr_dbg("Current vertical reference:");
|
2014-01-22 04:08:00 +00:00
|
|
|
if (devc->model->series->protocol >= PROTOCOL_V3) {
|
2013-11-01 11:05:49 +00:00
|
|
|
/* Vertical reference - not certain if this is the place to read it. */
|
2013-12-29 00:34:58 +00:00
|
|
|
for (i = 0; i < devc->model->analog_channels; i++) {
|
2014-01-22 00:22:41 +00:00
|
|
|
if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", i + 1) != SR_OK)
|
2013-12-29 00:34:58 +00:00
|
|
|
return SR_ERR;
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_int(sdi->conn, ":WAV:YREF?", &devc->vert_reference[i]) != SR_OK)
|
2013-12-29 00:34:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
sr_dbg("CH%d %d", i + 1, devc->vert_reference[i]);
|
|
|
|
}
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
/* Vertical offset. */
|
2013-12-29 00:34:58 +00:00
|
|
|
for (i = 0; i < devc->model->analog_channels; i++) {
|
|
|
|
cmd = g_strdup_printf(":CHAN%d:OFFS?", i + 1);
|
2014-01-17 14:10:36 +00:00
|
|
|
res = sr_scpi_get_float(sdi->conn, cmd, &devc->vert_offset[i]);
|
2013-12-29 00:34:58 +00:00
|
|
|
g_free(cmd);
|
|
|
|
if (res != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
sr_dbg("Current vertical offset:");
|
|
|
|
for (i = 0; i < devc->model->analog_channels; i++)
|
|
|
|
sr_dbg("CH%d %g", i + 1, devc->vert_offset[i]);
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
/* Coupling. */
|
2013-12-29 00:34:58 +00:00
|
|
|
for (i = 0; i < devc->model->analog_channels; i++) {
|
|
|
|
cmd = g_strdup_printf(":CHAN%d:COUP?", i + 1);
|
2014-01-17 14:10:36 +00:00
|
|
|
res = sr_scpi_get_string(sdi->conn, cmd, &devc->coupling[i]);
|
2013-12-29 00:34:58 +00:00
|
|
|
g_free(cmd);
|
|
|
|
if (res != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
sr_dbg("Current coupling:");
|
|
|
|
for (i = 0; i < devc->model->analog_channels; i++)
|
|
|
|
sr_dbg("CH%d %s", i + 1, devc->coupling[i]);
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
/* Trigger source. */
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_string(sdi->conn, ":TRIG:EDGE:SOUR?", &devc->trigger_source) != SR_OK)
|
2013-04-11 14:06:55 +00:00
|
|
|
return SR_ERR;
|
|
|
|
sr_dbg("Current trigger source %s", devc->trigger_source);
|
|
|
|
|
|
|
|
/* Horizontal trigger position. */
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_float(sdi->conn, ":TIM:OFFS?", &devc->horiz_triggerpos) != SR_OK)
|
2013-04-11 14:06:55 +00:00
|
|
|
return SR_ERR;
|
2013-11-01 11:05:49 +00:00
|
|
|
sr_dbg("Current horizontal trigger position %g", devc->horiz_triggerpos);
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
/* Trigger slope. */
|
2014-01-17 14:10:36 +00:00
|
|
|
if (sr_scpi_get_string(sdi->conn, ":TRIG:EDGE:SLOP?", &devc->trigger_slope) != SR_OK)
|
2013-04-11 14:06:55 +00:00
|
|
|
return SR_ERR;
|
|
|
|
sr_dbg("Current trigger slope %s", devc->trigger_slope);
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|