]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds/api.c
scpi: add a generic scan API and implement it in usbtmc and serial transport
[libsigrok.git] / hardware / rigol-ds / api.c
index 598978e3cf4ca8a68a606a3200e5b21b89c9f995..0f319cbd0902c5bce5d5c8c4eaee190ebf6a642b 100644 (file)
@@ -269,7 +269,7 @@ static int probe_port(const char *resource, const char *serialcomm, GSList **dev
 
        *devices = NULL;
 
-       if (!(scpi = scpi_dev_inst_new(resource, serialcomm)))
+       if (!(scpi = scpi_dev_inst_new(di->priv, resource, serialcomm)))
                return SR_ERR;
 
        if (sr_scpi_open(scpi) != SR_OK) {
@@ -482,10 +482,13 @@ static int dev_close(struct sr_dev_inst *sdi)
        struct sr_scpi_dev_inst *scpi;
        struct dev_context *devc;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        scpi = sdi->conn;
        devc = sdi->priv;
 
-       if (devc->model->series->protocol >= PROTOCOL_V2)
+       if (devc->model->series->protocol == PROTOCOL_V2)
                rigol_ds_config_set(sdi, ":KEY:LOCK DISABLE");
 
        if (scpi) {
@@ -515,6 +518,9 @@ static int analog_frame_size(const struct sr_dev_inst *sdi)
                        analog_probes++;
        }
 
+       if (analog_probes == 0)
+               return 0;
+
        switch (devc->data_source) {
        case DATA_SOURCE_LIVE:
                return devc->model->series->live_samples;
@@ -654,7 +660,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
                const struct sr_probe_group *probe_group)
 {
        struct dev_context *devc;
-       uint64_t tmp_u64, p, q;
+       uint64_t p, q;
        double t_dbl;
        unsigned int i, j;
        int ret;
@@ -679,11 +685,13 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
                devc->limit_frames = g_variant_get_uint64(data);
                break;
        case SR_CONF_TRIGGER_SLOPE:
-               tmp_u64 = g_variant_get_uint64(data);
-               if (tmp_u64 != 0 && tmp_u64 != 1)
-                       return SR_ERR;
+               tmp_str = g_variant_get_string(data, NULL);
+
+               if (!tmp_str || !(tmp_str[0] == 'f' || tmp_str[0] == 'r'))
+                       return SR_ERR_ARG;
+
                g_free(devc->trigger_slope);
-               devc->trigger_slope = g_strdup(tmp_u64 ? "POS" : "NEG");
+               devc->trigger_slope = g_strdup((tmp_str[0] == 'r') ? "POS" : "NEG");
                ret = rigol_ds_config_set(sdi, ":TRIG:EDGE:SLOP %s", devc->trigger_slope);
                break;
        case SR_CONF_HORIZ_TRIGGERPOS: