]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hameg-hmo/api.c
hameg-hmo: Avoid bogus SCPI timeouts.
[libsigrok.git] / src / hardware / hameg-hmo / api.c
index 0070b61569800e3132bbc8ae4e816eb1dac13696..71d3a986797b81a97ad6e490930c27c590de2d61 100644 (file)
@@ -200,6 +200,9 @@ static int config_get(uint32_t key, GVariant **data,
        case SR_CONF_TRIGGER_SLOPE:
                *data = g_variant_new_string((*model->trigger_slopes)[state->trigger_slope]);
                break;
+       case SR_CONF_TRIGGER_PATTERN:
+               *data = g_variant_new_string(state->trigger_pattern);
+               break;
        case SR_CONF_HORIZ_TRIGGERPOS:
                *data = g_variant_new_double(state->horiz_triggerpos);
                break;
@@ -250,7 +253,7 @@ static int config_set(uint32_t key, GVariant *data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
        int ret, cg_type, idx, j;
-       char command[MAX_COMMAND_SIZE], float_str[30];
+       char command[MAX_COMMAND_SIZE], float_str[30], *tmp_str;
        struct dev_context *devc;
        const struct scope_config *model;
        struct scope_state *state;
@@ -285,7 +288,10 @@ static int config_set(uint32_t key, GVariant *data,
                g_snprintf(command, sizeof(command),
                           (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
                           (*model->trigger_sources)[idx]);
-               ret = sr_scpi_send(sdi->conn, command);
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               ret = SR_OK;
                break;
        case SR_CONF_VDIV:
                if (!cg)
@@ -314,7 +320,10 @@ static int config_set(uint32_t key, GVariant *data,
                g_snprintf(command, sizeof(command),
                           (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
                           float_str);
-               ret = sr_scpi_send(sdi->conn, command);
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               ret = SR_OK;
                update_sample_rate = TRUE;
                break;
        case SR_CONF_HORIZ_TRIGGERPOS:
@@ -330,7 +339,10 @@ static int config_set(uint32_t key, GVariant *data,
                g_snprintf(command, sizeof(command),
                           (*model->scpi_dialect)[SCPI_CMD_SET_HORIZ_TRIGGERPOS],
                           float_str);
-               ret = sr_scpi_send(sdi->conn, command);
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               ret = SR_OK;
                break;
        case SR_CONF_TRIGGER_SLOPE:
                if ((idx = std_str_idx(data, *model->trigger_slopes, model->num_trigger_slopes)) < 0)
@@ -339,7 +351,25 @@ static int config_set(uint32_t key, GVariant *data,
                g_snprintf(command, sizeof(command),
                           (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
                           (*model->trigger_slopes)[idx]);
-               ret = sr_scpi_send(sdi->conn, command);
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               ret = SR_OK;
+               break;
+       case SR_CONF_TRIGGER_PATTERN:
+               tmp_str = (char *)g_variant_get_string(data, 0);
+               idx = strlen(tmp_str);
+               if (idx == 0 || idx > model->analog_channels + model->digital_channels)
+                       return SR_ERR_ARG;
+               g_snprintf(command, sizeof(command),
+                          (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_PATTERN],
+                          tmp_str);
+               if (sr_scpi_send(sdi->conn, command) != SR_OK ||
+                   sr_scpi_get_opc(sdi->conn) != SR_OK)
+                       return SR_ERR;
+               g_free(state->trigger_pattern);
+               state->trigger_pattern = g_strdup(tmp_str);
+               ret = SR_OK;
                break;
        case SR_CONF_COUPLING:
                if (!cg)
@@ -410,9 +440,6 @@ static int config_set(uint32_t key, GVariant *data,
                break;
        }
 
-       if (ret == SR_OK)
-               ret = sr_scpi_get_opc(sdi->conn);
-
        if (ret == SR_OK && update_sample_rate)
                ret = hmo_update_sample_rate(sdi);