From: Valentin Ochs Date: Thu, 11 Jun 2020 16:14:17 +0000 (+0200) Subject: rigol-ds: Get correct samplerate for Memory and Segmented sources X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1cbb3b1cfbd0334001bde052413cc7aa869d5994;p=libsigrok.git rigol-ds: Get correct samplerate for Memory and Segmented sources Read it at the start of acquisition. This prevents requests for the SR from interfering with ongoing transfers. This fixes bug #1217. --- diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index e86c922e..af15587d 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -526,7 +526,6 @@ static int config_get(uint32_t key, GVariant **data, struct dev_context *devc; struct sr_channel *ch; const char *tmp_str; - uint64_t samplerate; int analog_channel = -1; float smallest_diff = INFINITY; int idx = -1; @@ -570,14 +569,7 @@ static int config_get(uint32_t key, GVariant **data, *data = g_variant_new_string("Segmented"); break; case SR_CONF_SAMPLERATE: - if (devc->data_source == DATA_SOURCE_LIVE) { - samplerate = analog_frame_size(sdi) / - (devc->timebase * devc->model->series->num_horizontal_divs); - *data = g_variant_new_uint64(samplerate); - } else { - sr_dbg("Unknown data source: %d.", devc->data_source); - return SR_ERR_NA; - } + *data = g_variant_new_uint64(devc->sample_rate); break; case SR_CONF_TRIGGER_SOURCE: if (!strcmp(devc->trigger_source, "ACL")) @@ -990,6 +982,20 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc->channel_entry = devc->enabled_channels; + if (devc->data_source == DATA_SOURCE_LIVE) + devc->sample_rate = analog_frame_size(sdi) / + (devc->timebase * devc->model->series->num_horizontal_divs); + else { + float xinc; + if (devc->model->series->protocol >= PROTOCOL_V3 && + sr_scpi_get_float(sdi->conn, "WAV:XINC?", &xinc) != SR_OK) { + sr_err("Couldn't get sampling rate"); + return SR_ERR; + } + devc->sample_rate = 1. / xinc; + } + + if (rigol_ds_capture_start(sdi) != SR_OK) return SR_ERR; diff --git a/src/hardware/rigol-ds/protocol.h b/src/hardware/rigol-ds/protocol.h index a40c7ac1..ccecfabe 100644 --- a/src/hardware/rigol-ds/protocol.h +++ b/src/hardware/rigol-ds/protocol.h @@ -129,6 +129,7 @@ struct dev_context { gboolean digital_channels[MAX_DIGITAL_CHANNELS]; gboolean la_enabled; float timebase; + float sample_rate; float attenuation[MAX_ANALOG_CHANNELS]; float vdiv[MAX_ANALOG_CHANNELS]; int vert_reference[MAX_ANALOG_CHANNELS];