/* 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_channel *ch; int tmp; if (!(devc = sdi->priv)) return SR_ERR; ch = devc->channel_entry->data; if (devc->model->series->protocol != PROTOCOL_V3) return SR_OK; if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", ch->index + 1) != SR_OK) return SR_ERR; /* Check that the number of samples will be accepted */ 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; /* * 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(500 * 1000); rigol_ds_config_set(sdi, ":SING"); rigol_ds_set_wait_event(devc, WAIT_STOP); return SR_ERR; } return SR_OK; }
/* Start reading data from the current channel */ SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_channel *ch; if (!(devc = sdi->priv)) return SR_ERR; ch = devc->channel_entry->data; sr_dbg("Starting reading data from channel %d", ch->index + 1); switch (devc->model->series->protocol) { case PROTOCOL_V1: case PROTOCOL_V2: if (ch->type == SR_CHANNEL_LOGIC) { if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK) return SR_ERR; } else { if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d", ch->index + 1) != SR_OK) return SR_ERR; } rigol_ds_set_wait_event(devc, WAIT_NONE); break; case PROTOCOL_V3: if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", ch->index + 1) != SR_OK) return SR_ERR; if (devc->data_source != DATA_SOURCE_LIVE) { if (rigol_ds_config_set(sdi, ":WAV:RES") != SR_OK) return SR_ERR; if (rigol_ds_config_set(sdi, ":WAV:BEG") != SR_OK) return SR_ERR; } break; case PROTOCOL_V4: if (ch->type == SR_CHANNEL_ANALOG) { if (rigol_ds_config_set(sdi, ":WAV:SOUR CHAN%d", ch->index + 1) != SR_OK) return SR_ERR; } else { if (rigol_ds_config_set(sdi, ":WAV:SOUR D%d", ch->index) != SR_OK) return SR_ERR; } if (rigol_ds_config_set(sdi, devc->data_source == DATA_SOURCE_LIVE ? ":WAV:MODE NORM" :":WAV:MODE RAW") != SR_OK) return SR_ERR; break; } if (devc->model->series->protocol >= PROTOCOL_V3 && ch->type == SR_CHANNEL_ANALOG) { /* Vertical reference. */ if (sr_scpi_get_int(sdi->conn, ":WAV:YREF?", &devc->vert_reference[ch->index]) != SR_OK) return SR_ERR; } rigol_ds_set_wait_event(devc, WAIT_BLOCK); devc->num_channel_bytes = 0; devc->num_header_bytes = 0; devc->num_block_bytes = 0; return SR_OK; }
SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi) { struct dev_context *devc; struct scope_state *state; const struct scope_config *config; int tmp; unsigned int i; float tmp_float; gboolean channel_found; char tmp_str[MAX_COMMAND_SIZE]; char chan_name[20]; devc = sdi->priv; config = devc->model_config; state = devc->model_state; channel_found = FALSE; for (i = 0; i < config->analog_channels; ++i) { if (state->analog_channels[i].state) { g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1); g_snprintf(tmp_str, sizeof(tmp_str), (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], chan_name); channel_found = TRUE; break; } } if (!channel_found) { for (i = 0; i < config->digital_pods; i++) { if (state->digital_pods[i]) { g_snprintf(chan_name, sizeof(chan_name), "POD%d", i); g_snprintf(tmp_str, sizeof(tmp_str), (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE], chan_name); channel_found = TRUE; break; } } } /* No channel is active, ask the instrument for the sample rate * in single shot mode */ if (!channel_found) { if (sr_scpi_get_float(sdi->conn, (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE], &tmp_float) != SR_OK) return SR_ERR; state->sample_rate = tmp_float; } else { if (sr_scpi_get_int(sdi->conn, tmp_str, &tmp) != SR_OK) return SR_ERR; state->sample_rate = tmp / (((float) (*config->timebases)[state->timebase][0] / (*config->timebases)[state->timebase][1]) * config->num_xdivs); } return SR_OK; }