From: Ralf Date: Fri, 23 Oct 2020 17:49:29 +0000 (+0200) Subject: rigol-dg: Read back parameters for MSO5000 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cee4b066c064e834beec423c826c632f58019f49;p=libsigrok.git rigol-dg: Read back parameters for MSO5000 --- diff --git a/src/hardware/rigol-dg/api.c b/src/hardware/rigol-dg/api.c index f57246fc..f9a90e68 100644 --- a/src/hardware/rigol-dg/api.c +++ b/src/hardware/rigol-dg/api.c @@ -268,8 +268,9 @@ static const struct scpi_command cmdset_mso5000[] = { { PSG_CMD_GET_ENABLED, "SOUR%s:OUTPUT:STATE?", }, { PSG_CMD_SET_ENABLE, "SOUR%s:OUTPUT:STATE ON", }, { PSG_CMD_SET_DISABLE, "SOUR%s:OUTPUT:STATE OFF", }, - { PSG_CMD_GET_SOURCE, "SOUR%s:FUNC?", }, - { PSG_CMD_SET_SOURCE, "SOUR%s:FUNC %s", }, + { PSG_CMD_SET_SOURCE, "SOUR%s:FUNC %s", }, /* Hack to avoid if in set pattern */ + { PSG_CMD_GET_SOURCE_NO_PARAM, "SOUR%s:FUNC?", }, + { PSG_CMD_SET_SOURCE_NO_PARAM, "SOUR%s:FUNC %s", }, { PSG_CMD_GET_FREQUENCY, "SOUR%s:FREQ?", }, { PSG_CMD_SET_FREQUENCY, "SOUR%s:FREQ %f", }, { PSG_CMD_GET_AMPLITUDE, "SOUR%s:VOLT?", }, diff --git a/src/hardware/rigol-dg/protocol.c b/src/hardware/rigol-dg/protocol.c index 5e19b57d..99f8baba 100644 --- a/src/hardware/rigol-dg/protocol.c +++ b/src/hardware/rigol-dg/protocol.c @@ -56,6 +56,46 @@ SR_PRIV const struct waveform_spec *rigol_dg_get_waveform_spec( return spec; } +SR_PRIV int rigol_dg_get_double_param(const struct sr_dev_inst *sdi, + const struct sr_channel_group *cg, int psg_cmd, double *value) +{ + struct dev_context *devc; + struct sr_scpi_dev_inst *scpi; + const char *command; + GVariant *data; + gchar *response, **params; + const gchar *s; + int ret; + + devc = sdi->priv; + scpi = sdi->conn; + data = NULL; + params = NULL; + response = NULL; + ret = SR_ERR_NA; + + command = sr_scpi_cmd_get(devc->cmdset, psg_cmd); + if (command && *command) { + sr_scpi_get_opc(scpi); + ret = sr_scpi_cmd_resp(sdi, devc->cmdset, + PSG_CMD_SELECT_CHANNEL, cg->name, &data, + G_VARIANT_TYPE_STRING, psg_cmd, cg->name); + if (ret == SR_OK) { + response = g_variant_dup_string(data, NULL); + g_strstrip(response); + s = sr_scpi_unquote_string(response); + sr_spew("Double value is: '%s'", s); + + *value = g_ascii_strtod(s, NULL); + } + } + + g_variant_unref(data); + g_free(response); + g_strfreev(params); + return ret; +} + SR_PRIV int rigol_dg_get_channel_state(const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -84,6 +124,34 @@ SR_PRIV int rigol_dg_get_channel_state(const struct sr_dev_inst *sdi, ch = cg->channels->data; ch_status = &devc->ch_status[ch->index]; + command = sr_scpi_cmd_get(devc->cmdset, PSG_CMD_GET_SOURCE_NO_PARAM); + if (command && *command) { + sr_scpi_get_opc(scpi); + ret = sr_scpi_cmd_resp(sdi, devc->cmdset, + PSG_CMD_SELECT_CHANNEL, cg->name, &data, + G_VARIANT_TYPE_STRING, PSG_CMD_GET_SOURCE_NO_PARAM, cg->name); + if (ret != SR_OK) + goto done; + response = g_variant_dup_string(data, NULL); + g_strstrip(response); + s = sr_scpi_unquote_string(response); + sr_spew("Channel state: '%s'", s); + + if ((ret = rigol_dg_string_to_waveform( + &devc->device->channels[ch->index], s, &wf)) != SR_OK) + goto done; + + ch_status->wf = wf; + ch_status->wf_spec = rigol_dg_get_waveform_spec( + &devc->device->channels[ch->index], wf); + + /* Ignore errors on read, keep default value */ + rigol_dg_get_double_param(sdi, cg, PSG_CMD_GET_FREQUENCY, &ch_status->freq); + rigol_dg_get_double_param(sdi, cg, PSG_CMD_GET_AMPLITUDE, &ch_status->ampl); + rigol_dg_get_double_param(sdi, cg, PSG_CMD_GET_OFFSET, &ch_status->offset); + rigol_dg_get_double_param(sdi, cg, PSG_CMD_GET_PHASE, &ch_status->phase); + } + command = sr_scpi_cmd_get(devc->cmdset, PSG_CMD_GET_SOURCE); if (command && *command) { sr_scpi_get_opc(scpi); diff --git a/src/hardware/rigol-dg/protocol.h b/src/hardware/rigol-dg/protocol.h index b4e25ae5..02e1acdc 100644 --- a/src/hardware/rigol-dg/protocol.h +++ b/src/hardware/rigol-dg/protocol.h @@ -43,6 +43,8 @@ enum psg_commands { PSG_CMD_SET_DISABLE, PSG_CMD_GET_SOURCE, PSG_CMD_SET_SOURCE, + PSG_CMD_GET_SOURCE_NO_PARAM, + PSG_CMD_SET_SOURCE_NO_PARAM, PSG_CMD_SET_FREQUENCY, PSG_CMD_GET_FREQUENCY, PSG_CMD_SET_AMPLITUDE, @@ -137,6 +139,8 @@ SR_PRIV int rigol_dg_string_to_waveform( const struct channel_spec *ch, const char *s, enum waveform_type *wf); SR_PRIV const struct waveform_spec *rigol_dg_get_waveform_spec( const struct channel_spec *ch, enum waveform_type wf); +SR_PRIV int rigol_dg_get_double_param(const struct sr_dev_inst *sdi, + const struct sr_channel_group *cg, int psg_cmd, double *value); SR_PRIV int rigol_dg_get_channel_state(const struct sr_dev_inst *sdi, const struct sr_channel_group *cg); SR_PRIV int rigol_dg_receive_data(int fd, int revents, void *cb_data);