+ }
+
+ buf[len] = 0;
+ tokens = g_strsplit(buf, delimiter, 0);
+ close(fd);
+ sr_dbg("response: %s %d [%s]", device, len, buf);
+
+ for (num_tokens = 0; tokens[num_tokens] != NULL; num_tokens++);
+
+ if (num_tokens < 4) {
+ g_strfreev(tokens);
+ g_free(device);
+ return NULL;
+ }
+
+ manufacturer = tokens[0];
+ model = tokens[1];
+ version = tokens[3];
+
+ if (strcmp(manufacturer, "Rigol Technologies")) {
+ g_strfreev(tokens);
+ g_free(device);
+ return NULL;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
+ if (!strcmp(model, supported_models[i])) {
+ matched = 1;
+ has_digital = g_str_has_suffix(model, "D");
+ break;
+ }
+ }
+
+ if (!matched || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
+ manufacturer, model, version))) {
+ g_strfreev(tokens);
+ g_free(device);
+ return NULL;
+ }
+
+ g_strfreev(tokens);
+
+ if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
+ sr_err("Device context malloc failed.");
+ g_free(device);
+ return NULL;
+ }
+ devc->limit_frames = 0;
+ devc->device = device;
+ devc->has_digital = has_digital;
+ sdi->priv = devc;
+ sdi->driver = di;
+
+ for (i = 0; i < 2; i++) {
+ if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
+ i == 0 ? "CH1" : "CH2")))
+ return NULL;
+ 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;
+ probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name);
+ g_free(channel_name);
+ if (!probe)
+ return NULL;
+ sdi->probes = g_slist_append(sdi->probes, probe);
+ }
+ }
+
+ drvc->instances = g_slist_append(drvc->instances, sdi);
+ devices = g_slist_append(devices, sdi);