From: Soeren Apel Date: Sun, 28 Sep 2014 12:33:03 +0000 (+0200) Subject: Removal of sdi->index, step 7: fix testo X-Git-Tag: libsigrok-0.4.0~923 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=bde9fbd1978ca2454e6b46eb65efe217a1f872bd;p=libsigrok.git Removal of sdi->index, step 7: fix testo --- diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 8970a9f9..3ceb0869 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -58,9 +58,9 @@ static GSList *scan(GSList *options) libusb_device **devlist; struct libusb_device_handle *hdl; GSList *conn_devices, *devices, *l; - int devcnt, ret, i; + int ret, i; const char *str; - char manufacturer[64], product[64]; + char manufacturer[64], product[64], connection_id[64]; devices = NULL; drvc = di->priv; @@ -118,17 +118,19 @@ static GSList *scan(GSList *options) if (strncmp(manufacturer, "testo", 5)) continue; + usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + /* Hardcode the 435 for now.*/ if (strcmp(product, "testo 435/635/735")) continue; - devcnt = g_slist_length(drvc->instances); - sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE, "Testo", + sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Testo", "435/635/735", NULL); sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL); + sdi->connection_id = g_strdup(connection_id); devc = g_malloc(sizeof(struct dev_context)); devc->model = &models[0]; devc->limit_msec = 0; @@ -161,6 +163,7 @@ static int dev_open(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; libusb_device **devlist; int ret, i; + char connection_id[64]; if (!di->priv) { sr_err("Driver was not initialized."); @@ -170,8 +173,8 @@ static int dev_open(struct sr_dev_inst *sdi) usb = sdi->conn; libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { - if (libusb_get_bus_number(devlist[i]) != usb->bus - || libusb_get_device_address(devlist[i]) != usb->address) + usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); + if (strcmp(sdi->connection_id, connection_id)) continue; if ((ret = libusb_open(devlist[i], &usb->devhdl))) { sr_err("Failed to open device: %s.", libusb_error_name(ret));