]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds1xx2/api.c
mic-985xx: Use sr_dev_inst to store connection handle.
[libsigrok.git] / hardware / rigol-ds1xx2 / api.c
index 5e4198ce16483ac1fd7ac026dd03c19df5693113..53c4fb313ae2fc36b78542080224e0576e38c7bf 100644 (file)
@@ -186,7 +186,7 @@ static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
        /* When setting a bunch of parameters in a row, the DS1052E scrambles
         * some of them unless there is at least 100ms delay in between. */
        sr_spew("delay %dms", 100);
-       g_usleep(100);
+       g_usleep(100000);
 
        return SR_OK;
 }
@@ -243,7 +243,7 @@ static GSList *hw_scan(GSList *options)
                close(fd);
                if (len == 0) {
                        g_free(device);
-                       return NULL;
+                       continue;
                }
 
                buf[len] = 0;
@@ -256,7 +256,7 @@ static GSList *hw_scan(GSList *options)
                if (num_tokens < 4) {
                        g_strfreev(tokens);
                        g_free(device);
-                       return NULL;
+                       continue;
                }
 
                manufacturer = tokens[0];
@@ -266,7 +266,7 @@ static GSList *hw_scan(GSList *options)
                if (strcmp(manufacturer, "Rigol Technologies")) {
                        g_strfreev(tokens);
                        g_free(device);
-                       return NULL;
+                       continue;
                }
 
                for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
@@ -281,7 +281,7 @@ static GSList *hw_scan(GSList *options)
                        manufacturer, model, version))) {
                        g_strfreev(tokens);
                        g_free(device);
-                       return NULL;
+                       continue;
                }
 
                g_strfreev(tokens);
@@ -289,40 +289,46 @@ static GSList *hw_scan(GSList *options)
                if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
                        sr_err("Device context malloc failed.");
                        g_free(device);
-                       return NULL;
+                       goto hw_scan_abort;
                }
+
                devc->limit_frames = 0;
                devc->device = device;
                devc->has_digital = has_digital;
                sdi->priv = devc;
                sdi->driver = di;
+               drvc->instances = g_slist_append(drvc->instances, sdi);
+               devices = g_slist_append(devices, sdi);
 
                for (i = 0; i < 2; i++) {
                        if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
-                           i == 0 ? "CH1" : "CH2")))
-                               return NULL;
+                                   i == 0 ? "CH1" : "CH2")))
+                               goto hw_scan_abort;
                        sdi->probes = g_slist_append(sdi->probes, probe);
                }
 
                if (devc->has_digital) {
                        for (i = 0; i < 16; i++) {
                                if (!(channel_name = g_strdup_printf("D%d", i)))
-                                       return NULL;
+                                       goto hw_scan_abort;
                                probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name);
                                g_free(channel_name);
                                if (!probe)
-                                       return NULL;
+                                       goto hw_scan_abort;
                                sdi->probes = g_slist_append(sdi->probes, probe);
                        }
                }
-
-               drvc->instances = g_slist_append(drvc->instances, sdi);
-               devices = g_slist_append(devices, sdi);
        }
 
        g_dir_close(dir);
 
        return devices;
+
+hw_scan_abort:
+       g_dir_close(dir);
+       g_slist_free(devices);
+       clear_instances();
+       return NULL;
 }
 
 static GSList *hw_dev_list(void)
@@ -379,7 +385,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
                *data = g_variant_new_int32(NUM_VDIV);
                break;
        default:
-               return SR_ERR_ARG;
+               return SR_ERR_NA;
        }
 
        return SR_OK;
@@ -488,8 +494,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
                        ret = SR_ERR_ARG;
                break;
        default:
-               sr_err("Unknown hardware capability: %d.", id);
-               ret = SR_ERR_ARG;
+               ret = SR_ERR_NA;
                break;
        }
 
@@ -501,7 +506,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
        GVariant *tuple, *rational[2];
        GVariantBuilder gvb;
        unsigned int i;
-       struct dev_context *devc = sdi->priv;
+       struct dev_context *devc;
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
@@ -532,11 +537,15 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
                *data = g_variant_builder_end(&gvb);
                break;
        case SR_CONF_TRIGGER_SOURCE:
+               if (!sdi || !sdi->priv)
+                       /* Can't know this until we have the exact model. */
+                       return SR_ERR_ARG;
+               devc = sdi->priv;
                *data = g_variant_new_strv(trigger_sources,
                                devc->has_digital ? ARRAY_SIZE(trigger_sources) : 4);
                break;
        default:
-               return SR_ERR_ARG;
+               return SR_ERR_NA;
        }
 
        return SR_OK;