]> sigrok.org Git - libsigrok.git/commitdiff
rigol-dg: Read back parameters for MSO5000
authorRalf <redacted>
Fri, 23 Oct 2020 17:49:29 +0000 (19:49 +0200)
committerSoeren Apel <redacted>
Sat, 28 Sep 2024 22:00:17 +0000 (00:00 +0200)
src/hardware/rigol-dg/api.c
src/hardware/rigol-dg/protocol.c
src/hardware/rigol-dg/protocol.h

index f57246fc5ee5d0764c2c060f5dcceb5c758a800c..f9a90e6892ee0abce65b98683033be209ccfe502 100644 (file)
@@ -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?", },
index 5e19b57dc618596acd24f1509f5b5e9df412c3b7..99f8babae48e0e79ae1db092bdb7d8e4743d83a8 100644 (file)
@@ -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);
index b4e25ae5d853c6bd10cc60040e209fa1373d662a..02e1acdcf08881a6017a889c84fa3ed719258610 100644 (file)
@@ -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);