+static int rigol_ds_trigger_wait(const struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+ long s;
+
+ if (!(devc = sdi->priv))
+ return SR_ERR;
+
+ /*
+ * If timebase < 50 msecs/DIV just sleep about one sweep time except
+ * for really fast sweeps.
+ */
+ if (devc->timebase < 0.0499)
+ {
+ if (devc->timebase > 0.99e-6) {
+ /*
+ * Timebase * num hor. divs * 85(%) * 1e6(usecs) / 100
+ * -> 85 percent of sweep time
+ */
+ s = (devc->timebase * devc->model->num_horizontal_divs
+ * 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');
+ }
+}
+
+/* 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;
+ struct sr_probe *probe;
+ int tmp;
+
+ if (!(devc = sdi->priv))
+ return SR_ERR;
+
+ probe = devc->channel_entry->data;
+
+ if (sr_scpi_send(sdi->conn, ":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)
+ return SR_ERR;
+ if (get_cfg_int(sdi, "*ESR?", &tmp) != SR_OK)
+ return SR_ERR;
+ /*
+ * 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);
+ sr_scpi_send(sdi->conn, ":SING");
+ rigol_ds_set_wait_event(devc, WAIT_STOP);
+ return SR_ERR;
+ }
+
+ return SR_OK;
+}