ret = gl_read_data(devh);
return ret;
}
-
-int gl_open(int vid)
-{
- int ret;
- struct libusb_device **devs;
- struct libusb_device *dev;
- size_t i = 0;
- struct libusb_device_descriptor desc;
-
- ret = libusb_init(NULL);
- if (ret < 0)
- return GL_ELIBUSB;
-
- if (libusb_get_device_list(NULL, &devs) < 0) {
- ret = GL_EOPEN;
- goto gl_open_error;
- }
-
- while ((dev = devs[i++]) != NULL) {
- if (libusb_get_device_descriptor(dev, &desc) < 0)
- break;
-
- if (desc.idVendor == vid) {
- if (libusb_open(dev, &g_devh) < 0)
- g_devh = NULL;
- break;
- }
- }
-
- libusb_free_device_list(devs, 1);
-
- if (!g_devh) {
- ret = GL_EOPEN;
- goto gl_open_error;
- }
-
- ret = libusb_set_configuration(g_devh, 1);
- if (ret < 0) {
- ret = GL_ESETCONFIG;
- goto gl_open_error;
- }
-
- ret = libusb_claim_interface(g_devh, 0);
- if (ret < 0) {
- ret = GL_ECLAIM;
- goto gl_open_error;
- }
-
- return GL_OK;
-
-gl_open_error:
- gl_close();
- return ret;
-}
-
-int gl_close(void)
-{
- if (g_devh) {
- libusb_release_interface(g_devh, 0);
- libusb_reset_device(g_devh);
- libusb_close(g_devh);
- }
- libusb_exit(NULL);
-
- return 0;
-}
sr_info("closing device %d on %d.%d interface %d", sdi->index,
zp->usb->bus, zp->usb->address, USB_INTERFACE);
libusb_release_interface(zp->usb->devhdl, USB_INTERFACE);
+ libusb_reset_device(zp->usb->devhdl);
libusb_close(zp->usb->devhdl);
zp->usb->devhdl = NULL;
+ /* TODO: Call libusb_exit() here or only in hw_cleanup()? */
sdi->status = SR_ST_INACTIVE;
}
/* Find all ZeroPlus analyzers and add them to device list. */
devcnt = 0;
- libusb_get_device_list(usb_context, &devlist);
+ libusb_get_device_list(usb_context, &devlist); /* TODO: Errors. */
for (i = 0; devlist[i]; i++) {
err = libusb_get_device_descriptor(devlist[i], &des);
return SR_ERR_ARG;
}
+ err = libusb_set_configuration(zp->usb->devhdl, USB_CONFIGURATION);
+ if (err < 0) {
+ sr_warn("zp: Unable to set USB configuration %d: %d",
+ USB_CONFIGURATION, err);
+ return SR_ERR;
+ }
+
err = libusb_claim_interface(zp->usb->devhdl, USB_INTERFACE);
if (err != 0) {
sr_warn("Unable to claim interface: %d", err);
return SR_ERR;
}
+
analyzer_reset(zp->usb->devhdl);
analyzer_initialize(zp->usb->devhdl);