Пример #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;
	char *tmp_str;

	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;

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

	if (array_float_get(tmp_str, hmo_timebases, ARRAY_SIZE(hmo_timebases),
			&i) != SR_OK) {
		g_free(tmp_str);
		sr_err("Could not determine array index for time base.");
		return SR_ERR;
	}
	g_free(tmp_str);

	state->timebase = i;

	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;
}
Пример #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;
}
Пример #3
0
static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
				    const struct scope_config *config,
				    struct scope_state *state)
{
	unsigned int i, j;
	char command[MAX_COMMAND_SIZE];
	char *tmp_str;

	for (i = 0; i < config->analog_channels; i++) {
		g_snprintf(command, sizeof(command),
			   (*config->scpi_dialect)[SCPI_CMD_GET_ANALOG_CHAN_STATE],
			   i + 1);

		if (sr_scpi_get_bool(scpi, command,
				     &state->analog_channels[i].state) != SR_OK)
			return SR_ERR;

		g_snprintf(command, sizeof(command),
			   (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_DIV],
			   i + 1);

		if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
			return SR_ERR;

		if (array_float_get(tmp_str, hmo_vdivs, ARRAY_SIZE(hmo_vdivs),
				&j) != SR_OK) {
			g_free(tmp_str);
			sr_err("Could not determine array index for vertical div scale.");
			return SR_ERR;
		}

		g_free(tmp_str);
		state->analog_channels[i].vdiv = j;

		g_snprintf(command, sizeof(command),
			   (*config->scpi_dialect)[SCPI_CMD_GET_VERTICAL_OFFSET],
			   i + 1);

		if (sr_scpi_get_float(scpi, command,
				     &state->analog_channels[i].vertical_offset) != SR_OK)
			return SR_ERR;

		g_snprintf(command, sizeof(command),
			   (*config->scpi_dialect)[SCPI_CMD_GET_COUPLING],
			   i + 1);

		if (scope_state_get_array_option(scpi, command, config->coupling_options,
					 &state->analog_channels[i].coupling) != SR_OK)
			return SR_ERR;

		g_snprintf(command, sizeof(command),
			   (*config->scpi_dialect)[SCPI_CMD_GET_PROBE_UNIT],
			   i + 1);

		if (sr_scpi_get_string(scpi, command, &tmp_str) != SR_OK)
			return SR_ERR;

		if (tmp_str[0] == 'A')
			state->analog_channels[i].probe_unit = 'A';
		else
			state->analog_channels[i].probe_unit = 'V';
		g_free(tmp_str);
	}

	return SR_OK;
}
Пример #4
0
/**
 * Obtains information about all analog channels from the oscilloscope.
 * The internal state information is updated accordingly.
 *
 * @param sdi The device instance.
 * @param config The device's device configuration.
 * @param state The device's state information.
 *
 * @return SR_ERR on error, SR_OK otherwise.
 */
static int analog_channel_state_get(const struct sr_dev_inst *sdi,
		const struct scope_config *config,
		struct scope_state *state)
{
	struct sr_scpi_dev_inst *scpi;
	int i, j;
	GSList *l;
	struct sr_channel *ch;
	gchar *response;

	scpi = sdi->conn;

	for (i = 0; i < config->analog_channels; i++) {

		if (dlm_analog_chan_state_get(scpi, i + 1,
				&state->analog_states[i].state) != SR_OK)
			return SR_ERR;

		for (l = sdi->channels; l; l = l->next) {
			ch = l->data;
			if (ch->index == i) {
				ch->enabled = state->analog_states[i].state;
				break;
			}
		}

		if (dlm_analog_chan_vdiv_get(scpi, i + 1, &response) != SR_OK)
			return SR_ERR;

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

		g_free(response);
		state->analog_states[i].vdiv = j;

		if (dlm_analog_chan_voffs_get(scpi, i + 1,
				&state->analog_states[i].vertical_offset) != SR_OK)
			return SR_ERR;

		if (dlm_analog_chan_wrange_get(scpi, i + 1,
				&state->analog_states[i].waveform_range) != SR_OK)
			return SR_ERR;

		if (dlm_analog_chan_woffs_get(scpi, i + 1,
				&state->analog_states[i].waveform_offset) != SR_OK)
			return SR_ERR;

		if (dlm_analog_chan_coupl_get(scpi, i + 1, &response) != SR_OK) {
			g_free(response);
			return SR_ERR;
		}

		if (array_option_get(response, config->coupling_options,
				&state->analog_states[i].coupling) != SR_OK) {
			g_free(response);
			return SR_ERR;
		}
		g_free(response);
	}

	return SR_OK;
}