71
72
if (p->debug) fprintf(stderr,"usb_check_and_add() called with VID 0x%x, PID 0x%x\n",descriptor.idVendor, descriptor.idProduct);
75
#if defined(NT) || defined(__APPLE__)
75
76
/* Ignore libusb1 HID driver capability */
76
if (descriptor.bDeviceClass == LIBUSB_CLASS_HID)
79
struct libusb_config_descriptor *config;
78
struct libusb_config_descriptor *config = NULL;
81
if (libusb_get_config_descriptor(dev, 0, &config) != LIBUSB_SUCCESS) {
80
if (descriptor.bDeviceClass != LIBUSB_CLASS_HID
81
&& libusb_get_config_descriptor(dev, 0, &config) != LIBUSB_SUCCESS) {
82
82
if (p->debug) fprintf(stderr,"Get config desc. 0 failed\n");
86
if (config->bNumInterfaces > 0
87
&& config->interface[0]. num_altsetting > 0
88
& config->interface[0].altsetting[0].bInterfaceClass == LIBUSB_CLASS_HID) {
89
if (p->debug) fprintf(stderr,"Is a libusb HID device\n");
86
if (descriptor.bDeviceClass == LIBUSB_CLASS_HID
87
|| (config->bNumInterfaces > 0
88
&& config->interface[0]. num_altsetting > 0
89
&& config->interface[0].altsetting[0].bInterfaceClass == LIBUSB_CLASS_HID)) {
91
/* See if this devices is already in the list via the HID interface */
92
/* (This may not be 100% correct in the face of multiple instances
93
of the same device, if Windows allows different drivers for different
94
instances of the same device type.) */
95
for (i = 0; i < p->npaths; i++) {
96
if (p->paths[i]->vid == descriptor.idVendor
97
&& p->paths[i]->pid == descriptor.idProduct)
101
if (p->debug) fprintf(stderr,"Is an HID device and already added\n");
103
libusb_free_config_descriptor(config);
90
108
libusb_free_config_descriptor(config);
93
libusb_free_config_descriptor(config);
152
167
#ifdef ENABLE_USB
153
168
ssize_t i, nlist;
154
libusb_context *ctx = NULL;
156
169
struct libusb_device **list;
158
171
/* Scan the USB busses for instruments we recognise */
159
/* We're not expecting any of our unstruments to be an interface on a device. */
172
/* We're not expecting any of our instruments to be an interface on a device. */
174
if (p->ctx == NULL) {
176
if ((rv = libusb_init(&p->ctx)) != 0) {
177
error("libusb_init() failed with %d",rv);
163
181
if (p->debug > 8)
164
libusb_set_debug(ctx, p->debug);
182
libusb_set_debug(p->ctx, p->debug);
166
184
nlist = libusb_get_device_list(NULL, &list);
241
/* Cleanup any USB specific icoms */
242
void usb_del_usb(icoms *p) {
245
if (p->ctx != NULL) {
249
#endif /* USE_LIBUSB1 */
228
252
/* Return the instrument type if the port number is USB, */
229
253
/* and instUnknown if it is not. */
238
262
if (port <= 0 || port > p->npaths)
239
error("icoms - usb_is_usb_portno: port number out of range!");
263
error("icoms - usb_is_usb_portno: port number %d out of range %d - %d",port,1,p->npaths);
241
265
#ifdef ENABLE_USB
242
266
if (p->paths[port-1]->dev != NULL)
636
657
if (p->is_open && port != p->port) { /* If port number changes */
641
662
/* Make sure the port is open */
642
663
if (!p->is_open) {
664
struct usb_device_descriptor descriptor;
643
665
#ifdef USE_LIBUSB1
644
666
const struct libusb_interface_descriptor *ifd;
645
667
struct libusb_config_descriptor *confdesc;
704
726
error("Opening USB port '%s' config %d failed (%s) (Permissions ?)",p->ppath->path,config,USB_STRERROR(rv));
730
fprintf(stderr,"open() of USB port '%s' suceeded\n",p->ppath->path);
732
/* Get a copy of the device descriptor so we can see device params */
734
if (libusb_get_device_descriptor(p->ppath->dev, &descriptor) != LIBUSB_SUCCESS)
735
error("Get device descriptor on USB port '%s' failed with %d (%s)",p->ppath->path,rv,libusb_strerror(rv));
737
descriptor = p->ppath->dev->descriptor; /* Copy */
708
740
p->vid = p->ppath->vid;
709
741
p->pid = p->ppath->pid;
710
742
p->usbd = p->ppath->dev;
733
/* (Should use bConfigurationValue ?) */
766
if (p->debug > 1) fprintf(stderr, "Number of configurations = %d\n",
767
descriptor.bNumConfigurations);
768
#if defined(UNIX) && !defined(__APPLE__)
769
/* only call set_configuration on Linux if the device has more than one */
770
/* possible configuration, because Linux does a set_configuration by default, */
771
/* and two of them mess up instruments like the Spyder2 */
773
if (descriptor.bNumConfigurations > 1) {
734
776
/* Can't skip this, as it is needed to setup the interface and end points on OS X */
735
777
#ifdef USE_LIBUSB1
736
778
if ((rv = libusb_set_configuration(p->usbh, p->cnfg)) < 0)
1430
1476
#ifdef USE_LIBUSB1
1431
1477
if (hcancel != NULL)
1432
1478
rv = libusb_cancel_transfer((struct libusb_transfer *)hcancel);
1480
msec_sleep(1); /* Let device recover ? */
1434
1481
rv = usb_resetep(p->usbh, (int)hcancel); /* Not reliable ? */
1482
msec_sleep(1); /* Let device recover ? */