The hameg-hmo driver returns an incorrect sample rate: to
reproduce this bug, set the maximum sample rate from the
ACQUIRE menu.

This patch fixes the driver so that the correct sample rate
is returned.

Signed-off-by: Guido Trentalancia <gu...@trentalancia.com>
---
 src/hardware/hameg-hmo/protocol.c |   51 +++-----------------------------------
 src/scpi.h                        |    1 
 2 files changed, 5 insertions(+), 47 deletions(-)

diff -pru libsigrok-git-orig/src/hardware/hameg-hmo/protocol.c 
libsigrok-git-hameg-hmo-fix-sample-rate-reading/src/hardware/hameg-hmo/protocol.c
--- libsigrok-git-orig/src/hardware/hameg-hmo/protocol.c        2018-11-16 
21:58:04.552966155 +0100
+++ 
libsigrok-git-hameg-hmo-fix-sample-rate-reading/src/hardware/hameg-hmo/protocol.c
   2018-11-18 01:13:47.022542226 +0100
@@ -37,7 +37,6 @@ static const char *hameg_scpi_dialect[]
        [SCPI_CMD_GET_COUPLING]               = ":CHAN%d:COUP?",
        [SCPI_CMD_SET_COUPLING]               = ":CHAN%d:COUP %s",
        [SCPI_CMD_GET_SAMPLE_RATE]            = ":ACQ:SRAT?",
-       [SCPI_CMD_GET_SAMPLE_RATE_LIVE]       = ":%s:DATA:POINTS?",
        [SCPI_CMD_GET_ANALOG_DATA]            = ":FORM:BORD %s;" \
                                                ":FORM REAL,32;:CHAN%d:DATA?",
        [SCPI_CMD_GET_VERTICAL_DIV]           = ":CHAN%d:SCAL?",
@@ -665,58 +664,18 @@ SR_PRIV int hmo_update_sample_rate(const
        struct dev_context *devc;
        struct scope_state *state;
        const struct scope_config *config;
-       int tmp;
-       unsigned int i;
        float tmp_float;
-       gboolean channel_found;
-       char tmp_str[MAX_COMMAND_SIZE];
-       char chan_name[20];
 
        devc = sdi->priv;
        config = devc->model_config;
        state = devc->model_state;
-       channel_found = FALSE;
-
-       for (i = 0; i < config->analog_channels; i++) {
-               if (!state->analog_channels[i].state)
-                       continue;
-               g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1);
-               g_snprintf(tmp_str, sizeof(tmp_str),
-                          
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
-                          chan_name);
-               channel_found = TRUE;
-               break;
-       }
 
-       if (!channel_found) {
-               for (i = 0; i < config->digital_pods; i++) {
-                       if (!state->digital_pods[i].state)
-                               continue;
-                       g_snprintf(chan_name, sizeof(chan_name), "POD%d", i);
-                       g_snprintf(tmp_str, sizeof(tmp_str),
-                                  
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
-                                  chan_name);
-                       channel_found = TRUE;
-                       break;
-               }
-       }
-
-       /* No channel is active, ask the instrument for the sample rate
-        * in single shot mode */
-       if (!channel_found) {
-               if (sr_scpi_get_float(sdi->conn,
-                                     
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
-                                     &tmp_float) != SR_OK)
-                       return SR_ERR;
+       if (sr_scpi_get_float(sdi->conn,
+                             (*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE],
+                             &tmp_float) != SR_OK)
+               return SR_ERR;
 
-               state->sample_rate = tmp_float;
-       } else {
-               if (sr_scpi_get_int(sdi->conn, tmp_str, &tmp) != SR_OK)
-                       return SR_ERR;
-               state->sample_rate = tmp / (((float) 
(*config->timebases)[state->timebase][0] /
-                                            
(*config->timebases)[state->timebase][1]) *
-                                           config->num_xdivs);
-       }
+       state->sample_rate = tmp_float;
 
        return SR_OK;
 }
diff -pru libsigrok-git-orig/src/scpi.h 
libsigrok-git-hameg-hmo-fix-sample-rate-reading/src/scpi.h
--- libsigrok-git-orig/src/scpi.h       2018-11-15 17:16:49.628199054 +0100
+++ libsigrok-git-hameg-hmo-fix-sample-rate-reading/src/scpi.h  2018-11-18 
01:14:25.481540855 +0100
@@ -57,7 +57,6 @@ enum {
        SCPI_CMD_GET_ANALOG_DATA,
        SCPI_CMD_GET_DIG_DATA,
        SCPI_CMD_GET_SAMPLE_RATE,
-       SCPI_CMD_GET_SAMPLE_RATE_LIVE,
        SCPI_CMD_GET_PROBE_UNIT,
        SCPI_CMD_GET_DIG_POD_THRESHOLD,
        SCPI_CMD_SET_DIG_POD_THRESHOLD,


_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to