+/* Wait for enough data becoming available in scope output buffer */
+static int rigol_ds_block_wait(const struct sr_dev_inst *sdi)
+{
+ char buf[30];
+ struct dev_context *devc;
+ time_t start;
+ int len;
+
+ if (!(devc = sdi->priv))
+ return SR_ERR;
+
+ start = time(NULL);
+
+ do {
+ if (time(NULL) - start >= 3) {
+ sr_dbg("Timeout waiting for data block");
+ return SR_ERR_TIMEOUT;
+ }
+
+ /*
+ * 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 (get_cfg(sdi, ":WAV:STAT?", buf, sizeof(buf)) != SR_OK)
+ return SR_ERR;
+
+ if (parse_int(buf + 5, &len) != SR_OK)
+ return SR_ERR;
+ } while (buf[0] == 'R' && len < 1000000);
+
+ rigol_ds_set_wait_event(devc, WAIT_NONE);
+
+ return SR_OK;
+}
+
+/* Start capturing a new frameset */
+SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+
+ 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;
+ rigol_ds_set_wait_event(devc, WAIT_TRIGGER);