Beispiel #1
0
SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
{
	struct dev_context *devc;
	struct scope_state *state;
	const struct scope_config *config;
	float tmp_float;
	unsigned int i;

	devc = sdi->priv;
	config = devc->model_config;
	state = devc->model_state;

	sr_info("Fetching scope state");

	if (analog_channel_state_get(sdi->conn, config, state) != SR_OK)
		return SR_ERR;

	if (digital_channel_state_get(sdi->conn, config, state) != SR_OK)
		return SR_ERR;

	if (sr_scpi_get_float(sdi->conn,
			(*config->scpi_dialect)[SCPI_CMD_GET_TIMEBASE],
			&tmp_float) != SR_OK)
		return SR_ERR;

	for (i = 0; i < config->num_timebases; i++) {
		if (tmp_float == ((float) (*config->timebases)[i][0] /
				  (*config->timebases)[i][1])) {
			state->timebase = i;
			break;
		}
	}
	if (i == config->num_timebases) {
		sr_err("Could not determine array index for time base.");
		return SR_ERR;
	}

	if (sr_scpi_get_float(sdi->conn,
			(*config->scpi_dialect)[SCPI_CMD_GET_HORIZ_TRIGGERPOS],
			&tmp_float) != SR_OK)
		return SR_ERR;
	state->horiz_triggerpos = tmp_float /
		(((double) (*config->timebases)[state->timebase][0] /
		  (*config->timebases)[state->timebase][1]) * config->num_xdivs);
	state->horiz_triggerpos -= 0.5;
	state->horiz_triggerpos *= -1;

	if (scope_state_get_array_option(sdi->conn,
			(*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE],
			config->trigger_sources, &state->trigger_source) != SR_OK)
		return SR_ERR;

	if (scope_state_get_array_option(sdi->conn,
		(*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE],
		config->trigger_slopes, &state->trigger_slope) != SR_OK)
		return SR_ERR;

	if (hmo_update_sample_rate(sdi) != SR_OK)
		return SR_ERR;

	sr_info("Fetching finished.");

	scope_state_dump(config, state);

	return SR_OK;
}
Beispiel #2
0
/**
 * Obtains information about the current device state from the oscilloscope,
 * including all analog and digital channel configurations.
 * The internal state information is updated accordingly.
 *
 * @param sdi The device instance.
 *
 * @return SR_ERR on error, SR_OK otherwise.
 */
SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi)
{
	struct dev_context *devc;
	struct scope_state *state;
	const struct scope_config *config;
	float tmp_float;
	gchar *response;
	int i;

	devc = sdi->priv;
	config = devc->model_config;
	state = devc->model_state;

	if (analog_channel_state_get(sdi, config, state) != SR_OK)
		return SR_ERR;

	if (digital_channel_state_get(sdi, config, state) != SR_OK)
		return SR_ERR;

	if (dlm_timebase_get(sdi->conn, &response) != SR_OK)
		return SR_ERR;

	if (array_float_get(response, dlm_timebases,
			ARRAY_SIZE(dlm_timebases), &i) != SR_OK) {
		g_free(response);
		return SR_ERR;
	}

	g_free(response);
	state->timebase = i;

	if (dlm_horiz_trigger_pos_get(sdi->conn, &tmp_float) != SR_OK)
		return SR_ERR;

	/* TODO: Check if the calculation makes sense for the DLM. */
	state->horiz_triggerpos = tmp_float /
			(((double)dlm_timebases[state->timebase][0] /
			dlm_timebases[state->timebase][1]) * config->num_xdivs);
	state->horiz_triggerpos -= 0.5;
	state->horiz_triggerpos *= -1;

	if (dlm_trigger_source_get(sdi->conn, &response) != SR_OK) {
		g_free(response);
		return SR_ERR;
	}

	if (array_option_get(response, config->trigger_sources,
			&state->trigger_source) != SR_OK) {
		g_free(response);
		return SR_ERR;
	}

	g_free(response);

	if (dlm_trigger_slope_get(sdi->conn, &i) != SR_OK)
		return SR_ERR;

	state->trigger_slope = i;

	if (dlm_acq_length_get(sdi->conn, &state->samples_per_frame) != SR_OK) {
		sr_err("Failed to query acquisition length.");
		return SR_ERR;
	}

	dlm_sample_rate_query(sdi);

	scope_state_dump(config, state);

	return SR_OK;
}