您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ usb_find_busses函数代码示例

51自学网 2021-06-03 09:19:47
  C++
这篇教程C++ usb_find_busses函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中usb_find_busses函数的典型用法代码示例。如果您正苦于以下问题:C++ usb_find_busses函数的具体用法?C++ usb_find_busses怎么用?C++ usb_find_busses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了usb_find_busses函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: usb_open_device_with_vid_pid

usb_dev_handle * usb_open_device_with_vid_pid(void* context, unsigned short vid, unsigned short pid) {	usb_find_busses();	usb_find_devices();	struct usb_bus *busses;	busses = usb_get_busses();  struct usb_bus *bus;	for (bus = busses; bus; bus = bus->next) {		struct usb_device *dev;		for (dev = bus->devices; dev; dev = dev->next) {			/* Check if this device is a printer */			if ((dev->descriptor.idVendor == vid) && (dev->descriptor.idProduct == pid)) {				/* Open the device, claim the interface and do your processing */        return usb_open(dev);			}		}	}  return NULL;}
开发者ID:JayFoxRox,项目名称:LTWheelConf,代码行数:24,


示例2: usbdev_open

/* * The "baud" parameter is meaningless for USB devices, so we reuse it * to pass the desired USB device ID. */static int usbdev_open(char * port, union pinfo pinfo, union filedescriptor *fd){  char string[256];  char product[256];  struct usb_bus *bus;  struct usb_device *dev;  usb_dev_handle *udev;  char *serno, *cp2;  int i;  int iface;  size_t x;  /*   * The syntax for usb devices is defined as:   *   * -P usb[:serialnumber]   *   * See if we've got a serial number passed here.  The serial number   * might contain colons which we remove below, and we compare it   * right-to-left, so only the least significant nibbles need to be   * specified.   */  if ((serno = strchr(port, ':')) != NULL)    {      /* first, drop all colons there if any */      cp2 = ++serno;      while ((cp2 = strchr(cp2, ':')) != NULL)	{	  x = strlen(cp2) - 1;	  memmove(cp2, cp2 + 1, x);	  cp2[x] = '/0';	}      if (strlen(serno) > 12)	{	  avrdude_message(MSG_INFO, "%s: usbdev_open(): invalid serial number /"%s/"/n",                          progname, serno);	  return -1;	}    }  if (fd->usb.max_xfer == 0)    fd->usb.max_xfer = USBDEV_MAX_XFER_MKII;  usb_init();  usb_find_busses();  usb_find_devices();  for (bus = usb_get_busses(); bus; bus = bus->next)    {      for (dev = bus->devices; dev; dev = dev->next)	{	  if (dev->descriptor.idVendor == pinfo.usbinfo.vid &&	      dev->descriptor.idProduct == pinfo.usbinfo.pid)	    {	      udev = usb_open(dev);	      if (udev)		{		  /* yeah, we found something */		  if (usb_get_string_simple(udev,					    dev->descriptor.iSerialNumber,					    string, sizeof(string)) < 0)		    {		      avrdude_message(MSG_INFO, "%s: usb_open(): cannot read serial number /"%s/"/n",                                      progname, usb_strerror());		      /*		       * On some systems, libusb appears to have		       * problems sending control messages.  Catch the		       * benign case where the user did not request a		       * particular serial number, so we could		       * continue anyway.		       */		      if (serno != NULL)			return -1; /* no chance */		      else			strcpy(string, "[unknown]");		    }		  if (usb_get_string_simple(udev,					    dev->descriptor.iProduct,					    product, sizeof(product)) < 0)		    {		      avrdude_message(MSG_INFO, "%s: usb_open(): cannot read product name /"%s/"/n",                                      progname, usb_strerror());		      strcpy(product, "[unnamed product]");		    }		  /*		   * The CMSIS-DAP specification mandates the string		   * "CMSIS-DAP" must be present somewhere in the		   * product name string for a device compliant to		   * that protocol.  Use this for the decisision		   * whether we have to search for a HID interface		   * below.		   *///.........这里部分代码省略.........
开发者ID:UbiquityRobotics,项目名称:bus_loki,代码行数:101,


示例3: drv_MOGX_open

static int drv_MOGX_open(void){    struct usb_bus *busses, *bus;    struct usb_device *dev;    char driver[1024];    char product[1024];    char manufacturer[1024];    char serialnumber[1024];    int ret;    lcd_dev = NULL;    info("%s: scanning for Matrix Orbital GX Series LCD...", Name);    usb_set_debug(0);    usb_init();    usb_find_busses();    usb_find_devices();    busses = usb_get_busses();    for (bus = busses; bus; bus = bus->next) {	for (dev = bus->devices; dev; dev = dev->next) {	    if ((dev->descriptor.idVendor == MatrixOrbitalGX_VENDOR) &&		((dev->descriptor.idProduct == MatrixOrbitalGX_DEVICE_1) ||		 (dev->descriptor.idProduct == MatrixOrbitalGX_DEVICE_2) ||		 (dev->descriptor.idProduct == MatrixOrbitalGX_DEVICE_3))) {		/* At the moment, I have information for only this LCD */		if (dev->descriptor.idProduct == MatrixOrbitalGX_DEVICE_2)		    backlight_RGB = 0;		info("%s: found Matrix Orbital GX Series LCD on bus %s device %s", Name, bus->dirname, dev->filename);		lcd_dev = usb_open(dev);		ret = usb_get_driver_np(lcd_dev, 0, driver, sizeof(driver));		if (ret == 0) {		    info("%s: interface 0 already claimed by '%s'", Name, driver);		    info("%s: attempting to detach driver...", Name);		    if (usb_detach_kernel_driver_np(lcd_dev, 0) < 0) {			error("%s: usb_detach_kernel_driver_np() failed!", Name);			return -1;		    }		}		usb_set_configuration(lcd_dev, 1);		usleep(100);		if (usb_claim_interface(lcd_dev, 0) < 0) {		    error("%s: usb_claim_interface() failed!", Name);		    return -1;		}		usb_set_altinterface(lcd_dev, 0);		usb_get_string_simple(lcd_dev, dev->descriptor.iProduct, product, sizeof(product));		usb_get_string_simple(lcd_dev, dev->descriptor.iManufacturer, manufacturer, sizeof(manufacturer));		usb_get_string_simple(lcd_dev, dev->descriptor.iSerialNumber, serialnumber, sizeof(serialnumber));		info("%s: Manufacturer='%s' Product='%s' SerialNumber='%s'", Name, manufacturer, product, serialnumber);		return 0;	    }	}    }    error("%s: could not find a Matrix Orbital GX Series LCD", Name);    return -1;}
开发者ID:KCFTech,项目名称:lcd4linux,代码行数:70,


示例4: main

int main(int argc, char *argv[]){	struct usb_bus *bus;	struct usb_device *dev, *mydev;	usb_dev_handle *handle;	unsigned char bytes[64];	int ret;	int i; 	for (ret = 0; ret < 64; ret++) {		 bytes[ret] = 0;	}	bytes[0] = 0; 	bytes[1] = 0; 	bytes[2] = 0; 	bytes[3] = 0; 	bytes[4] = 0; 	bytes[5] = 0; 	bytes[6] = 0x01; 	bytes[7] = 0xbb; 	usb_init();	usb_find_busses();	usb_find_devices();	for (bus = usb_busses; bus; bus = bus->next) {		for (dev = bus->devices; dev; dev = dev->next) {			if (dev->descriptor.idVendor == 0x1130 && dev->descriptor.idProduct == 0x6807) {				printf("find my device/n");				mydev = dev;				break;			}		}	}	handle = usb_open(mydev);	printf("handle = %d/n", handle);	//usb_get_driver_np(handle, 0, bytes, 64); 	//fprintf(stderr,  "return usb_get_driver name is %s/n",  bytes); #if 1	ret = usb_detach_kernel_driver_np(handle, 1); 	fprintf(stderr,  "usb_detach_kernel_driver_np return %d/n",  ret); 	ret = usb_claim_interface(handle, 1);	printf("claim interface return %d/n",  ret); #endif	#if 1	ret = usb_detach_kernel_driver_np(handle, 0); 	fprintf(stderr,  "return usb_detach_kernel_driver_np is %d/n",  ret); 	ret = usb_claim_interface(handle, 0);	printf("claim interface return %d/n",  ret); #endif	ret = usb_control_msg(handle, 0x21, 0x09,	0x0200, 1, bytes, 0x0008, 1000);	printf("usb_control_msg return %d/n",  ret); 	sleep(1); 	ret = usb_interrupt_read(handle, 3, bytes, 64,  1000); 	printf("usb_interrupt_read return %d/n",  ret); 	for (i = 0;  i < 64;  i++) {		printf("0x%02x ", bytes[i]); 	}	printf("/n"); 	usb_release_interface(handle, 0); 	usb_release_interface(handle, 1); 	usb_close(handle); 	return 0;}
开发者ID:axlrose,项目名称:cells,代码行数:73,


示例5: HPRescanUsbBus

static void HPRescanUsbBus(void){	int i, j;	struct usb_bus *bus;	struct usb_device *dev;	char bus_device[BUS_DEVICE_STRSIZE];	usb_find_busses();	usb_find_devices();	for (i=0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)		/* clear rollcall */		readerTracker[i].status = READER_ABSENT;	/* For each USB bus */	for (bus = usb_get_busses(); bus; bus = bus->next)	{		/* For each USB device */		for (dev = bus->devices; dev; dev = dev->next)		{			/* check if the device is supported by one driver */			for (i=0; i<driverSize; i++)			{				if (driverTracker[i].libraryPath != NULL &&					dev->descriptor.idVendor == driverTracker[i].manuID &&					dev->descriptor.idProduct == driverTracker[i].productID)				{					int newreader;					/* A known device has been found */					snprintf(bus_device, BUS_DEVICE_STRSIZE, "%s:%s",						bus->dirname, dev->filename);					bus_device[BUS_DEVICE_STRSIZE - 1] = '/0';#ifdef DEBUG_HOTPLUG					Log2(PCSC_LOG_DEBUG, "Found matching USB device: %s",						bus_device);#endif					newreader = TRUE;					/* Check if the reader is a new one */					for (j=0; j<PCSCLITE_MAX_READERS_CONTEXTS; j++)					{						if (strncmp(readerTracker[j].bus_device,							bus_device, BUS_DEVICE_STRSIZE) == 0)						{							/* The reader is already known */							readerTracker[j].status = READER_PRESENT;							newreader = FALSE;#ifdef DEBUG_HOTPLUG							Log2(PCSC_LOG_DEBUG, "Refresh USB device: %s",								bus_device);#endif							break;						}					}					/* New reader found */					if (newreader)						HPAddHotPluggable(dev, bus_device, &driverTracker[i]);				}			}		} /* End of USB device for..loop */	} /* End of USB bus for..loop */	/*	 * check if all the previously found readers are still present	 */	for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++)	{#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)		int fd;		char filename[BUS_DEVICE_STRSIZE];		/*	BSD workaround:		 *	ugenopen() in sys/dev/usb/ugen.c returns EBUSY		 *	when the character device file is already open.		 *	Because of this, open usb devices will not be		 *	detected by usb_find_devices(), so we have to		 *	check for this explicitly.		 */		if (readerTracker[i].status == READER_PRESENT ||			 readerTracker[i].fullName == NULL)			continue;		sscanf(readerTracker[i].bus_device, "%*[^:]%*[:]%s", filename);		fd = open(filename, O_RDONLY);		if (fd == -1)		{			if (errno == EBUSY)			{				/* The device is present */#ifdef DEBUG_HOTPLUG				Log2(PCSC_LOG_DEBUG, "BSD: EBUSY on %s", filename);#endif				readerTracker[i].status = READER_PRESENT;			}#ifdef DEBUG_HOTPLUG			else				Log3(PCSC_LOG_DEBUG, "BSD: %s error: %s", filename,//.........这里部分代码省略.........
开发者ID:andyvand,项目名称:pcsc-lite-clone,代码行数:101,


示例6: hd_init_lcd2usb

/** * Initialize the driver. * /param drvthis  Pointer to driver structure. * /retval 0       Success. * /retval -1      Error. */inthd_init_lcd2usb(Driver *drvthis){	PrivateData *p = (PrivateData *) drvthis->private_data;	struct usb_bus *bus;	p->hd44780_functions->senddata = lcd2usb_HD44780_senddata;	p->hd44780_functions->backlight = lcd2usb_HD44780_backlight;	p->hd44780_functions->scankeypad = lcd2usb_HD44780_scankeypad;	p->hd44780_functions->close = lcd2usb_HD44780_close;	p->hd44780_functions->set_contrast = lcd2usb_HD44780_set_contrast;	p->hd44780_functions->flush = lcd2usb_HD44780_flush;	/* try to find USB device */#if 0	usb_debug = 2;#endif	usb_init();	usb_find_busses();	usb_find_devices();	p->usbHandle = NULL;	for (bus = usb_get_busses(); bus != NULL; bus = bus->next) {		struct usb_device *dev;		for (dev = bus->devices; dev != NULL; dev = dev->next) {			/* Check if this device is a LCD2USB device */			if ((dev->descriptor.idVendor == LCD2USB_VENDORID) &&			 (dev->descriptor.idProduct == LCD2USB_PRODUCTID)) {				/*				 * LCD2USB device found; try to find its				 * description				 */				p->usbHandle = usb_open(dev);				if (p->usbHandle == NULL) {					report(RPT_WARNING, "hd_init_lcd2usb: unable to open device");				}				else {					/* read firmware version */					unsigned char buffer[2];					if (usb_control_msg(p->usbHandle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,							    LCD2USB_GET_FWVER, 0, 0, (char *)buffer, sizeof(buffer), 1000) == 2)						report(RPT_INFO, "hd_init_lcd2usb: device with firmware version %d.%02d found", buffer[0], buffer[1]);				}			}		}	}	if (p->usbHandle != NULL) {		debug(RPT_DEBUG, "hd_init_lcd2usb: opening device succeeded");	}	else {		report(RPT_ERR, "hd_init_lcd2usb: no (matching) LCD2USB device found");		return -1;	}	/* allocate and initialize send buffer */	if ((p->tx_buf.buffer = malloc(LCD2USB_MAX_CMD)) == NULL) {		report(RPT_ERR, "hd_init_lcd2usb: could not allocate send buffer");		lcd2usb_HD44780_close(p);		return -1;	}	p->tx_buf.type = -1;	p->tx_buf.use_count = 0;	common_init(p, IF_4BIT);	/* replace uPause with empty one after initialization */	p->hd44780_functions->uPause = lcd2usb_HD44780_uPause;	return 0;}
开发者ID:FamousBonecrusher,项目名称:lcdproc-0.5.6_MCP23008,代码行数:83,


示例7: tr

	/// /brief Search for compatible devices.	/// /return A string with the result of the search.	QString Device::search() {		if(this->error)			return tr("Can't search for Hantek oscilloscopes: %1").arg(Helper::libUsbErrorString(this->error));				QString message;		QString deviceAddress;		int errorCode = LIBUSB_SUCCESS;		#if LIBUSB_VERSION == 0		errorCode = usb_find_busses();		if(errorCode >= 0)			errorCode = usb_find_devices();		if(errorCode < 0)			return tr("Failed to get device list: %1").arg(Helper::libUsbErrorString(errorCode));				struct usb_device *device = NULL;				// Iterate through all usb devices		for(struct usb_bus *bus = usb_busses; bus; bus = bus->next) {			for(device = bus->devices; device; device = device->next) {				// Check VID and PID				if(device->descriptor.idVendor == HANTEK_VENDOR_ID) {					this->model = (Model) this->modelIds.indexOf(device->descriptor.idProduct);					if(this->model >= 0)						break; // Found a compatible device, ignore others				}			}			if(this->model >= 0) {				deviceAddress = QString("%1:%2").arg(bus->dirname).arg(device->filename);				break; // Found a compatible device, ignore other busses			}		}				if(this->model >= 0) {			// Open device			deviceAddress = QString("%1:%2").arg(device->bus->location, 3, 10, QLatin1Char('0')).arg(device->devnum, 3, 10, QLatin1Char('0'));			this->handle = usb_open(device);			if(this->handle) {				struct usb_config_descriptor *configDescriptor = device->config;				struct usb_interface *interface;				struct usb_interface_descriptor *interfaceDescriptor;				for(int interfaceIndex = 0; interfaceIndex < configDescriptor->bNumInterfaces; ++interfaceIndex) {					interface = &configDescriptor->interface[interfaceIndex];					if(interface->num_altsetting < 1)						continue;										interfaceDescriptor = &interface->altsetting[0];					if(interfaceDescriptor->bInterfaceClass == USB_CLASS_VENDOR_SPEC && interfaceDescriptor->bInterfaceSubClass == 0 && interfaceDescriptor->bInterfaceProtocol == 0 && interfaceDescriptor->bNumEndpoints == 2) {						// That's the interface we need, claim it						errorCode = usb_claim_interface(this->handle, interfaceDescriptor->bInterfaceNumber);						if(errorCode < 0) {							usb_close(this->handle);							this->handle = 0;							message = tr("Failed to claim interface %1 of device %2: %3").arg(QString::number(interfaceDescriptor->bInterfaceNumber), deviceAddress, Helper::libUsbErrorString(errorCode));						}						else {								this->interface = interfaceDescriptor->bInterfaceNumber;														// Check the maximum endpoint packet size							usb_endpoint_descriptor *endpointDescriptor;							this->outPacketLength = 0;							this->inPacketLength = 0;							for (int endpoint = 0; endpoint < interfaceDescriptor->bNumEndpoints; ++endpoint) {								endpointDescriptor = &interfaceDescriptor->endpoint[endpoint];								switch(endpointDescriptor->bEndpointAddress) {									case HANTEK_EP_OUT:										this->outPacketLength = endpointDescriptor->wMaxPacketSize;										break;									case HANTEK_EP_IN:										this->inPacketLength = endpointDescriptor->wMaxPacketSize;										break;								}							}							message = tr("Device found: Hantek %1 (%2)").arg(this->modelStrings[this->model], deviceAddress);							emit connected();						}					}				}			}			else				message = tr("Couldn't open device %1").arg(deviceAddress);		}		else			message = tr("No Hantek oscilloscope found");#else		libusb_device **deviceList;		libusb_device *device;				if(this->handle)			libusb_close(this->handle);				ssize_t deviceCount = libusb_get_device_list(this->context, &deviceList);		if(deviceCount < 0)			return tr("Failed to get device list: %1").arg(Helper::libUsbErrorString(errorCode));				// Iterate through all usb devices		this->model = MODEL_UNKNOWN;		for(ssize_t deviceIterator = 0; deviceIterator < deviceCount; ++deviceIterator) {//.........这里部分代码省略.........
开发者ID:DinBan,项目名称:openhantek,代码行数:101,


示例8: usbOpenDevice

static int usbOpenDevice(usb_dev_handle **device, int vendor,			 char *vendorName, int product, char *productName){struct usb_bus       *bus;struct usb_device    *dev;usb_dev_handle       *handle = NULL;int                  errorCode = USB_ERROR_NOTFOUND;static int           didUsbInit = 0;    if(!didUsbInit){        didUsbInit = 1;        usb_init();    }    usb_find_busses();    usb_find_devices();    for(bus=usb_get_busses(); bus; bus=bus->next){        for(dev=bus->devices; dev; dev=dev->next){            if(dev->descriptor.idVendor == vendor &&	       dev->descriptor.idProduct == product){                char    string[256];                int     len;		/* we need to open the device in order to query strings */                handle = usb_open(dev);                if(!handle){                    errorCode = USB_ERROR_ACCESS;                    fprintf(stderr,			    "%s: Warning: cannot open USB device: %s/n",			    progname, usb_strerror());                    continue;                }                if(vendorName == NULL && productName == NULL){		    /* name does not matter */                    break;                }                /* now check whether the names match: */                len = usb_get_string_simple(handle, dev->descriptor.iManufacturer,					    string, sizeof(string));                if(len < 0){                    errorCode = USB_ERROR_IO;                    fprintf(stderr,			    "%s: Warning: cannot query manufacturer for device: %s/n",			    progname, usb_strerror());                }else{                    errorCode = USB_ERROR_NOTFOUND;		    if (verbose > 1)		        fprintf(stderr,				"%s: seen device from vendor ->%s<-/n",				progname, string);                    if(strcmp(string, vendorName) == 0){                        len = usb_get_string_simple(handle, dev->descriptor.iProduct,						    string, sizeof(string));                        if(len < 0){                            errorCode = USB_ERROR_IO;                            fprintf(stderr,				    "%s: Warning: cannot query product for device: %s/n",				    progname, usb_strerror());                        }else{                            errorCode = USB_ERROR_NOTFOUND;			    if (verbose > 1)			        fprintf(stderr,					"%s: seen product ->%s<-/n",					progname, string);                            if(strcmp(string, productName) == 0)                                break;                        }                    }                }                usb_close(handle);                handle = NULL;            }        }        if(handle)            break;    }    if(handle != NULL){        errorCode = 0;        *device = handle;    }    return errorCode;}
开发者ID:embedded-creations,项目名称:Networked-Display,代码行数:80,


示例9: usbFindDevice

UsbDevice *usbFindDevice (UsbDeviceChooser *chooser, UsbChooseChannelData *data) {  UsbDevice *device = NULL;  int result;  {    static int initialized = 0;    if (!initialized) {      usb_init();      initialized = 1;    }  }  if ((result = usb_find_busses()) >= 0) {    if ((result = usb_find_devices()) >= 0) {      struct usb_bus *bus = usb_get_busses();      if (bus) {        struct usb_bus *bus0 = bus;        do {          struct usb_device *dev = bus->devices;          if (dev) {            struct usb_device *dev0 = dev;            do {              UsbDeviceExtension *devx;              if ((devx = malloc(sizeof(*devx)))) {                if ((devx->handle = usb_open(dev))) {                  if ((device = usbTestDevice(devx, chooser, data))) return device;                  usb_close(devx->handle);                } else {                  logMessage(LOG_ERR, "USB open error: vendor=%X product=%X",                             getLittleEndian16(dev->descriptor.idVendor),                             getLittleEndian16(dev->descriptor.idProduct));                }                free(devx);              } else {                logSystemError("USB device extension allocate");              }              if ((dev = dev->next) == dev0) dev = NULL;            } while (dev);          }          if ((bus = bus->next) == bus0) bus = NULL;        } while (bus);      }    } else {      errno = -result;      logSystemError("USB devices find");    }  } else {    errno = -result;    logSystemError("USB busses find");  }  return device;}
开发者ID:plundblad,项目名称:brltty,代码行数:63,


示例10: hd_init_bwct_usb

/** * Initialize the driver. * /param drvthis  Pointer to driver structure. * /retval 0       Success. * /retval -1      Error. */inthd_init_bwct_usb(Driver *drvthis){  PrivateData *p = (PrivateData*) drvthis->private_data;  struct usb_bus *bus;  //char device_manufacturer[LCD_MAX_WIDTH+1] = "";  char device_serial[LCD_MAX_WIDTH+1] = DEFAULT_SERIALNO;  char serial[LCD_MAX_WIDTH+1] = DEFAULT_SERIALNO;  p->hd44780_functions->senddata = bwct_usb_HD44780_senddata;  p->hd44780_functions->close = bwct_usb_HD44780_close;  p->hd44780_functions->set_contrast = bwct_usb_HD44780_set_contrast;  /* Read config file's contents: serial number and contrast */  strncpy(serial, drvthis->config_get_string(drvthis->name, "SerialNumber",                                             0, DEFAULT_SERIALNO), sizeof(serial));  serial[sizeof(serial)-1] = '/0';  if (*serial != '/0') {    report(RPT_INFO, "hd_init_bwct_usb: Using serial number: %s", serial);  }  /* try to find USB device */#if 0  usb_debug = 2;#endif  usb_init();  usb_find_busses();  usb_find_devices();  p->usbHandle = NULL;  p->usbIndex = 0;  for (bus = usb_get_busses(); bus != NULL; bus = bus->next) {    struct usb_device *dev;    for (dev = bus->devices; dev != NULL; dev = dev->next) {      int c;      /* Check if this device is a BWCT device */      if (dev->descriptor.idVendor != BWCT_USB_VENDORID) {        continue;      }      /* Loop through all of the configurations */      for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {        /* Loop through all of the interfaces */        for (p->usbIndex = 0; p->usbIndex < dev->config[c].bNumInterfaces; p->usbIndex++) {          int a;          /* Loop through all of the alternate settings */          for (a = 0; a < dev->config[c].interface[p->usbIndex].num_altsetting; a++) {            /* Check if this interface is a BWCT lcd */            if (((dev->config[c].interface[p->usbIndex].altsetting[a].bInterfaceClass == 0xFF) &&                 (dev->config[c].interface[p->usbIndex].altsetting[a].bInterfaceSubClass == 0x01)) ||                (dev->descriptor.idProduct == BWCT_USB_PRODUCTID)) {              /* BWCT device found; try to find its description and serial number */              p->usbHandle = usb_open(dev);              if (p->usbHandle == NULL) {                report(RPT_WARNING, "hd_init_bwct_usb: unable to open device");                // return -1;                /* it's better to continue */              }              else {                /* get device information & check for serial number */                //if (usb_get_string_simple(p->usbHandle, dev->descriptor.iManufacturer,                //                          manufacturer, LCD_MAX_WIDTH) <= 0)                //  *manufacturer = '/0';                //manufacturer[sizeof(manufacturer)-1] = '/0';                //if (usb_get_string_simple(p->usbHandle, dev->descriptor.iProduct,                //                          product, LCD_MAX_WIDTH) <= 0)                //  *product = '/0';                //product[sizeof(product)-1] = '/0';                if (usb_get_string_simple(p->usbHandle, dev->descriptor.iSerialNumber,                                          device_serial, LCD_MAX_WIDTH) <= 0)                  *device_serial = '/0';                device_serial[sizeof(device_serial)-1] = '/0';                if ((*serial != '/0') && (*device_serial == '/0')) {                  report(RPT_ERR, "hd_init_bwct_usb: unable to get device's serial number");                  usb_close(p->usbHandle);                  return -1;                }                /* succeed if no serial was given in the config or the 2 numbers match */                if ((*serial == '/0') || (strcmp(serial, device_serial) == 0))                  goto done;                usb_close(p->usbHandle);                p->usbHandle = NULL;              }            }          }//.........这里部分代码省略.........
开发者ID:emteejay,项目名称:lcdproc,代码行数:101,


示例11: fprintf

int UHandler::openDevice (usb_dev_handle **device, int vendor, char *vendorName, int product, char *productName){	fprintf (stderr, "UHandler: opening device./n");struct usb_bus      *bus;  // bussesstruct usb_device   *dev;  // devicesusb_dev_handle      *handle = NULL; // handle for detected deviceint                 errorCode = USB_ERROR_NOTFOUND; // error code %)static int          didUsbInit = 0; // just an initialization indicator     if(!didUsbInit){          didUsbInit = 1;        usb_init();    }    usb_find_busses();    usb_find_devices();    for(bus=usb_get_busses(); bus; bus=bus->next){ // looking among all busses and devices        for(dev=bus->devices; dev; dev=dev->next){            if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product){ // if vendor and id are matching needed ones                char    string[256];                int     len;                handle = usb_open(dev); /* we need to open the device in order to query strings */                if(!handle){                    errorCode = USB_ERROR_ACCESS;                    fprintf(stderr, "Warning: cannot open USB device: %s/n", usb_strerror());                    continue;                }                if(vendorName == NULL && productName == NULL){  /* name does not matter */                    break;                }                /* now check whether the names match: */                len = getString (handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string));                if(len < 0){                    errorCode = USB_ERROR_IO;                    fprintf(stderr, "Warning: cannot query manufacturer for device: %s/n", usb_strerror());                }else{                    errorCode = USB_ERROR_NOTFOUND;                    fprintf(stderr, "seen device from vendor ->%s<-/n", string);                    if(strcmp(string, vendorName) == 0){                        len = getString (handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string));                        if(len < 0){                            errorCode = USB_ERROR_IO;                            fprintf(stderr, "Warning: cannot query product for device: %s/n", usb_strerror());                        }else{                            errorCode = USB_ERROR_NOTFOUND;                            fprintf(stderr, "seen product ->%s<-/n", string);                            if(strcmp(string, productName) == 0)                                break;                        }                    }                }                usb_close(handle);                handle = NULL;            }        }        if(handle)            break;    }    if(handle != NULL){        errorCode = 0;        *device = handle;    }    return errorCode;}
开发者ID:infernal666knight,项目名称:opendaq,代码行数:64,


示例12: libusb_open

/* On success, fill in the curDevice structure and return the report * descriptor length. On failure, return -1. * Note: When callback is not NULL, the report descriptor will be * passed to this function together with the udev and USBDevice_t * information. This callback should return a value > 0 if the device * is accepted, or < 1 if not. If it isn't accepted, the next device * (if any) will be tried, until there are no more devices left. */static int libusb_open(usb_dev_handle **udevp, USBDevice_t *curDevice, USBDeviceMatcher_t *matcher,	int (*callback)(usb_dev_handle *udev, USBDevice_t *hd, unsigned char *rdbuf, int rdlen)){#ifdef HAVE_USB_DETACH_KERNEL_DRIVER_NP	int retries;#endif	int rdlen1, rdlen2; /* report descriptor length, method 1+2 */	USBDeviceMatcher_t *m;	struct usb_device *dev;	struct usb_bus *bus;	usb_dev_handle *udev;	struct usb_interface_descriptor *iface;	int ret, res;	unsigned char buf[20];	unsigned char *p;	char string[256];	int i;	/* report descriptor */	unsigned char	rdbuf[MAX_REPORT_SIZE];	int		rdlen;	/* libusb base init */	usb_init();	usb_find_busses();	usb_find_devices();#ifndef __linux__ /* SUN_LIBUSB (confirmed to work on Solaris and FreeBSD) */	/* Causes a double free corruption in linux if device is detached! */	libusb_close(*udevp);#endif	for (bus = usb_busses; bus; bus = bus->next) {		for (dev = bus->devices; dev; dev = dev->next) {			upsdebugx(2, "Checking device (%04X/%04X) (%s/%s)", dev->descriptor.idVendor,				dev->descriptor.idProduct, bus->dirname, dev->filename);			/* supported vendors are now checked by the			   supplied matcher */			/* open the device */			*udevp = udev = usb_open(dev);			if (!udev) {				upsdebugx(2, "Failed to open device, skipping. (%s)", usb_strerror());				continue;			}			/* collect the identifying information of this			   device. Note that this is safe, because			   there's no need to claim an interface for			   this (and therefore we do not yet need to			   detach any kernel drivers). */			free(curDevice->Vendor);			free(curDevice->Product);			free(curDevice->Serial);			free(curDevice->Bus);			memset(curDevice, '/0', sizeof(*curDevice));			curDevice->VendorID = dev->descriptor.idVendor;			curDevice->ProductID = dev->descriptor.idProduct;			curDevice->Bus = strdup(bus->dirname);			if (dev->descriptor.iManufacturer) {				ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer,					string, sizeof(string));				if (ret > 0) {					curDevice->Vendor = strdup(string);				}			}			if (dev->descriptor.iProduct) {				ret = usb_get_string_simple(udev, dev->descriptor.iProduct,					string, sizeof(string));				if (ret > 0) {					curDevice->Product = strdup(string);				}			}			if (dev->descriptor.iSerialNumber) {				ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber,					string, sizeof(string));				if (ret > 0) {					curDevice->Serial = strdup(string);				}			}			upsdebugx(2, "- VendorID: %04x", curDevice->VendorID);			upsdebugx(2, "- ProductID: %04x", curDevice->ProductID);			upsdebugx(2, "- Manufacturer: %s", curDevice->Vendor ? curDevice->Vendor : "unknown");			upsdebugx(2, "- Product: %s", curDevice->Product ? curDevice->Product : "unknown");//.........这里部分代码省略.........
开发者ID:alfh,项目名称:nut,代码行数:101,


示例13: musb_open

int musb_open(MUSB_INTERFACE **musb_interface, int vendor, int product, int instance, int configuration, int usbinterface){#if defined(HAVE_LIBUSB)      struct usb_bus *bus;   struct usb_device *dev;   int count = 0;      usb_init();   usb_find_busses();   usb_find_devices();   usb_set_debug(3);      for (bus = usb_get_busses(); bus; bus = bus->next)      for (dev = bus->devices; dev; dev = dev->next)         if (dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product) {            if (count == instance) {               int status;               usb_dev_handle *udev;               udev = usb_open(dev);               if (!udev) {                  fprintf(stderr, "musb_open: usb_open() error/n");                  return MUSB_ACCESS_ERROR;               }               status = usb_set_configuration(udev, configuration);               if (status < 0) {                  fprintf(stderr, "musb_open: usb_set_configuration() error %d (%s)/n", status,                     strerror(-status));                  fprintf(stderr,                     "musb_open: Found USB device 0x%04x:0x%04x instance %d, but cannot initialize it: please check permissions on /"/proc/bus/usb/%s/%s/" and /"/dev/bus/usb/%s/%s/"/n",                     vendor, product, instance, bus->dirname, dev->filename, bus->dirname, dev->filename);                  return MUSB_ACCESS_ERROR;               }               /* see if we have write access */               status = usb_claim_interface(udev, usbinterface);               if (status < 0) {                  fprintf(stderr, "musb_open: usb_claim_interface() error %d (%s)/n", status,                     strerror(-status));#ifdef _MSC_VER                  fprintf(stderr,                     "musb_open: Found USB device 0x%04x:0x%04x instance %d, but cannot initialize it:/nDevice is probably used by another program/n",                     vendor, product, instance);#else                  fprintf(stderr,                     "musb_open: Found USB device 0x%04x:0x%04x instance %d, but cannot initialize it: please check permissions on /"/proc/bus/usb/%s/%s/"/n",                     vendor, product, instance, bus->dirname, dev->filename);#endif                  return MUSB_ACCESS_ERROR;               }               *musb_interface = (MUSB_INTERFACE*)calloc(1, sizeof(MUSB_INTERFACE));               (*musb_interface)->dev = udev;               (*musb_interface)->usb_configuration = configuration;               (*musb_interface)->usb_interface     = usbinterface;               return MUSB_SUCCESS;            }            count++;         }      return MUSB_NOT_FOUND;   #elif defined(HAVE_LIBUSB10)      static int first_call = 1;   libusb_device **dev_list;   libusb_device_handle *dev;   struct libusb_device_descriptor desc;      int status, i, n;   int count = 0;      if (first_call) {      first_call = 0;      libusb_init(NULL);      // libusb_set_debug(NULL, 3);   }         n = libusb_get_device_list(NULL, &dev_list);      for (i=0 ; i<n ; i++) {      status = libusb_get_device_descriptor(dev_list[i], &desc);      if (desc.idVendor == vendor && desc.idProduct == product) {         if (count == instance) {            status = libusb_open(dev_list[i], &dev);            if (status < 0) {               fprintf(stderr, "musb_open: libusb_open() error %d/n", status);               return MUSB_ACCESS_ERROR;            }            status = libusb_set_configuration(dev, configuration);            if (status < 0) {               fprintf(stderr, "musb_open: usb_set_configuration() error %d/n", status);               fprintf(stderr,//.........这里部分代码省略.........
开发者ID:andrewpeck,项目名称:drs4-daq,代码行数:101,


示例14: findProxmark

usb_dev_handle* findProxmark(int verbose, unsigned int *iface){  struct usb_bus *busses, *bus;  usb_dev_handle *handle = NULL;  struct prox_unit units[50];  int iUnit = 0;  usb_find_busses();  usb_find_devices();  busses = usb_get_busses();  for (bus = busses; bus; bus = bus->next) {    struct usb_device *dev;        for (dev = bus->devices; dev; dev = dev->next) {      struct usb_device_descriptor *desc = &(dev->descriptor);      if ((desc->idProduct == 0x4b8f) && (desc->idVendor == 0x9ac4)) {        handle = usb_open(dev);        if (!handle) {          if (verbose)            fprintf(stderr, "open fabiled: %s!/n", usb_strerror());          //return NULL;          continue;        }        *iface = dev->config[0].interface[0].altsetting[0].bInterfaceNumber;        struct prox_unit unit = {handle, {0}};        usb_get_string_simple(handle, desc->iSerialNumber, unit.serial_number, sizeof(unit.serial_number));        units[iUnit++] = unit;        //return handle;      }    }  }  if (iUnit > 0) {    int iSelection = 0;    fprintf(stdout, "/nConnected units:/n");    for (int i = 0; i < iUnit; i++) {      struct usb_device * dev = usb_device(units[i].handle);      fprintf(stdout, "/t%d. SN: %s [%s/%s]/n", i+1, units[i].serial_number, dev->bus->dirname, dev->filename);    }    if (iUnit > 1) {      while (iSelection < 1 || iSelection > iUnit) {        fprintf(stdout, "Which unit do you want to connect to? ");        fscanf(stdin, "%d", &iSelection);        }      }    else      iSelection = 1;    iSelection --;    for (int i = 0; i < iUnit; i++) {      if (iSelection == i) continue;      usb_close(units[i].handle);      units[i].handle = NULL;    }    return units[iSelection].handle;  }  return NULL;}
开发者ID:Proxmark,项目名称:proxmark3,代码行数:67,


示例15: LOG_INFO

/** @brief detect devices based on usb pid / vid. *  @return list with usb VID / PID values. */QMap<uint32_t, QString> System::listUsbDevices(void){    QMap<uint32_t, QString> usbids;    // usb pid detection    LOG_INFO() << "Searching for USB devices";#if defined(Q_OS_LINUX)#if defined(LIBUSB1)    libusb_device **devs;    if(libusb_init(NULL) != 0) {        LOG_ERROR() << "Initializing libusb-1 failed.";        return usbids;    }    if(libusb_get_device_list(NULL, &devs) < 1) {        LOG_ERROR() << "Error getting device list.";        return usbids;    }    libusb_device *dev;    int i = 0;    while((dev = devs[i++]) != NULL) {        QString name;        unsigned char buf[256];        uint32_t id;        struct libusb_device_descriptor descriptor;        if(libusb_get_device_descriptor(dev, &descriptor) == 0) {            id = descriptor.idVendor << 16 | descriptor.idProduct;            libusb_device_handle *dh;            if(libusb_open(dev, &dh) == 0) {                libusb_get_string_descriptor_ascii(dh, descriptor.iManufacturer, buf, 256);                name += QString::fromLatin1((char*)buf) + " ";                libusb_get_string_descriptor_ascii(dh, descriptor.iProduct, buf, 256);                name += QString::fromLatin1((char*)buf);                libusb_close(dh);            }            if(name.isEmpty())                name = tr("(no description available)");            if(id) {                usbids.insertMulti(id, name);                LOG_INFO("USB: 0x%08x, %s", id, name.toLocal8Bit().data());            }        }    }    libusb_free_device_list(devs, 1);    libusb_exit(NULL);#else    usb_init();    usb_find_busses();    usb_find_devices();    struct usb_bus *b;    b = usb_busses;    while(b) {        if(b->devices) {            struct usb_device *u;            u = b->devices;            while(u) {                uint32_t id;                id = u->descriptor.idVendor << 16 | u->descriptor.idProduct;                // get identification strings                usb_dev_handle *dev;                QString name;                char string[256];                int res;                dev = usb_open(u);                if(dev) {                    if(u->descriptor.iManufacturer) {                        res = usb_get_string_simple(dev, u->descriptor.iManufacturer,                                                    string, sizeof(string));                        if(res > 0)                            name += QString::fromLatin1(string) + " ";                    }                    if(u->descriptor.iProduct) {                        res = usb_get_string_simple(dev, u->descriptor.iProduct,                                                    string, sizeof(string));                        if(res > 0)                            name += QString::fromLatin1(string);                    }                    usb_close(dev);                }                if(name.isEmpty()) name = tr("(no description available)");                if(id) {                    usbids.insertMulti(id, name);                    LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16) << name;                }                u = u->next;            }        }        b = b->next;    }#endif#endif#if defined(Q_OS_MACX)    kern_return_t result = KERN_FAILURE;//.........这里部分代码省略.........
开发者ID:zfhrp6,项目名称:rockbox,代码行数:101,


示例16: hd_init_usb4all

/** * Initialize the driver. * /param drvthis  Pointer to driver structure. * /retval 0       Success. * /retval -1      Error. */inthd_init_usb4all(Driver *drvthis){	PrivateData *p = (PrivateData *) drvthis->private_data;	struct usb_bus *bus;	p->hd44780_functions->senddata = usb4all_HD44780_senddata;	p->hd44780_functions->close = usb4all_HD44780_close;	p->hd44780_functions->set_contrast = usb4all_HD44780_set_contrast;	p->hd44780_functions->backlight = usb4all_HD44780_backlight;	p->hd44780_functions->readkeypad = usb4all_HD44780_readkeypad;	/* try to find USB device */	usb_init();	usb_find_busses();	usb_find_devices();	p->usbHandle = NULL;	for (bus = usb_get_busses(); bus != NULL; bus = bus->next) {		struct usb_device *dev;		for (dev = bus->devices; dev != NULL; dev = dev->next) {			/* Check if this device is a usb4all device */			if ((dev->descriptor.idVendor == USB4ALL_VENDORID) &&			 (dev->descriptor.idProduct == USB4ALL_PRODUCTID)) {				/* USB-4-all device found; try to open it */				p->usbHandle = usb_open(dev);				if (p->usbHandle == NULL) {					report(RPT_WARNING, "hd_init_usb4all: unable to open device");					/*					 * Do not exit here because other					 * (possibly working) devices may be					 * connected.					 */				}				else {					report(RPT_INFO, "hd_init_usb4all: USB-4-all device found");					usb4all_determine_usb_params(p, &dev->config[0].interface[0].altsetting[0]);				}			}		}	}	/* No device found at all */	if (p->usbHandle == NULL) {		report(RPT_ERR, "hd_init_usb4all: no (matching) USB-4-all device found");		return -1;	}	if (p->usbMode == -1) {		report(RPT_ERR, "hd_init_usb4all: unknown usb mode");		return -1;	}	/* allocate and initialize buffer */	if ((p->tx_buf.buffer = malloc(USB4ALL_TX_MAX)) == NULL) {		report(RPT_ERR, "hd_init_usb4all: could not allocate send buffer");		usb4all_HD44780_close(p);		return -1;	}	if ((p->rx_buf.buffer = malloc(USB4ALL_RX_MAX)) == NULL) {		report(RPT_ERR, "hd_init_usb4all: could not allocate receive buffer");		usb4all_HD44780_close(p);		return -1;	}	common_init(p, IF_4BIT);	/* replace uPause with empty one after initialization */	p->hd44780_functions->uPause = usb4all_HD44780_uPause;	/* initialize usb-4-all controller */	usb4all_init(p);	return 0;}
开发者ID:FamousBonecrusher,项目名称:lcdproc-0.5.6_MCP23008,代码行数:87,


示例17: rawhid_open

//  rawhid_open - open 1 or more devices////    Inputs://	max = maximum number of devices to open//	vid = Vendor ID, or -1 if any//	pid = Product ID, or -1 if any//	usage_page = top level usage page, or -1 if any//	usage = top level usage number, or -1 if any//    Output://	actual number of devices opened//int rawhid_open(int max, int vid, int pid, int usage_page, int usage){	struct usb_bus *bus;	struct usb_device *dev;	struct usb_interface *iface;	struct usb_interface_descriptor *desc;	struct usb_endpoint_descriptor *ep;	usb_dev_handle *u;	uint8_t buf[1024], *p;	int i, n, len, tag, ep_in, ep_out, count=0, claimed;	uint32_t val=0, parsed_usage, parsed_usage_page;	hid_t *hid;	if (first_hid) free_all_hid();	printf("rawhid_open, max=%d/n", max);	if (max < 1) return 0;	usb_init();	usb_find_busses();	usb_find_devices();	for (bus = usb_get_busses(); bus; bus = bus->next) {		for (dev = bus->devices; dev; dev = dev->next) {			if (vid > 0 && dev->descriptor.idVendor != vid) continue;			if (pid > 0 && dev->descriptor.idProduct != pid) continue;			if (!dev->config) continue;			if (dev->config->bNumInterfaces < 1) continue;			printf("device: vid=%04X, pic=%04X, with %d iface/n",				dev->descriptor.idVendor,				dev->descriptor.idProduct,				dev->config->bNumInterfaces);			iface = dev->config->interface;			u = NULL;			claimed = 0;			for (i=0; i<dev->config->bNumInterfaces && iface; i++, iface++) {				desc = iface->altsetting;				if (!desc) continue;				printf("  type %d, %d, %d/n", desc->bInterfaceClass,					desc->bInterfaceSubClass, desc->bInterfaceProtocol);				if (desc->bInterfaceClass != 3) continue;				if (desc->bInterfaceSubClass != 0) continue;				if (desc->bInterfaceProtocol != 0) continue;				ep = desc->endpoint;				ep_in = ep_out = 0;				for (n = 0; n < desc->bNumEndpoints; n++, ep++) {					if (ep->bEndpointAddress & 0x80) {						if (!ep_in) ep_in = ep->bEndpointAddress & 0x7F;						printf("    IN endpoint %d/n", ep_in);					} else {						if (!ep_out) ep_out = ep->bEndpointAddress;						printf("    OUT endpoint %d/n", ep_out);					}				}				if (!ep_in) continue;				if (!u) {					u = usb_open(dev);					if (!u) {						printf("  unable to open device/n");						break;					}				}				printf("  hid interface (generic)/n");				if (usb_get_driver_np(u, i, (char *)buf, sizeof(buf)) >= 0) {					printf("  in use by driver /"%s/"/n", buf);					if (usb_detach_kernel_driver_np(u, i) < 0) {						printf("  unable to detach from kernel/n");						continue;					}				}				if (usb_claim_interface(u, i) < 0) {					printf("  unable claim interface %d/n", i);					continue;				}				len = usb_control_msg(u, 0x81, 6, 0x2200, i, (char *)buf, sizeof(buf), 250);					printf("  descriptor, len=%d/n", len);				if (len < 2) {					usb_release_interface(u, i);					continue;				}				p = buf;				parsed_usage_page = parsed_usage = 0;				while ((tag = hid_parse_item(&val, &p, buf + len)) >= 0) {					printf("  tag: %X, val %X/n", tag, val);					if (tag == 4) parsed_usage_page = val;					if (tag == 8) parsed_usage = val;					if (parsed_usage_page && parsed_usage) break;				}				if ((!parsed_usage_page) || (!parsed_usage) ||				  (usage_page > 0 && parsed_usage_page != usage_page) ||				  (usage > 0 && parsed_usage != usage)) {					usb_release_interface(u, i);//.........这里部分代码省略.........
开发者ID:Eih3,项目名称:v0.83,代码行数:101,


示例18: WinMain

int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prev_instance,                     LPSTR cmd_line, int cmd_show){  MSG msg;  WNDCLASSEX win_class;  DEV_BROADCAST_DEVICEINTERFACE dev_if;  LoadLibrary("comctl32.dll");  win_class.cbSize = sizeof(WNDCLASSEX);     win_class.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS ;  win_class.lpfnWndProc = win_proc;  win_class.cbClsExtra = 0;  win_class.cbWndExtra = 0;  win_class.hInstance = instance;  win_class.hIcon = NULL;  win_class.hCursor = LoadCursor(NULL, IDC_ARROW);  win_class.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);  win_class.lpszMenuName = NULL;  win_class.lpszClassName = LIBUSB_WINDOW_CLASS;  win_class.hIconSm = NULL;  RegisterClassEx(&win_class);  main_win = CreateWindowEx(WS_EX_APPWINDOW| WS_EX_CONTROLPARENT,                            LIBUSB_WINDOW_CLASS,                             "TestLibUsb - Windows Version",                             WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN                             | WS_DLGFRAME,                            CW_USEDEFAULT, 0, 500, 500, NULL, NULL,                             instance, NULL);  if(!main_win)     {      return FALSE;    }  exit_button = CreateWindow("BUTTON", "Exit",                             WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,                             10, 10,                              LIBUSB_BUTTON_WIDTH, LIBUSB_BUTTON_HEIGHT,                              main_win, (HMENU) ID_EXIT, instance, NULL);  refresh_button = CreateWindow("BUTTON", "Refresh",                                WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,                                10, 100,                                 LIBUSB_BUTTON_WIDTH, LIBUSB_BUTTON_HEIGHT,                                 main_win, (HMENU) ID_REFRESH, instance,                                 NULL);  edit_box = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", NULL,                            WS_CHILD | WS_VISIBLE | WS_VSCROLL |                             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL                             | ES_AUTOHSCROLL | ES_READONLY,                             CW_USEDEFAULT, CW_USEDEFAULT,                             CW_USEDEFAULT, CW_USEDEFAULT,                            main_win, (HMENU) ID_EDIT, instance, NULL);   SendMessage(edit_box, WM_SETFONT, (WPARAM) CreateFont(13, 8, 0, 0,                                                        400, 0, 0, 0,                                                        0, 1, 2, 1,                                                        49, "Courier"), 0);  ShowWindow(main_win, cmd_show);  UpdateWindow(main_win);  BringWindowToTop(main_win);  usb_set_debug(4);  usb_init();  usb_find_busses();  on_refresh();  dev_if.dbcc_size = sizeof(dev_if);  dev_if.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;  dev_if.dbcc_classguid = GUID_DEVINTERFACE_USB_HUB;  notification_handle_hub = RegisterDeviceNotification(main_win, &dev_if, 0);  dev_if.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;  notification_handle_dev = RegisterDeviceNotification(main_win, &dev_if, 0);  while(GetMessage(&msg, NULL, 0, 0) )     {      TranslateMessage(&msg);      DispatchMessage(&msg);    }  DestroyWindow(main_win);  UnregisterClass(LIBUSB_WINDOW_CLASS, instance);  return 0;}
开发者ID:mcuee,项目名称:libusb-win32,代码行数:95,


示例19: _usb_init

/** * initialize hardware */static NftResult _usb_init(void *privdata, const char *id){        Niftylino *n = privdata;        struct usb_bus *bus;        struct usb_device *dev;        struct usb_dev_handle *h;        /* save id */        strncpy(n->id, id, sizeof(n->id));        /* get our chain */        LedChain *chain = led_hardware_get_chain(n->hw);        /* pixel-format of our chain */        LedPixelFormat *format = led_chain_get_format(chain);        /* pixelformat supported? */        NiftylinoValueWidth vw;        switch (led_pixel_format_get_bytes_per_pixel(format) /                led_pixel_format_get_n_components(format))        {                        /* 8 bit values */                case 1:                {                        vw = NIFTYLINO_8BIT_VALUES;                        break;                }                        /* 16 bit values */                case 2:                {                        vw = NIFTYLINO_16BIT_VALUES;                        break;                }                        /* unsupported format */                default:                {                        NFT_LOG(L_ERROR,                                "Unsupported format requested: %d bytes-per-pixel, %d components-per-pixel",                                led_pixel_format_get_bytes_per_pixel(format),                                led_pixel_format_get_n_components(format));                        return NFT_FAILURE;                }        }        /* find (new) busses */        usb_find_busses();        /* find (new) devices */        usb_find_devices();        /* open niftylino usb-device */        char serial[255];        /* walk all busses */        for(bus = usb_get_busses(); bus; bus = bus->next)        {                /* walk all devices on bus */                for(dev = bus->devices; dev; dev = dev->next)                {                        /* found niftylino? */                        if((dev->descriptor.idVendor != VENDOR_ID) ||                           (dev->descriptor.idProduct != PRODUCT_ID))                        {                                continue;                        }                        /* try to open */                        if(!(h = usb_open(dev)))                                /* device allready open or other error */                                continue;                        /* interface already claimed by driver? */                        char driver[1024];                        if(!(usb_get_driver_np(h, 0, driver, sizeof(driver))))                        {                                // NFT_LOG(L_ERROR, "Device already claimed by                                // /"%s/"", driver);                                continue;                        }                        /* reset device */                        usb_reset(h);                        usb_close(h);                        // ~ if(usb_reset(h) < 0)                        // ~ {                        // ~ /* reset failed */                        // ~ usb_close(h);                        // ~ continue;                        // ~ }//.........这里部分代码省略.........
开发者ID:niftylight,项目名称:niftyled-plugins,代码行数:101,


示例20: usbOpenDevice

int usbOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int _usesReportIDs){struct usb_bus      *bus;struct usb_device   *dev;usb_dev_handle      *handle = NULL;int                 errorCode = USB_ERROR_NOTFOUND;static int          didUsbInit = 0;    if(!didUsbInit){        usb_init();        didUsbInit = 1;    }    usb_find_busses();    usb_find_devices();    for(bus=usb_get_busses(); bus; bus=bus->next){        for(dev=bus->devices; dev; dev=dev->next){            if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product){                char    string[256];                int     len;                handle = usb_open(dev); /* we need to open the device in order to query strings */                if(!handle){                    errorCode = USB_ERROR_ACCESS;                    fprintf(stderr, "Warning: cannot open USB device: %s/n", usb_strerror());                    continue;                }                if(vendorName == NULL && productName == NULL){  /* name does not matter */                    break;                }                /* now check whether the names match: */                len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string));                if(len < 0){                    errorCode = USB_ERROR_IO;                    fprintf(stderr, "Warning: cannot query manufacturer for device: %s/n", usb_strerror());                }else{                    errorCode = USB_ERROR_NOTFOUND;                    /* fprintf(stderr, "seen device from vendor ->%s<-/n", string); */		    /* check product name , the is no vendor name*/                    len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string));                    if(len < 0){                          errorCode = USB_ERROR_IO;                          fprintf(stderr, "Warning: cannot query product for device: %s/n", usb_strerror());                    }else{                          errorCode = USB_ERROR_NOTFOUND;                          // fprintf(stderr, "seen product ->%s<-/n", string);                           if(strcmp(string, productName) == 0)                              break;                    }                                   }                usb_close(handle);                handle = NULL;            }        }        if(handle)            break;    }    if(handle != NULL){        int rval, retries = 3;        if(usb_set_configuration(handle, 1)){            fprintf(stderr, "Warning: could not set configuration: %s/n", usb_strerror());        }        /* now try to claim the interface and detach the kernel HID driver on         * linux and other operating systems which support the call.         */        while((rval = usb_claim_interface(handle, 0)) != 0 && retries-- > 0){#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP            if(usb_detach_kernel_driver_np(handle, 0) < 0){                fprintf(stderr, "Warning: could not detach kernel HID driver: %s/n", usb_strerror());            }#endif        }#ifndef __APPLE__        if(rval != 0)            fprintf(stderr, "Warning: could not claim interface/n");#endif/* Continue anyway, even if we could not claim the interface. Control transfers * should still work. */        errorCode = 0;        *device = handle;        usesReportIDs = _usesReportIDs;    }    return errorCode;}
开发者ID:brNX,项目名称:BootloadHID-mod,代码行数:84,


示例21: usbhidOpenDevice

int usbhidOpenDevice(usbDevice_t** device, int vendor, const char* vendorName, int product, const char* productName){	struct usb_bus*     bus;	struct usb_device*  dev;	usb_dev_handle*     handle = NULL;	int                 errorCode = USBOPEN_ERR_NOTFOUND;	static int          didUsbInit = 0;	if (!didUsbInit)	{		usb_init();		didUsbInit = 1;	}	usb_find_busses();	usb_find_devices();	for (bus = usb_get_busses(); bus; bus = bus->next)	{		for (dev = bus->devices; dev; dev = dev->next)		{			if (dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product)			{				char    string[256];				int     len;				handle = usb_open(dev); // we need to open the device in order to query strings				if (!handle)				{					errorCode = USBOPEN_ERR_ACCESS;					DEBUG_PRINT(("Warning: cannot open USB device: %s/n", usb_strerror()));					continue;				}				if (vendorName == NULL && productName == NULL)  // name does not matter					break;				// now check whether the names match:				len = usbhidGetStringAscii(handle, dev->descriptor.iManufacturer, string, sizeof(string));				if (len < 0)				{					errorCode = USBOPEN_ERR_IO;					DEBUG_PRINT(("Warning: cannot query manufacturer for device: %s/n", usb_strerror()));				} else {					errorCode = USBOPEN_ERR_NOTFOUND;					if (strcmp(string, vendorName) == 0)					{						len = usbhidGetStringAscii(handle, dev->descriptor.iProduct, string, sizeof(string));						if (len < 0)						{							errorCode = USBOPEN_ERR_IO;							DEBUG_PRINT(("Warning: cannot query product for device: %s/n", usb_strerror()));						} else {							errorCode = USBOPEN_ERR_NOTFOUND;							if (strcmp(string, productName) == 0)								break;						}					}				}				usb_close(handle);				handle = NULL;			}		}		if (handle)			break;	}	if (handle != NULL)	{		errorCode = USBOPEN_SUCCESS;		*device = (usbDevice_t*)handle;	}	return errorCode;}
开发者ID:nodep,项目名称:nrfburn,代码行数:75,


示例22: usbOpenDevice

int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp){	struct usb_bus *bus;	struct usb_device *dev;	usb_dev_handle *handle = NULL;	int errorCode = USBOPEN_ERR_NOTFOUND;    usb_find_busses();    usb_find_devices();    for(bus = usb_get_busses(); bus; bus = bus->next)	{        for(dev = bus->devices; dev; dev = dev->next)		{            if((vendorID == 0 || dev->descriptor.idVendor == vendorID) && (productID == 0 || dev->descriptor.idProduct == productID))			{                char    vendor[256], product[256], serial[256];                int     len;                handle = usb_open(dev);                				if(!handle)				{                    errorCode = USBOPEN_ERR_ACCESS;                    if(warningsFp != NULL)					{                        fprintf(warningsFp, "Warning: cannot open VID=0x%04x PID=0x%04x: %s/n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror());                    }					continue;                }                len = vendor[0] = 0;                if(dev->descriptor.iManufacturer > 0)				{                    len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, vendor, sizeof(vendor));                }                if(len < 0)				{                    errorCode = USBOPEN_ERR_ACCESS;                    if(warningsFp != NULL)					{                        fprintf(warningsFp, "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s/n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror());					}				}				else				{                    errorCode = USBOPEN_ERR_NOTFOUND;                    if(shellStyleMatch(vendor, vendorNamePattern))					{                        len = product[0] = 0;                        if(dev->descriptor.iProduct > 0)						{                            len = usbGetStringAscii(handle, dev->descriptor.iProduct, product, sizeof(product));                        }                        if(len < 0)						{                            errorCode = USBOPEN_ERR_ACCESS;                            if(warningsFp != NULL)                                fprintf(warningsFp, "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s/n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror());                        }						else						{                            errorCode = USBOPEN_ERR_NOTFOUND;                            if(shellStyleMatch(product, productNamePattern))							{                                len = serial[0] = 0;                                if(dev->descriptor.iSerialNumber > 0)								{                                    len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, serial, sizeof(serial));                                }                                if(len < 0)								{                                    errorCode = USBOPEN_ERR_ACCESS;                                    if(warningsFp != NULL)                                        fprintf(warningsFp, "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s/n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror());                                }                                if(shellStyleMatch(serial, serialNamePattern))								{                                    if(printMatchingDevicesFp != NULL)									{                                        if(serial[0] == 0)										{                                            fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=/"%s/" product=/"%s/"/n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product);                                        }										else										{                                            fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=/"%s/" product=/"%s/" serial=/"%s/"/n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product, serial);                                        }                                    }									else									{                                        break;                                    }                                }                            }                        }                    }                }                usb_close(handle);                handle = NULL;//.........这里部分代码省略.........
开发者ID:bstrysko,项目名称:The-Cogito-Project,代码行数:101,


示例23: main

int main(int argc, char** argv){    struct BENCHMARK_TEST_PARAM Test;    struct BENCHMARK_TRANSFER_PARAM* ReadTest	= NULL;    struct BENCHMARK_TRANSFER_PARAM* WriteTest	= NULL;    int key;    if (argc == 1)    {        ShowHelp();        return -1;    }	ShowCopyright();    // NOTE: This is the log level for the benchmark application.    //#if defined __ERROR_H__    usb_log_set_level(255);#endif    SetTestDefaults(&Test);    // Load the command line arguments.    if (ParseBenchmarkArgs(&Test, argc, argv) < 0)        return -1;    // Initialize the critical section used for locking    // the volatile members of the transfer params in order    // to update/modify the running statistics.    //    InitializeCriticalSection(&DisplayCriticalSection);    // Initialize the library.    usb_init();    // Find all busses.    usb_find_busses();    // Find all connected devices.    usb_find_devices();    if (Test.UseList)    {        if (GetTestDeviceFromList(&Test) < 0)            goto Done;    }    else    {        // Open a benchmark device. see Bench_Open().        Test.DeviceHandle = Bench_Open(Test.Vid, Test.Pid, Test.Intf, Test.Altf, &Test.Device);    }    if (!Test.DeviceHandle || !Test.Device)    {        CONERR("device %04X:%04X not found!/n",Test.Vid, Test.Pid);        goto Done;    }    // If "NoTestSelect" appears in the command line then don't send the control    // messages for selecting the test type.    //    if (!Test.NoTestSelect)    {        if (Bench_SetTestType(Test.DeviceHandle, Test.TestType, Test.Intf) != 1)        {            CONERR("setting bechmark test type #%d!/n%s/n", Test.TestType, usb_strerror());            goto Done;        }    }    CONMSG("Benchmark device %04X:%04X opened../n",Test.Vid, Test.Pid);    // If reading from the device create the read transfer param. This will also create    // a thread in a suspended state.    //    if (Test.TestType & TestTypeRead)    {        ReadTest = CreateTransferParam(&Test, Test.Ep | USB_ENDPOINT_DIR_MASK);        if (!ReadTest) goto Done;    }    // If writing to the device create the write transfer param. This will also create    // a thread in a suspended state.    //    if (Test.TestType & TestTypeWrite)    {        WriteTest = CreateTransferParam(&Test, Test.Ep);        if (!WriteTest) goto Done;    }    // Set configuration #1.    if (usb_set_configuration(Test.DeviceHandle, 1) < 0)    {        CONERR("setting configuration #%d!/n%s/n",1,usb_strerror());        goto Done;    }    // Claim_interface Test.Intf (Default is #0)    if (usb_claim_interface(Test.DeviceHandle, Test.Intf) < 0)//.........这里部分代码省略.........
开发者ID:DavidCussans,项目名称:eudaq-old,代码行数:101,


示例24: OpenUSBByName

//.........这里部分代码省略.........#define HAL_HEADER "usb_device_"			/* parse the hal string */			if (				/* search the last '/' char */				(p = strrchr(dirname, '/'))				/* if the string starts with "usb_device_" we continue */				&& (0 == strncmp(++p, HAL_HEADER, sizeof(HAL_HEADER)-1))				/* skip the HAL header */				&& (p += sizeof(HAL_HEADER)-1)				/* search the last '_' */				&& (p = strrchr(++p, '_'))				&& (0 == strncmp(++p, "if", 2))			   )			{				/* convert the interface number */				interface_number = atoi(p+2);			}			else				DEBUG_CRITICAL2("can't parse using libhal scheme: %s", device);			/* dirname was just a temporary variable */			dirname = NULL;		}	}#endif	if (busses == NULL)		usb_init();	(void)usb_find_busses();	(void)usb_find_devices();	busses = usb_get_busses();	if (busses == NULL)	{		DEBUG_CRITICAL("No USB busses found");		return STATUS_UNSUCCESSFUL;	}	/* is the reader_index already used? */	if (usbDevice[reader_index].handle != NULL)	{		DEBUG_CRITICAL2("USB driver with index %X already in use",			reader_index);		return STATUS_UNSUCCESSFUL;	}	/* Info.plist full patch filename */	(void)snprintf(infofile, sizeof(infofile), "%s/%s/Contents/Info.plist",		PCSCLITE_HP_DROPDIR, BUNDLE);	/* general driver info */	if (!LTPBundleFindValueWithKey(infofile, "ifdManufacturerString", keyValue, 0))	{		DEBUG_INFO2("Manufacturer: %s", keyValue);	}	else	{		DEBUG_INFO2("LTPBundleFindValueWithKey error. Can't find %s?",			infofile);		return STATUS_UNSUCCESSFUL;
开发者ID:andyvand,项目名称:pcsc-lite-clone,代码行数:67,


示例25: glcd2usb_init

/** * API: Initialize glcd2usb connection type. */intglcd2usb_init(Driver *drvthis){	PrivateData *p = (PrivateData *)drvthis->private_data;	CT_glcd2usb_data *ctd;	static int didUsbInit = 0;	struct usb_bus *bus;	struct usb_device *dev;	usb_dev_handle *handle = NULL;	int err = 0;	int rval, retries = 3;	int len;	/* Set up connection type low-level functions */	p->glcd_functions->blit = glcd2usb_blit;	p->glcd_functions->close = glcd2usb_close;	p->glcd_functions->set_backlight = glcd2usb_backlight;	p->glcd_functions->poll_keys = glcd2usb_poll_keys;	/* Allocate memory structures */	ctd = (CT_glcd2usb_data *) calloc(1, sizeof(CT_glcd2usb_data));	if (ctd == NULL) {		report(RPT_ERR, "%s/glcd2usb: error allocating connection data", drvthis->name);		return -1;	}	p->ct_data = ctd;	/*	 * Try to find and open a device. Only the first device found will be	 * recognized.	 */	if (!didUsbInit) {		usb_init();		didUsbInit = 1;	}	usb_find_busses();	usb_find_devices();	for (bus = usb_get_busses(); bus != NULL; bus = bus->next) {		for (dev = bus->devices; dev != NULL; dev = dev->next) {			if (dev->descriptor.idVendor == GLCD2USB_VID			    && dev->descriptor.idProduct == GLCD2USB_PID) {				handle = usb_open(dev);				if (!handle) {					report(RPT_WARNING, "%s/glcd2usb: cannot open USB device: %s",					       drvthis->name, usb_strerror());					continue;				}				else {					goto found_dev;				}			}		}	}found_dev:	if (handle) {		debug(RPT_DEBUG, "%s/glcd2usb: opening device succeeded", drvthis->name);	}	else {		report(RPT_ERR, "%s/glcd2usb: no GLCD2USB device found", drvthis->name);		goto err_out;	}	if (usb_set_configuration(handle, 1))		report(RPT_WARNING, "%s/glcd2usb: could not set configuration: %s",		       drvthis->name, usb_strerror());	/*	 * now try to claim the interface and detach the kernel HID driver on	 * Linux and other operating systems which support the call.	 */	while ((rval = usb_claim_interface(handle, 0)) != 0 && retries-- > 0) {#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP		if (usb_detach_kernel_driver_np(handle, 0) < 0) {			report(RPT_WARNING, "%s/glcd2usb: could not detach kernel HID driver: %s",			       drvthis->name, usb_strerror());		}#endif	}	if (rval != 0)		report(RPT_WARNING, "%s/glcd2usb: could not claim interface", drvthis->name);	/*	 * Continue anyway, even if we could not claim the interface. Control	 * transfers should still work.	 */	ctd->device = handle;	/* Query device */	memset(&(ctd->tx_buffer), 0, sizeof(ctd->tx_buffer));	len = sizeof(display_info_t);//.........这里部分代码省略.........
开发者ID:TangYang798,项目名称:lcdproc,代码行数:101,


示例26: pickit2_spi_init

int pickit2_spi_init(void){	unsigned int usedevice = 0; // FIXME: allow to select one of multiple devices	uint8_t buf[CMD_LENGTH] = {		CMD_EXEC_SCRIPT,		10,			/* Script length */		SCR_SET_PINS,		2, /* Bit-0=0(PDC Out), Bit-1=1(PGD In), Bit-2=0(PDC LL), Bit-3=0(PGD LL) */		SCR_SET_AUX,		0, /* Bit-0=0(Aux Out), Bit-1=0(Aux LL) */		SCR_VDD_ON,		SCR_MCLR_GND_OFF,	/* Let CS# float */		SCR_VPP_PWM_ON,		SCR_VPP_ON,		/* Pull CS# high */		SCR_BUSY_LED_ON,		CMD_CLR_DLOAD_BUFF,		CMD_CLR_ULOAD_BUFF,		CMD_END_OF_BUFFER	};	int spispeed_idx = 0;	char *spispeed = extract_programmer_param("spispeed");	if (spispeed != NULL) {		int i = 0;		for (; spispeeds[i].name; i++) {			if (strcasecmp(spispeeds[i].name, spispeed) == 0) {				spispeed_idx = i;				break;			}		}		if (spispeeds[i].name == NULL) {			msg_perr("Error: Invalid 'spispeed' value./n");			free(spispeed);			return 1;		}		free(spispeed);	}	int millivolt = 3500;	char *voltage = extract_programmer_param("voltage");	if (voltage != NULL) {		millivolt = parse_voltage(voltage);		free(voltage);		if (millivolt < 0)			return 1;	}	/* Here comes the USB stuff */	usb_init();	(void)usb_find_busses();	(void)usb_find_devices();	struct usb_device *dev = get_device_by_vid_pid(PICKIT2_VID, PICKIT2_PID, usedevice);	if (dev == NULL) {		msg_perr("Could not find a PICkit2 on USB!/n");		return 1;	}	msg_pdbg("Found USB device (%04x:%04x)./n", dev->descriptor.idVendor, dev->descriptor.idProduct);	pickit2_handle = usb_open(dev);	int ret = usb_set_configuration(pickit2_handle, 1);	if (ret != 0) {		msg_perr("Could not set USB device configuration: %i %s/n", ret, usb_strerror());		if (usb_close(pickit2_handle) != 0)			msg_perr("Could not close USB device!/n");		return 1;	}	ret = usb_claim_interface(pickit2_handle, 0);	if (ret != 0) {		msg_perr("Could not claim USB device interface %i: %i %s/n", 0, ret, usb_strerror());		if (usb_close(pickit2_handle) != 0)			msg_perr("Could not close USB device!/n");		return 1;	}	if (register_shutdown(pickit2_shutdown, NULL) != 0) {		return 1;	}	if (pickit2_get_firmware_version()) {		return 1;	}	/* Command Set SPI Speed */	if (pickit2_set_spi_speed(spispeed_idx)) {		return 1;	}	/* Command Set SPI Voltage */	msg_pdbg("Setting voltage to %i mV./n", millivolt);	if (pickit2_set_spi_voltage(millivolt) != 0) {		return 1;	}	/* Perform basic setup.	 * Configure pin directions and logic levels, turn Vdd on, turn busy LED on and clear buffers. */	ret = usb_interrupt_write(pickit2_handle, ENDPOINT_OUT, (char *)buf, CMD_LENGTH, DFLT_TIMEOUT);	if (ret != CMD_LENGTH) {		msg_perr("Command Setup failed (%s)!/n", usb_strerror());//.........这里部分代码省略.........
开发者ID:173210,项目名称:flashrom,代码行数:101,


示例27: lock

bool ns_usb_control::reset_device(int bus,int device_id){	#ifdef _WIN32 	return false;	#else		#ifdef USE_NEW_USB	libusb_device **devices;	int r;	ssize_t cnt;	ns_acquire_lock_for_scope lock(usb_context.libusb_lock,__FILE__,__LINE__);	libusb_context * context = (libusb_context *)usb_context.get_context();	try{	  cnt = libusb_get_device_list(context, &devices);	  if (cnt < 0)	    throw ns_ex("ns_usb_control::Could not enumerate devices!");	  try{	    libusb_device *d;	    libusb_device *requested_device(0);	    int i = 0;	    	    while ((d= devices[i++]) != NULL) {	      struct libusb_device_descriptor desc;	      unsigned long bus_number(libusb_get_bus_number(d));	      unsigned long device_address(libusb_get_device_address(d));	      if (bus_number == bus && device_address == device_id){		requested_device = d;	      }	      else		libusb_unref_device(d);//don't hold onto devices that aren't used	    }	    	    	    if(requested_device==0){	      libusb_free_device_list(devices,0);	      lock.release();	      return 0;	    }	    struct libusb_device_handle *device_handle;	    int err = libusb_open(requested_device,&device_handle);	    if (err != 0)	      throw ns_ex("ns_usb_control::Could not open device: ") << err;	    	    err = libusb_reset_device(device_handle);	    if (err){	      libusb_close(device_handle);	      libusb_unref_device(requested_device);	      throw ns_ex("ns_usb::reset_device::Could not reset device: ") << err;	    }	    libusb_close(device_handle);	    libusb_unref_device(requested_device);	  }	  catch(...){	    //don't leak device name lists	    libusb_free_device_list(devices, 0);	    throw;	  }	}	catch(...){	  //release the context so that it can be reset	  usb_context.release_context();	  throw;	}		libusb_free_device_list(devices, 0);	lock.release();	return true;#else		ns_acquire_lock_for_scope lock(usb_context.libusb_lock,__FILE__,__LINE__);	usb_find_busses();	usb_find_devices();	struct usb_device *device(0);	ssize_t i = 0;	int err = 0;	for (struct usb_bus * cur_bus = usb_busses; cur_bus; cur_bus= cur_bus->next){		int cur_bus_number(atoi(cur_bus->dirname));		for (struct usb_device *dev = cur_bus->devices; dev; dev = dev->next){			int cur_device_id(dev->devnum);			//char * filename(dev->filename);			if (cur_bus_number == bus && device_id == cur_device_id){				device = dev;				break;			}		}	}     	if(!device){		lock.release();		return 0;	}	struct usb_dev_handle *handle;	handle = usb_open(device);	try{		if (err)			throw ns_ex("ns_usb::reset_device::Could not acquire handle for device");//.........这里部分代码省略.........
开发者ID:Carsten2,项目名称:lifespan,代码行数:101,


示例28: usbOpenDevice

static int usbOpenDevice(usb_dev_handle **device, int vendor, char *vendorName, int product, char *productName){    struct usb_bus      *bus;    struct usb_device   *dev;    usb_dev_handle      *handle = NULL;    int                 errorCode = USB_ERROR_NOTFOUND;    static int          didUsbInit = 0;    if(!didUsbInit) {        didUsbInit = 1;        usb_init();    }    usb_find_busses();    usb_find_devices();    for(bus=usb_get_busses(); bus; bus=bus->next) {											// iterate over busses        for(dev=bus->devices; dev; dev=dev->next) {											// iterate over devices            if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product) { // if we have found our device                char    string[256];                int     len;                handle = usb_open(dev);														// open it                if(!handle) {																// ooops                    errorCode = USB_ERROR_ACCESS;                    fprintf(stderr, "Warning: cannot open USB device: %s/n", usb_strerror());                    continue;                }                if(vendorName == NULL && productName == NULL) { /* name does not matter */                    break;                }                /* now check whether the names match: */                len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string));                if(len < 0) {                    errorCode = USB_ERROR_IO;                    fprintf(stderr, "Warning: cannot query manufacturer for device: %s/n", usb_strerror());                } else {                    errorCode = USB_ERROR_NOTFOUND;                    /* fprintf(stderr, "seen device from vendor ->%s<-/n", string); */                    if(strcmp(string, vendorName) == 0) {                        len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string));                        if(len < 0) {                            errorCode = USB_ERROR_IO;                            fprintf(stderr, "Warning: cannot query product for device: %s/n", usb_strerror());                        } else {                            errorCode = USB_ERROR_NOTFOUND;                            /* fprintf(stderr, "seen product ->%s<-/n", string); */                            if(strcmp(string, productName) == 0)                                break;                        }                    }                }                usb_close(handle);                handle = NULL;            }        }        if(handle)            break;    }    if(handle != NULL) {        errorCode = 0;        *device = handle;    }    return errorCode;}
开发者ID:ka010,项目名称:avrBridge,代码行数:62,


示例29: main

int main(int argc, char **argv) {    int ret, vendor, product;    struct usb_device *dev;    char buf[65535], *endptr;#if 0    usb_urb *isourb;    struct timeval isotv;    char isobuf[32768];#endif    usb_init();//    usb_set_debug(255);    usb_find_busses();    usb_find_devices();/*    if (argc!=3) {	printf("usage: %s vendorID productID/n", argv[0]);	printf("ID numbers of currently attached devices:/n");	list_devices();	exit(1);    }    vendor = strtol(argv[1], &endptr, 16);    if (*endptr != '/0') {	printf("invalid vendor id/n");	exit(1);    }    product = strtol(argv[2], &endptr, 16);    if (*endptr != '/0') {	printf("invalid product id/n");	exit(1);    }*/    printf("Hladam HUAWEI E220 a prepnem na modem - bbo 06/n");    vendor = 0x12d1;    product = 0x1003;    dev = find_device(vendor, product);    assert(dev);    devh = usb_open(dev);    assert(devh);        signal(SIGTERM, release_usb_device);/*    ret = usb_get_driver_np(devh, 0, buf, sizeof(buf));    printf("usb_get_driver_np returned %d/n", ret);    if (ret == 0) {	printf("interface 0 already claimed by driver /"%s/", attempting to detach it/n", buf);	ret = usb_detach_kernel_driver_np(devh, 0);	printf("usb_detach_kernel_driver_np returned %d/n", ret);    }    ret = usb_claim_interface(devh, 0);    if (ret != 0) {	printf("claim failed with error %d/n", ret);		exit(1);    }        ret = usb_set_altinterface(devh, 0);    assert(ret >= 0);*/// BBO typ 1 = DEVICEret = usb_get_descriptor(devh, 0x0000001, 0x0000000, buf, 0x0000012);//printf("1 get descriptor returned %d, bytes: ", ret);//print_bytes(buf, ret);//printf("/n");usleep(1*1000);// BBO typ 2 = CONFIGURATIONret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000009);//printf("2 get descriptor returned %d, bytes: ", ret);//print_bytes(buf, ret);//printf("/n");usleep(1*1000);// BBO typ 2 = CONFIGURATIONret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000020);//printf("3 get descriptor returned %d, bytes: ", ret);//print_bytes(buf, ret);//printf("/n");usleep(1*1000);/*ret = usb_release_interface(devh, 0);if (ret != 0) printf("failed to release interface before set_configuration: %d/n", ret);ret = usb_set_configuration(devh, 0x0000001);printf("4 set configuration returned %d/n", ret);ret = usb_claim_interface(devh, 0);if (ret != 0) printf("claim after set_configuration failed with error %d/n", ret);ret = usb_set_altinterface(devh, 0);printf("4 set alternate setting returned %d/n", ret);usleep(50*1000);ret = usb_set_altinterface(devh, 0);printf("5 set alternate setting returned %d/n", ret);usleep(62*1000);*/ret = usb_control_msg(devh, USB_TYPE_STANDARD + USB_RECIP_DEVICE, USB_REQ_SET_FEATURE, 00000001, 0, buf, 0, 1000);printf("4 set feature request returned %d/n", ret);/*	ret = usb_release_interface(devh, 0);	assert(ret == 0);*/	ret = usb_close(devh);	assert(ret == 0);//.........这里部分代码省略.........
开发者ID:guadalinex-archive,项目名称:guadalinex-v5,代码行数:101,


示例30: usbOpenDevice

int usbOpenDevice(usb_dev_handle ** device, int vendorID,                  char *vendorNamePattern, int productID,                  char *productNamePattern, char *serialNamePattern,                  FILE * printMatchingDevicesFp, FILE * warningsFp){    struct usb_bus *bus;    struct usb_device *dev;    usb_dev_handle *handle = NULL;    int errorCode = USBOPEN_ERR_NOTFOUND;    usb_find_busses();    usb_find_devices();    for (bus = usb_get_busses(); bus; bus = bus->next) {        for (dev = bus->devices; dev; dev = dev->next) {        /* iterate over                                                                  * all devices                                                                 * on all                                                                 * busses */            if ((vendorID == 0 || dev->descriptor.idVendor == vendorID)                && (productID == 0 || dev->descriptor.idProduct == productID)) {                char vendor[256],                 product[256],                 serial[256];                int len;                handle = usb_open(dev); /* we need to open the device in order                                         * to query strings */                if (!handle) {                    errorCode = USBOPEN_ERR_ACCESS;                    if (warningsFp != NULL)                        fprintf(warningsFp,                                "Warning: cannot open VID=0x%04x PID=0x%04x: %s/n",                                dev->descriptor.idVendor,                                dev->descriptor.idProduct, usb_strerror());                    continue;                }                /*                 * now check whether the names match:                  */                len = vendor[0] = 0;                if (dev->descriptor.iManufacturer > 0) {                    len =                        usbGetStringAscii(handle, dev->descriptor.iManufacturer,                                          vendor, sizeof(vendor));                }                if (len < 0) {                    errorCode = USBOPEN_ERR_ACCESS;                    if (warningsFp != NULL)                        fprintf(warningsFp,                                "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s/n",                                dev->descriptor.idVendor,                                dev->descriptor.idProduct, usb_strerror());                } else {                    errorCode = USBOPEN_ERR_NOTFOUND;                    /*                     * printf("seen device from vendor ->%s<-/n", vendor);                      */                    if (shellStyleMatch(vendor, vendorNamePattern)) {                        len = product[0] = 0;                        if (dev->descriptor.iProduct > 0) {                            len =                                usbGetStringAscii(handle,                                                  dev->descriptor.iProduct,                                                  product, sizeof(product));                        }                        if (len < 0) {                            errorCode = USBOPEN_ERR_ACCESS;                            if (warningsFp != NULL)                                fprintf(warningsFp,                                        "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s/n",                                        dev->descriptor.idVendor,                                        dev->descriptor.idProduct,                                        usb_strerror());                        } else {                            errorCode = USBOPEN_ERR_NOTFOUND;                            /*                             * printf("seen product ->%s<-/n", product);                              */                            if (shellStyleMatch(product, productNamePattern)) {                                len = serial[0] = 0;                                if (dev->descriptor.iSerialNumber > 0) {                                    len =                                        usbGetStringAscii(handle,                                                          dev->descriptor.                                                          iSerialNumber, serial,                                                          sizeof(serial));                                }                                if (len < 0) {                                    errorCode = USBOPEN_ERR_ACCESS;                                    if (warningsFp != NULL)                                        fprintf(warningsFp,                                                "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s/n",                                                dev->descriptor.idVendor,                                                dev->descriptor.idProduct,                                                usb_strerror());                                }                                if (shellStyleMatch(serial, serialNamePattern)) {                                    if (printMatchingDevicesFp != NULL) {                                        if (serial[0] == 0) {                                            fprintf(printMatchingDevicesFp,                                                    "VID=0x%04x PID=0x%04x vendor=/"%s/" product=/"%s/"/n",                                                    dev->descriptor.idVendor,//.........这里部分代码省略.........
开发者ID:Godzil,项目名称:quickdev16,代码行数:101,



注:本文中的usb_find_busses函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ usb_find_devices函数代码示例
C++ usb_fill_int_urb函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。