* Timebase * num hor. divs * 85(%) * 1e6(usecs) / 100
* -> 85 percent of sweep time
*/
- s = (devc->timebase * devc->model->num_horizontal_divs
+ s = (devc->timebase * devc->model->series->num_horizontal_divs
* 85e6) / 100L;
sr_spew("Sleeping for %ld usecs instead of trigger-wait", s);
g_usleep(s);
probe = devc->channel_entry->data;
- if (sr_scpi_send(sdi->conn, ":WAV:SOUR CHAN%d",
+ if (devc->model->series->protocol <= PROTOCOL_V2)
+ return SR_OK;
+
+ if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
probe->index + 1) != SR_OK)
return SR_ERR;
/* Check that the number of samples will be accepted */
- if (sr_scpi_send(sdi->conn, ":WAV:POIN %d;*OPC", devc->analog_frame_size) != SR_OK)
+ if (rigol_ds_config_set(sdi, ":WAV:POIN %d", devc->analog_frame_size) != SR_OK)
return SR_ERR;
if (sr_scpi_get_int(sdi->conn, "*ESR?", &tmp) != SR_OK)
return SR_ERR;
sr_warn("Single shot acquisition failed, retrying...");
/* Sleep a bit, otherwise the single shot will often fail */
g_usleep(500000);
- sr_scpi_send(sdi->conn, ":SING");
+ rigol_ds_config_set(sdi, ":SING");
rigol_ds_set_wait_event(devc, WAIT_STOP);
return SR_ERR;
}
return SR_OK;
}
+/* 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;
+
+ if (devc->model->series->protocol == PROTOCOL_V2) {
+ /* 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);
+ }
+}
+
/* Start capturing a new frameset */
SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
+ gchar *trig_mode;
if (!(devc = sdi->priv))
return SR_ERR;
sr_dbg("Starting data capture for frameset %lu of %lu",
devc->num_frames + 1, devc->limit_frames);
- if (sr_scpi_send(sdi->conn, ":WAV:FORM BYTE") != SR_OK)
- return SR_ERR;
- if (devc->data_source == DATA_SOURCE_LIVE) {
- if (sr_scpi_send(sdi->conn, ":WAV:MODE NORM") != SR_OK)
- return SR_ERR;
+ switch (devc->model->series->protocol) {
+ case PROTOCOL_V1:
rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
- } else {
- if (sr_scpi_send(sdi->conn, ":WAV:MODE RAW") != SR_OK)
+ break;
+ case PROTOCOL_V2:
+ if (devc->data_source == DATA_SOURCE_LIVE) {
+ if (rigol_ds_config_set(sdi, ":WAV:POIN:MODE NORMAL") != SR_OK)
+ return SR_ERR;
+ rigol_ds_set_wait_event(devc, WAIT_TRIGGER);
+ } 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;
+ 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 (sr_scpi_send(sdi->conn, ":SING", devc->analog_frame_size) != SR_OK)
- return SR_ERR;
- rigol_ds_set_wait_event(devc, WAIT_STOP);
+ 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);
+ } 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;
+ rigol_ds_set_wait_event(devc, WAIT_STOP);
+ }
+ break;
}
return SR_OK;
sr_dbg("Starting reading data from channel %d", probe->index + 1);
- if (devc->model->series < RIGOL_DS1000Z) {
+ if (devc->model->series->protocol <= PROTOCOL_V2) {
if (probe->type == SR_PROBE_LOGIC) {
if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK)
return SR_ERR;
probe->index + 1) != SR_OK)
return SR_ERR;
}
+ rigol_ds_set_wait_event(devc, WAIT_NONE);
} else {
- if (sr_scpi_send(sdi->conn, ":WAV:SOUR CHAN%d",
+ if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d",
probe->index + 1) != SR_OK)
return SR_ERR;
if (devc->data_source != DATA_SOURCE_LIVE) {
- if (sr_scpi_send(sdi->conn, ":WAV:RES") != SR_OK)
+ if (rigol_ds_config_set(sdi, ":WAV:RES") != SR_OK)
return SR_ERR;
- if (sr_scpi_send(sdi->conn, ":WAV:BEG") != SR_OK)
+ if (rigol_ds_config_set(sdi, ":WAV:BEG") != SR_OK)
return SR_ERR;
rigol_ds_set_wait_event(devc, WAIT_BLOCK);
} else
rigol_ds_set_wait_event(devc, WAIT_NONE);
}
- devc->num_frame_samples = 0;
+ devc->num_channel_bytes = 0;
devc->num_block_bytes = 0;
return SR_OK;
scpi = sdi->conn;
if (revents == G_IO_IN || revents == 0) {
- if (devc->model->series >= RIGOL_DS1000Z) {
- switch(devc->wait_event) {
- case WAIT_NONE:
- break;
- case WAIT_TRIGGER:
- if (rigol_ds_trigger_wait(sdi) != SR_OK)
- return TRUE;
- if (rigol_ds_channel_start(sdi) != SR_OK)
- return TRUE;
- break;
- 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;
+ switch(devc->wait_event) {
+ case WAIT_NONE:
+ break;
+ case WAIT_TRIGGER:
+ if (rigol_ds_trigger_wait(sdi) != SR_OK)
return TRUE;
- default:
- sr_err("BUG: Unknown event target encountered");
- }
+ if (rigol_ds_channel_start(sdi) != SR_OK)
+ return TRUE;
+ break;
+ 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");
}
probe = devc->channel_entry->data;
expected_data_bytes = probe->type == SR_PROBE_ANALOG ?
devc->analog_frame_size : devc->digital_frame_size;
-
- if (devc->num_block_bytes == 0 &&
- devc->model->series >= RIGOL_DS1000Z) {
- if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
- return TRUE;
- }
if (devc->num_block_bytes == 0) {
+ if (devc->model->series->protocol >= PROTOCOL_V3)
+ if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
+ return TRUE;
if (sr_scpi_read_begin(scpi) != SR_OK)
return TRUE;
- if (devc->model->protocol == PROTOCOL_IEEE488_2) {
+ if (devc->format == FORMAT_IEEE488_2) {
sr_dbg("New block header expected");
len = rigol_ds_read_header(scpi);
if (len == -1)
devc->num_block_read += len;
- if (devc->num_frame_samples == 0) {
- /* Start of a new frame. */
- packet.type = SR_DF_FRAME_BEGIN;
- sr_session_send(sdi, &packet);
- }
-
if (probe->type == SR_PROBE_ANALOG) {
vref = devc->vert_reference[probe->index];
vdiv = devc->vdiv[probe->index] / 25.6;
offset = devc->vert_offset[probe->index];
- if (devc->model->series >= RIGOL_DS1000Z)
+ if (devc->model->series->protocol >= PROTOCOL_V3)
for (i = 0; i < len; i++)
devc->data[i] = ((int)devc->buffer[i] - vref) * vdiv - offset;
else
if (devc->num_block_read == devc->num_block_bytes) {
sr_dbg("Block has been completed");
- if (devc->model->series >= RIGOL_DS1000Z) {
+ if (devc->format == FORMAT_IEEE488_2) {
/* Discard the terminating linefeed */
sr_scpi_read_data(scpi, (char *)devc->buffer, 1);
- }
- if (devc->model->protocol == PROTOCOL_IEEE488_2) {
/* Prepare for possible next block */
devc->num_block_bytes = 0;
if (devc->data_source != DATA_SOURCE_LIVE)
sr_dbg("%d of %d block bytes read", devc->num_block_read, devc->num_block_bytes);
}
- devc->num_frame_samples += len;
+ devc->num_channel_bytes += len;
- if (devc->num_frame_samples < expected_data_bytes)
- /* Don't have the whole frame yet. */
+ if (devc->num_channel_bytes < expected_data_bytes)
+ /* Don't have the full data for this channel yet, re-run. */
return TRUE;
- /* End of the frame. */
- sr_dbg("Frame completed, %d samples", devc->num_frame_samples);
- packet.type = SR_DF_FRAME_END;
- sr_session_send(sdi, &packet);
- if (devc->model->series >= RIGOL_DS1000Z) {
+ /* End of data for this channel. */
+ if (devc->model->series->protocol >= PROTOCOL_V3) {
/* Signal end of data download to scope */
if (devc->data_source != DATA_SOURCE_LIVE)
/*
* to the next channel causes an error. Fun with
* firmware...
*/
- sr_scpi_send(sdi->conn, ":WAV:END");
+ rigol_ds_config_set(sdi, ":WAV:END");
}
if (probe->type == SR_PROBE_ANALOG
/* Now we need to get the digital data. */
devc->channel_entry = devc->enabled_digital_probes;
rigol_ds_channel_start(sdi);
- } else if (++devc->num_frames == devc->limit_frames) {
- sdi->driver->dev_acquisition_stop(sdi, cb_data);
} else {
- /* Get the next frame, starting with the first analog channel. */
- if (devc->enabled_analog_probes)
- devc->channel_entry = devc->enabled_analog_probes;
- else
- devc->channel_entry = devc->enabled_digital_probes;
-
- if (devc->model->series < RIGOL_DS1000Z)
- rigol_ds_channel_start(sdi);
- else
+ /* 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. */
+ if (devc->enabled_analog_probes)
+ devc->channel_entry = devc->enabled_analog_probes;
+ else
+ devc->channel_entry = devc->enabled_digital_probes;
+
rigol_ds_capture_start(sdi);
+
+ /* Start of next frame. */
+ packet.type = SR_DF_FRAME_BEGIN;
+ sr_session_send(cb_data, &packet);
+ }
}
}
}
sr_dbg("CH%d %g", i + 1, devc->vdiv[i]);
sr_dbg("Current vertical reference:");
- if (devc->model->series >= RIGOL_DS1000Z) {
+ if (devc->model->series->protocol >= PROTOCOL_V3) {
/* Vertical reference - not certain if this is the place to read it. */
for (i = 0; i < devc->model->analog_channels; i++) {
- if (sr_scpi_send(sdi->conn, ":WAV:SOUR CHAN%d", i + 1) != SR_OK)
+ if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", i + 1) != SR_OK)
return SR_ERR;
if (sr_scpi_get_int(sdi->conn, ":WAV:YREF?", &devc->vert_reference[i]) != SR_OK)
return SR_ERR;