From: Alexandru Gagniuc Date: Thu, 30 Apr 2015 00:26:47 +0000 (-0700) Subject: scpi-pps: Add infrastructure for controlling output frequency X-Git-Tag: libsigrok-0.4.0~510 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=4264f1c03b3cd0e7d2634e207c79b1973789af28;p=libsigrok.git scpi-pps: Add infrastructure for controlling output frequency This patch only adds the needed infrastructure to control output frequency in the same manner as output voltage or current limit. This does require a new field in the channel_spec struct, for the sake of symmetry. --- diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index e68836b7..c1b4aca4 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -38,6 +38,7 @@ static const struct pps_channel_instance pci[] = { { SR_MQ_VOLTAGE, SCPI_CMD_GET_MEAS_VOLTAGE, "V" }, { SR_MQ_CURRENT, SCPI_CMD_GET_MEAS_CURRENT, "I" }, { SR_MQ_POWER, SCPI_CMD_GET_MEAS_POWER, "P" }, + { SR_MQ_FREQUENCY, SCPI_CMD_GET_MEAS_FREQUENCY, "F" }, }; static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) @@ -300,6 +301,14 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_VOLTAGE_TARGET; break; + case SR_CONF_OUTPUT_FREQUENCY: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_MEAS_FREQUENCY; + break; + case SR_CONF_OUTPUT_FREQUENCY_TARGET: + gvtype = G_VARIANT_TYPE_DOUBLE; + cmd = SCPI_CMD_GET_FREQUENCY_TARGET; + break; case SR_CONF_OUTPUT_CURRENT: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_MEAS_CURRENT; @@ -378,6 +387,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd d = g_variant_get_double(data); ret = scpi_cmd(sdi, SCPI_CMD_SET_VOLTAGE_TARGET, d); break; + case SR_CONF_OUTPUT_FREQUENCY_TARGET: + d = g_variant_get_double(data); + ret = scpi_cmd(sdi, SCPI_CMD_SET_FREQUENCY_TARGET, d); + break; case SR_CONF_OUTPUT_CURRENT_LIMIT: d = g_variant_get_double(data); ret = scpi_cmd(sdi, SCPI_CMD_SET_CURRENT_LIMIT, d); @@ -497,6 +510,16 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } *data = g_variant_builder_end(&gvb); break; + case SR_CONF_OUTPUT_FREQUENCY_TARGET: + ch_spec = &(devc->device->channels[ch->index]); + g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); + /* Min, max, write resolution. */ + for (i = 0; i < 3; i++) { + gvar = g_variant_new_double(ch_spec->frequency[i]); + g_variant_builder_add_value(&gvb, gvar); + } + *data = g_variant_builder_end(&gvb); + break; case SR_CONF_OUTPUT_CURRENT_LIMIT: g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); /* Min, max, step. */ @@ -543,6 +566,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, return ret; if (pch->mq == SR_MQ_VOLTAGE) cmd = SCPI_CMD_GET_MEAS_VOLTAGE; + else if (pch->mq == SR_MQ_FREQUENCY) + cmd = SCPI_CMD_GET_MEAS_FREQUENCY; else if (pch->mq == SR_MQ_CURRENT) cmd = SCPI_CMD_GET_MEAS_CURRENT; else if (pch->mq == SR_MQ_POWER) diff --git a/src/hardware/scpi-pps/profiles.c b/src/hardware/scpi-pps/profiles.c index 489f5bdb..7d1da16e 100644 --- a/src/hardware/scpi-pps/profiles.c +++ b/src/hardware/scpi-pps/profiles.c @@ -24,6 +24,7 @@ #include "protocol.h" #define CH_IDX(x) (1 << x) +#define FREQ_DC_ONLY {0, 0, 0} const char *pps_vendors[][2] = { { "RIGOL TECHNOLOGIES", "Rigol" }, @@ -61,7 +62,7 @@ static const uint32_t chroma_61604_devopts_cg[] = { }; const struct channel_spec chroma_61604_ch[] = { - { "1", { 0, 300, 0.1 }, { 0, 16, 0.1 } }, + { "1", { 0, 300, 0.1 }, { 0, 16, 0.1 }, FREQ_DC_ONLY }, }; const struct channel_group_spec chroma_61604_cg[] = { @@ -108,20 +109,20 @@ static const uint32_t rigol_dp800_devopts_cg[] = { }; const struct channel_spec rigol_dp821a_ch[] = { - { "1", { 0, 60, 0.001 }, { 0, 1, 0.0001 } }, - { "2", { 0, 8, 0.001 }, { 0, 10, 0.001 } }, + { "1", { 0, 60, 0.001 }, { 0, 1, 0.0001 }, FREQ_DC_ONLY }, + { "2", { 0, 8, 0.001 }, { 0, 10, 0.001 }, FREQ_DC_ONLY }, }; const struct channel_spec rigol_dp831_ch[] = { - { "1", { 0, 8, 0.001 }, { 0, 5, 0.0003 } }, - { "2", { 0, 30, 0.001 }, { 0, 2, 0.0001 } }, - { "3", { 0, -30, 0.001 }, { 0, 2, 0.0001 } }, + { "1", { 0, 8, 0.001 }, { 0, 5, 0.0003 }, FREQ_DC_ONLY }, + { "2", { 0, 30, 0.001 }, { 0, 2, 0.0001 }, FREQ_DC_ONLY }, + { "3", { 0, -30, 0.001 }, { 0, 2, 0.0001 }, FREQ_DC_ONLY }, }; const struct channel_spec rigol_dp832_ch[] = { - { "1", { 0, 30, 0.001 }, { 0, 3, 0.001 } }, - { "2", { 0, 30, 0.001 }, { 0, 3, 0.001 } }, - { "3", { 0, 5, 0.001 }, { 0, 3, 0.001 } }, + { "1", { 0, 30, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY }, + { "2", { 0, 30, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY }, + { "3", { 0, 5, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY }, }; const struct channel_group_spec rigol_dp820_cg[] = { @@ -181,7 +182,7 @@ static const uint32_t hp_6632b_devopts[] = { }; const struct channel_spec hp_6632b_ch[] = { - { "1", { 0, 20.475, 0.005 }, { 0, 5.1188, 0.00132 } }, + { "1", { 0, 20.475, 0.005 }, { 0, 5.1188, 0.00132 }, FREQ_DC_ONLY }, }; const struct channel_group_spec hp_6632b_cg[] = { diff --git a/src/hardware/scpi-pps/protocol.c b/src/hardware/scpi-pps/protocol.c index df7d478d..26ff8216 100644 --- a/src/hardware/scpi-pps/protocol.c +++ b/src/hardware/scpi-pps/protocol.c @@ -227,6 +227,8 @@ SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data) pch = devc->cur_channel->priv; if (pch->mq == SR_MQ_VOLTAGE) cmd = SCPI_CMD_GET_MEAS_VOLTAGE; + else if (pch->mq == SR_MQ_FREQUENCY) + cmd = SCPI_CMD_GET_MEAS_FREQUENCY; else if (pch->mq == SR_MQ_CURRENT) cmd = SCPI_CMD_GET_MEAS_CURRENT; else if (pch->mq == SR_MQ_POWER) diff --git a/src/hardware/scpi-pps/protocol.h b/src/hardware/scpi-pps/protocol.h index bd0dc933..e1ed8cb8 100644 --- a/src/hardware/scpi-pps/protocol.h +++ b/src/hardware/scpi-pps/protocol.h @@ -37,8 +37,11 @@ enum pps_scpi_cmds { SCPI_CMD_GET_MEAS_VOLTAGE, SCPI_CMD_GET_MEAS_CURRENT, SCPI_CMD_GET_MEAS_POWER, + SCPI_CMD_GET_MEAS_FREQUENCY, SCPI_CMD_GET_VOLTAGE_TARGET, SCPI_CMD_SET_VOLTAGE_TARGET, + SCPI_CMD_GET_FREQUENCY_TARGET, + SCPI_CMD_SET_FREQUENCY_TARGET, SCPI_CMD_GET_CURRENT_LIMIT, SCPI_CMD_SET_CURRENT_LIMIT, SCPI_CMD_GET_OUTPUT_ENABLED, @@ -100,6 +103,7 @@ struct channel_spec { /* Min, max, programming resolution. */ float voltage[3]; float current[3]; + float frequency[3]; }; struct scpi_command {