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

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

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

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

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

示例1: type

LibUsb::LibUsb(int type) : type(type){    intf = NULL;    readBufIndex = 0;    readBufSize = 0;    // Initialize the library.    usb_init();    usb_set_debug(0);    usb_find_busses();    usb_find_devices();}
开发者ID:BryanF1947,项目名称:GoldenCheetah,代码行数:13,


示例2: open_usb_device

usb_dev_handle * open_usb_device(int vid, int pid){	struct usb_bus *bus;	struct usb_device *dev;	usb_dev_handle *h;	char buf[128];	int r;	usb_init();	usb_find_busses();	usb_find_devices();	//printf_verbose("/nSearching for USB device:/n");	for (bus = usb_get_busses(); bus; bus = bus->next) {		for (dev = bus->devices; dev; dev = dev->next) {			//printf_verbose("bus /"%s/", device /"%s/" vid=%04X, pid=%04X/n",			//	bus->dirname, dev->filename,			//	dev->descriptor.idVendor,			//	dev->descriptor.idProduct			//);			if (dev->descriptor.idVendor != vid) continue;			if (dev->descriptor.idProduct != pid) continue;			h = usb_open(dev);			if (!h) {				printf_verbose("Found device but unable to open");				continue;			}			#ifdef LIBUSB_HAS_GET_DRIVER_NP			r = usb_get_driver_np(h, 0, buf, sizeof(buf));			if (r >= 0) {				r = usb_detach_kernel_driver_np(h, 0);				if (r < 0) {					usb_close(h);					printf_verbose("Device is in use by /"%s/" driver", buf);					continue;				}			}			#endif			// Mac OS-X - removing this call to usb_claim_interface() might allow			// this to work, even though it is a clear misuse of the libusb API.			// normally Apple's IOKit should be used on Mac OS-X			r = usb_claim_interface(h, 0);			if (r < 0) {				usb_close(h);				printf_verbose("Unable to claim interface, check USB permissions");				continue;			}			return h;		}	}	return NULL;}
开发者ID:zrafa,项目名称:pselab,代码行数:51,


示例3: ftdi_context_refresh

int ftdi_context_refresh(ftdi_context_t* context) {  struct usb_bus* libusb_bus;  struct usb_device* libusb_device;  struct ftdi_context* libftdi_context;  int i = 0;  error_clear(&context->error);    if (context->num_references) {    if (context->num_devices) {      for (i = 0; i < context->num_devices; ++i)        ftdi_device_destroy(&context->devices[i]);            free(context->devices);      context->devices = 0;      context->num_devices = 0;    }    usb_init();    if ((usb_find_busses() > 0) && (usb_find_devices() > 0)) {      for (libusb_bus = usb_get_busses(); libusb_bus;          libusb_bus = libusb_bus->next)        for (libusb_device = libusb_bus->devices; libusb_device;            libusb_device = libusb_device->next)          if (libusb_device->descriptor.idVendor == FTDI_VENDOR_ID)            context->num_devices++;    }        if (context->num_devices) {      context->devices = malloc(context->num_devices*sizeof(ftdi_device_t));            i = 0;      for (libusb_bus = usb_get_busses(); libusb_bus;          libusb_bus = libusb_bus->next)        for (libusb_device = libusb_bus->devices; libusb_device;            libusb_device = libusb_device->next)          if (libusb_device->descriptor.idVendor == FTDI_VENDOR_ID) {        libftdi_context = ftdi_new();        ftdi_init(libftdi_context);              ftdi_device_init(&context->devices[i], libftdi_context, libusb_bus,          libusb_device);        i++;      }    }  }  else    error_set(&context->error, FTDI_ERROR_INVALID_CONTEXT);    return error_get(&context->error);}
开发者ID:engenhariaeletronica3,项目名称:tulibs,代码行数:51,


示例4: find_device

//--------------------------------------------------------------------------void find_device(t_heavybox *x) {	usb_dev_handle      *handle = NULL;	struct usb_bus      *bus;	struct usb_device   *dev;	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 == USBDEV_SHARED_VENDOR && dev->descriptor.idProduct == USBDEV_SHARED_PRODUCT){                char    string[256];                int     len;                handle = usb_open(dev); /* we need to open the device in order to query strings */                if(!handle){                    error ("Warning: cannot open USB device: %s", usb_strerror());                    continue;                }                /* now find out whether the device actually is heavybox */                len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string));                if(len < 0){                    post("heavybox: warning: cannot query manufacturer for device: %s", usb_strerror());                    goto skipDevice;                }                if(strcmp(string, USB_CFG_VENDOR_NAME) != 0)                    goto skipDevice;                len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string));                if(len < 0){                    post("heavybox: warning: cannot query product for device: %s", usb_strerror());                    goto skipDevice;                }                if(strcmp(string, USB_CFG_DEVICE_NAME) == 0)                    break;				skipDevice:                usb_close(handle);                handle = NULL;            }        }        if(handle)            break;    }    if(!handle){        post("Could not find USB device workinprogress.ca/heavybox");		x->dev_handle = NULL;	} else {		 x->dev_handle = handle;		 post("Found USB device workinprogress.ca/heavybox");	}}
开发者ID:patricksebastien,项目名称:heavybox,代码行数:52,


示例5: usb_init

static usb_dev_handle *find_usb_device(uint16_t VID, uint16_t PID, uint8_t interface,		char *serialstring, char *productstring){	usb_dev_handle *dev_handle = NULL;	struct usb_bus *busses;	struct usb_bus *bus;	struct usb_device *dev;	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 == VID)			    && (dev->descriptor.idProduct == PID)) {				dev_handle = usb_open(dev);				if (NULL == dev_handle) {					LOG_ERROR("failed to open %04X:%04X, %s", VID, PID,						usb_strerror());					continue;				}				/* check description string */				if ((productstring != NULL && !usb_check_string(dev_handle,						dev->descriptor.iProduct, productstring, NULL, 0))					|| (serialstring != NULL && !usb_check_string(dev_handle,								dev->descriptor.iSerialNumber, serialstring, NULL, 0))) {					usb_close(dev_handle);					dev_handle = NULL;					continue;				}				if (usb_claim_interface(dev_handle, interface) != 0) {					LOG_ERROR(ERRMSG_FAILURE_OPERATION_MESSAGE,						"claim interface", usb_strerror());					usb_close(dev_handle);					dev_handle = NULL;					continue;				}				if (dev_handle != NULL)					return dev_handle;			}		}	}	return dev_handle;}
开发者ID:01org,项目名称:CODK-A-Flashpack,代码行数:50,


示例6: _ykusb_start

int _ykusb_start(void){	int rc;	usb_init();	rc = usb_find_busses();	if (rc >= 0)		rc = usb_find_devices();	if (rc >= 0)		return 1;	yk_errno = YK_EUSBERR;	return 0;}
开发者ID:bradfa,项目名称:yubikey-personalization,代码行数:14,


示例7: main

int main(int argc, char *argv[]) {    struct usb_bus      *bus;    struct usb_device   *dev;    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 == LCD2USB_VID) &&                     (dev->descriptor.idProduct == LCD2USB_PID)) {                handle = usb_open(dev);                break;            }        }    }    if(!handle) {        fprintf(stderr, "Error: Could not find LCD2USB device/n");        exit(-1);    }    lcd_clear();    int i = 0;    while (!feof(stdin)) {        char line[1024];        fgets(line, sizeof(line), stdin);        if (feof(stdin)) break;        line[strlen(line)-1] = '/0';        if(strlen(line) == 0) {            lcd_clear();            lcd_clear();            i = 0;            continue;        }        lcd_write(line);        i += strlen(line);        while (i % 20 != 0) {            lcd_write(" ");            i++;        }    }    usb_close(handle);    return 0;}
开发者ID:CarlKenner,项目名称:psmoveapi,代码行数:50,


示例8: xusb_init

static void xusb_init(){	if (!initizalized) {		xtalk_parse_options();		if (!xtalk_option_no_lock())			xusb_lock_usb();		usb_init();		usb_find_busses();		usb_find_devices();		initizalized = 1;		if (!xtalk_option_no_lock())			xusb_unlock_usb();	}}
开发者ID:MattheusNiels,项目名称:BackupCerberus,代码行数:14,


示例9: gp_port_usb_init

static int gp_port_usb_init (GPPort *port){	port->pl = malloc (sizeof (GPPortPrivateLibrary));	if (!port->pl)		return (GP_ERROR_NO_MEMORY);	memset (port->pl, 0, sizeof (GPPortPrivateLibrary));	port->pl->config = port->pl->interface = port->pl->altsetting = -1;	usb_init ();	usb_find_busses ();	usb_find_devices ();	return (GP_OK);}
开发者ID:jcoenraadts,项目名称:libgphoto2,代码行数:15,


示例10: rf2500_open

transport_t rf2500_open(const char *devpath, const char *requested_serial){	struct rf2500_transport *tr = malloc(sizeof(*tr));	struct usb_device *dev;	char buf[64];	if (!tr) {		pr_error("rf2500: can't allocate memory");		return NULL;	}	tr->base.destroy = usbtr_destroy;	tr->base.send = usbtr_send;	tr->base.recv = usbtr_recv;	usb_init();	usb_find_busses();	usb_find_devices();	if (devpath)		dev = usbutil_find_by_loc(devpath);	else		dev = usbutil_find_by_id(USB_FET_VENDOR, USB_FET_PRODUCT,					 requested_serial);	if (!dev) {		free(tr);		return NULL;	}	if (open_device(tr, dev) < 0) {		printc_err("rf2500: failed to open RF2500 device/n");		return NULL;	}	/* Flush out lingering data.	 *	 * The timeout apparently doesn't work on OS/X, and this loop	 * just hangs once the endpoint buffer empties.	 */#ifndef __APPLE__	while (usb_bulk_read(tr->handle, USB_FET_IN_EP,			     buf, sizeof(buf),			     100) > 0);#endif	return (transport_t)tr;}
开发者ID:Murali8051,项目名称:Aurava,代码行数:48,


示例11: while

void *p_trbs_thread(void *parameters) {	struct usb_bus *bus;	struct usb_device *device;	struct usb_dev_handle *handler;	struct s_exception *exception = NULL;	struct s_trbs_parameters *local_parameters = (struct s_trbs_parameters *)parameters;	int index, append;	while ((p_trbs_thread_continue(local_parameters->object)) && (usleep(local_parameters->sleep)==0)) {		d_object_lock(local_parameters->object->search_semaphore);		if ((usb_find_busses()) | (usb_find_devices())) {			for (bus = usb_get_busses(); bus; bus = bus->next)				for (device = bus->devices; device; device = device->next)					if (!p_trbs_thread_already(local_parameters->object, device)) {						append = d_false;						if ((handler = usb_open(device))) {								if (p_trb_check(device, handler, NULL)) {								d_try {									if ((local_parameters->trb_handle) &&											(local_parameters->trb_handle(f_trb_new(NULL, device, handler),														      local_parameters->trb_data)))										append = d_true;									else										usb_close(handler);								} d_catch(exception) {									/* here we have an already acquired device */									usb_close(handler);								} d_endtry;							} else if ((local_parameters->dev_handle) && (local_parameters->dev_handle(device, handler,											local_parameters->dev_data)))								append = d_true;							else								usb_close(handler);						}						if (append)							for (index = 0; index < d_trbs_slots_size; index++)								if (!local_parameters->object->devices[index].device) {									local_parameters->object->devices[index].device = device;									local_parameters->object->devices[index].referenced = d_true;									break;								}					}			for (index = 0; index < d_trbs_slots_size; index++) {				if (local_parameters->object->devices[index].device)					if (!local_parameters->object->devices[index].referenced)						local_parameters->object->devices[index].device = NULL;				local_parameters->object->devices[index].referenced = d_false;			}		}
开发者ID:nardinan,项目名称:serenity,代码行数:48,


示例12: find_usb_device

/* find a compatible USB receiver and return a usb_device, * or NULL on failure. */static struct usb_device* find_usb_device(void){	struct usb_bus* usb_bus;	struct usb_device* dev;	usb_init();	usb_find_busses();	usb_find_devices();	for (usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) {		for (dev = usb_bus->devices; dev; dev = dev->next)			if (is_device_ok(dev))				return dev;	}	return NULL;            /* no suitable device found */}
开发者ID:andyvand,项目名称:LIRC,代码行数:18,


示例13: main

int main(void){    usb_dev_handle *dev = NULL; /* the device handle */    char tmp[BUF_SIZE];    usb_init(); /* initialize the library */    usb_find_busses(); /* find all busses */    usb_find_devices(); /* find all connected devices */    if(!(dev = open_dev()))    {        printf("error: device not found!/n");        return 0;    }    if(usb_set_configuration(dev, 1) < 0)    {        printf("error: setting config 1 failed/n");        usb_close(dev);        return 0;    }    if(usb_claim_interface(dev, 0) < 0)    {        printf("error: claiming interface 0 failed/n");        usb_close(dev);        return 0;    }    if(usb_bulk_write(dev, EP_OUT, tmp, sizeof(tmp), 5000)            != sizeof(tmp))    {        printf("error: bulk write failed/n");    }    if(usb_bulk_read(dev, EP_IN, tmp, sizeof(tmp), 5000)            != sizeof(tmp))    {        printf("error: bulk read failed/n");    }    usb_release_interface(dev, 0);    usb_close(dev);    return 0;}
开发者ID:variability,项目名称:leon3,代码行数:47,


示例14: drv_BW_open

static int drv_BW_open(void){    struct usb_bus *busses, *bus;    struct usb_device *dev;    lcd = NULL;    info("%s: scanning USB for BWCT 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) {	    int c;	    if (dev->descriptor.idVendor != LCD_USB_VENDOR)		continue;	    /* Loop through all of the configurations */	    for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {		int i;		for (i = 0; i < dev->config[c].bNumInterfaces; i++) {		    int a;		    for (a = 0; a < dev->config[c].interface[i].num_altsetting; a++) {			if ((dev->descriptor.idProduct == LCD_USB_DEVICE) ||			    ((dev->config[c].interface[i].altsetting[a].bInterfaceClass == 0xff) &&			     (dev->config[c].interface[i].altsetting[a].bInterfaceSubClass == 0x01))) {			    info("%s: found BWCT USB LCD on bus %s device %s", Name, bus->dirname, dev->filename);			    interface = i;			    lcd = usb_open(dev);			    if (usb_claim_interface(lcd, interface) < 0) {				error("%s: usb_claim_interface() failed!", Name);				return -1;			    }			    return 0;			}		    }		}	    }	}    }    return -1;}
开发者ID:KCFTech,项目名称:lcd4linux,代码行数:46,


示例15: olimex_open

transport_t olimex_open(const char *devpath, const char *requested_serial){	struct olimex_transport *tr = malloc(sizeof(*tr));	struct usb_device *dev;	char buf[64];	if (!tr) {		pr_error(__FILE__": can't allocate memory");		return NULL;	}	tr->base.destroy = usbtr_destroy;	tr->base.send = usbtr_send;	tr->base.recv = usbtr_recv;	usb_init();	usb_find_busses();	usb_find_devices();	if (devpath) {		dev = usbutil_find_by_loc(devpath);	} else {		dev = usbutil_find_by_id(USB_FET_VENDOR, V1_PRODUCT,					 requested_serial);		if (!dev)			dev = usbutil_find_by_id(USB_FET_VENDOR, V2_PRODUCT,						 requested_serial);	}	if (!dev) {		free(tr);		return NULL;	}	if (open_device(tr, dev) < 0) {		printc_err(__FILE__ ": failed to open Olimex device/n");		return NULL;	}	/* Flush out lingering data */	while (usb_bulk_read(tr->handle, tr->in_ep,			     buf, sizeof(buf),			     100) > 0);	return (transport_t)tr;}
开发者ID:Murali8051,项目名称:Aurava,代码行数:46,


示例16: Hardware

HardwareThunder::HardwareThunder(QObject *parent) :    Hardware(parent),    m_usbHandler(NULL){    usb_init();    usb_find_busses();    usb_find_devices();    struct usb_bus *busses = usb_get_busses();    for (struct usb_bus *bus = busses; bus; bus = bus->next)    {        struct usb_device *dev;        for (dev = bus->devices; dev; dev = dev->next)        {            if (dev->descriptor.idVendor == 0x2123 &&                    dev->descriptor.idProduct == 0x1010)            {                qDebug() << "Found USB Raketenwerfer";                m_usbHandler = usb_open(dev);                if (m_usbHandler)                {                    int claimed = usb_claim_interface(m_usbHandler, 0);                    if (claimed == 0)                    {                        qDebug() << "USB claimed";                        // TODO                        return;                    }                    else                    {                        qWarning() << "Error claiming USB interface:" << usb_strerror();                    }                }                else                {                    qWarning() << "Could not open USB device:" << usb_strerror();                }            }        }    }    qWarning() << "Could not find USB device";}
开发者ID:RazZziel,项目名称:3Sentry,代码行数:46,


示例17: usb_init

static struct usb_device *findDev(uint16_t vendor, uint16_t product) {  struct usb_bus *bus;  struct usb_device *dev;  struct usb_bus *busses;  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 == vendor) && (dev->descriptor.idProduct == product)) {				return dev;			}	return NULL;}
开发者ID:johnlepikhin,项目名称:catbeat,代码行数:17,


示例18: usb_set_debug

bool LibUsb::find(){    usb_set_debug(0);    usb_find_busses();    usb_find_devices();    switch (type) {    // Search USB busses for USB2 ANT+ stick host controllers    default:    case TYPE_ANT: return findAntStick();              break;    case TYPE_FORTIUS: return findFortius();              break;    }}
开发者ID:WaterworthD,项目名称:GoldenCheetah,代码行数:17,


示例19: usb_init

static struct usb_device *device_init(void){    struct usb_bus *usb_bus;    struct usb_device *dev;    usb_init();    usb_find_busses();    usb_find_devices();    for (usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) {        for (dev = usb_bus->devices; dev; dev = dev->next) {            if ((dev->descriptor.idVendor == G9X_VENDOR_ID) && (dev->descriptor.idProduct == G9X_PRODUCT_ID))        	return dev;        }    }    return NULL;}
开发者ID:pschmitt,项目名称:aur-g9xled,代码行数:17,


示例20: setup_libusb_access

usb_dev_handle* setup_libusb_access() {  usb_dev_handle *lvr_winusb;  if (debug) {    usb_set_debug(255);  }  else {    usb_set_debug(0);  }  usb_init();  usb_find_busses();  usb_find_devices();  if (!(lvr_winusb = find_lvr_winusb())) {    printf("Couldn't find the USB device, exiting./n");    return NULL;  }  usb_detach(lvr_winusb, INTERFACE1);  usb_detach(lvr_winusb, INTERFACE2);  // reset device  if (usb_reset(lvr_winusb) != 0) {    printf("Could not reset device./n");    return NULL;  }  if (usb_set_configuration(lvr_winusb, 0x01) < 0) {    printf("Could not set configuration 1./n");    return NULL;  }  // Microdia tiene 2 interfaces  if (usb_claim_interface(lvr_winusb, INTERFACE1) < 0) {    printf("Could not claim interface./n");    return NULL;  }  if (usb_claim_interface(lvr_winusb, INTERFACE2) < 0) {    printf("Could not claim interface./n");    return NULL;  }  return lvr_winusb;}
开发者ID:stefansundin,项目名称:pcsensor-temper,代码行数:46,


示例21: destroyList

void UDMXOut::rescanDevices(){	struct usb_device* dev;	struct usb_bus* bus;	/* Treat all devices as dead first, until we find them again. Those	   that aren't found, get destroyed at the end of this function. */	QList <UDMXDevice*> destroyList(m_devices);	usb_find_busses();	usb_find_devices();	/* Iterate thru all buses */	for (bus = usb_get_busses(); bus != NULL; bus = bus->next)	{		/* Iterate thru all devices in each bus */		for (dev = bus->devices; dev != NULL; dev = dev->next)		{			UDMXDevice* udev;			udev = device(dev);			if (udev != NULL)			{				/* We already have this device and it's still				   there. Remove from the destroy list and				   continue iterating. */				destroyList.removeAll(udev);				continue;			}			else if (UDMXDevice::isUDMXDevice(dev) == true)			{				/* This is a new device. Create and append. */				udev = new UDMXDevice(this, dev);				m_devices.append(udev);			}		}	}	/* Destroy those devices that were no longer found. */	while (destroyList.isEmpty() == false)	{		UDMXDevice* udev = destroyList.takeFirst();		m_devices.removeAll(udev);		delete udev;	}}
开发者ID:speakman,项目名称:qlc,代码行数:46,


示例22: usb_ingenic_init

int usb_ingenic_init(struct ingenic_dev *ingenic_dev,		     const char *bus_filter,		     const char *dev_filter){	int num_ingenic, status = -1;	usb_init(); 	/* usb_set_debug(255); */	usb_find_busses();	usb_find_devices();	num_ingenic = get_ingenic_device(ingenic_dev, bus_filter, dev_filter);	if (num_ingenic == 0) {		fprintf(stderr, "Error - no XBurst device found/n");		goto out;	} else if (num_ingenic > 1) {		fprintf(stderr, "Error - too many XBurst devices found: %i/n",			num_ingenic);		goto out;	}	ingenic_dev->usb_handle = usb_open(ingenic_dev->usb_dev);	if (!ingenic_dev->usb_handle) {		fprintf(stderr, "Error - can't open XBurst device: %s/n",			usb_strerror());		goto out;	}	if (get_ingenic_interface(ingenic_dev)) {		fprintf(stderr, "Error - can't find XBurst interface/n");		goto out;	}	if (usb_claim_interface(ingenic_dev->usb_handle,				ingenic_dev->interface)) {		fprintf(stderr, "Error - can't claim XBurst interface: %s/n",			usb_strerror());		goto out;	}	status = 0;out:	return status;}
开发者ID:bukinr,项目名称:ingenic-boot,代码行数:46,


示例23: usb_find_busses

/* This project uses the free shared default VID/PID. If you want to see an * example device lookup where an individually reserved PID is used, see our * RemoteSensor reference implementation. */static usb_dev_handle   *findDevice(void){struct usb_bus      *bus;struct usb_device   *dev;usb_dev_handle      *handle = 0;    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 == USBDEV_SHARED_VENDOR && dev->descriptor.idProduct == USBDEV_SHARED_PRODUCT){                char    string[256];                int     len;                handle = usb_open(dev); /* we need to open the device in order to query strings */                if(!handle){                    fprintf(stderr, "Warning: cannot open USB device: %s/n", usb_strerror());                    continue;                }                len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string));                if(len < 0){                    fprintf(stderr, "warning: cannot query manufacturer for device: %s/n", usb_strerror());                    goto skipDevice;                }                if(strcmp(string, "www.fischl.de") != 0)                    goto skipDevice;                len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string));                if(len < 0){                    fprintf(stderr, "warning: cannot query product for device: %s/n", usb_strerror());                    goto skipDevice;                }		//  fprintf(stderr, "seen product ->%s<-/n", string);                 if(strcmp(string, "AVRUSBBoot") == 0)                    break;skipDevice:                usb_close(handle);                handle = NULL;            }        }        if(handle)            break;    }    if(!handle)        fprintf(stderr, "Could not find USB device www.fischl.de/AVRUSBBoot/n");    return handle;}
开发者ID:optixx,项目名称:megaledmatrix,代码行数:49,


示例24: micronucleus_connect

micronucleus* micronucleus_connect() {  micronucleus *nucleus = NULL;  struct usb_bus *busses;    // intialise usb and find micronucleus device  usb_init();  usb_find_busses();  usb_find_devices();    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 micronucleus */      if (dev->descriptor.idVendor == MICRONUCLEUS_VENDOR_ID && dev->descriptor.idProduct == MICRONUCLEUS_PRODUCT_ID)  {        nucleus = malloc(sizeof(micronucleus));        nucleus->version.major = (dev->descriptor.bcdUSB >> 8) & 0xFF;        nucleus->version.minor = dev->descriptor.bcdUSB & 0xFF;                if (nucleus->version.major > MICRONUCLEUS_MAX_MAJOR_VERSION) {	        fprintf(stderr, "Warning: device with unknown new version of Micronucleus detected./n");	        fprintf(stderr, "This tool doesn't know how to upload to this new device. Updates may be available./n");	        fprintf(stderr, "Device reports version as: %d.%d/n", nucleus->version.major, nucleus->version.minor);	        return NULL;        }                nucleus->device = usb_open(dev);                // get nucleus info        unsigned char buffer[6];        int res = usb_control_msg(nucleus->device, 0xC0, 0, 0, 0, buffer, 6, MICRONUCLEUS_USB_TIMEOUT);        assert(res >= 4);                nucleus->flash_size = (buffer[0]<<8) + buffer[1];        nucleus->data_length = (buffer[5]<<8) + buffer[4];        nucleus->page_size = buffer[2];        nucleus->pages = (nucleus->flash_size / nucleus->page_size);        if (nucleus->pages * nucleus->page_size < nucleus->flash_size) nucleus->pages += 1;        nucleus->write_sleep = buffer[3];        nucleus->erase_sleep = nucleus->write_sleep * nucleus->pages;      }    }  }
开发者ID:deanmao,项目名称:dojo_member_tool,代码行数:45,


示例25: bulk_init

static intbulk_init(const char *device){	struct usb_bus *bus;	struct usb_device *dev;	usb_init();	if (verbose)		usb_set_debug(verbose);	usb_find_busses();	usb_find_devices();	xsv_handle = NULL;	for (bus = usb_busses; bus; bus = bus->next) {		for (dev = bus->devices; dev; dev = dev->next) {			if (device && strcmp(dev->filename, device) != 0)				continue;			if (dev->descriptor.idVendor == 0x2207 &&				(dev->descriptor.idProduct == 0x290a ||				dev->descriptor.idProduct == 0x292a ||				dev->descriptor.idProduct == 0x281a)) {				xsv_handle = usb_open(dev);				if (verbose) {					printf("using rockchip device @ %s/n",						dev->filename);				}				break;			}		}	}	if (xsv_handle) {		usb_set_configuration(xsv_handle,1);		usb_claim_interface(xsv_handle,0);		usb_set_altinterface(xsv_handle,0);		return 0;	} else {		return -1;	}}
开发者ID:jaretcantu,项目名称:rkutils,代码行数:45,


示例26: littlewire_search

int littlewire_search(){  struct usb_bus *bus;  struct usb_device *dev;  usb_init();  usb_find_busses();  usb_find_devices();  lw_totalDevices = 0;  for (bus = usb_busses; bus; bus = bus->next)  {    for (dev = bus->devices; dev; dev = dev->next)    {      usb_dev_handle *udev;      char description[256];      char string[256];      int ret, i;      if((dev->descriptor.idVendor == VENDOR_ID) && (dev->descriptor.idProduct == PRODUCT_ID))      {        udev = usb_open(dev);        if (udev)        {          if (dev->descriptor.iSerialNumber)          {            ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof(string));            if (ret > 0)            {              lwResults[lw_totalDevices].serialNumber = atoi(string);              lwResults[lw_totalDevices].lw_device = dev;              lw_totalDevices++;            } else {              printf("Connection error! Try creating a udev rule or running with sudo./n");            }          }          usb_close(udev);        }      }    }  }  return lw_totalDevices;}
开发者ID:hybridgroup,项目名称:cylon-digispark,代码行数:45,


示例27: v2u_open_driver_idx

/** * Opens driver and returns the handle. Returns NULL on failure. */V2U_HANDLE v2u_open_driver_idx(int idx){    int index = 0;    struct usb_bus * bus;    usb_init();    usb_find_busses();    usb_find_devices();    for (bus = usb_get_busses(); bus; bus = bus->next) {        struct usb_device *dev;        for (dev = bus->devices; dev; dev = dev->next) {            if (VGA2USB_IS_ANY(                    dev->descriptor.idVendor,                    dev->descriptor.idProduct,                    dev->descriptor.iProduct,                    dev->descriptor.iManufacturer)) {                if (index == idx) {                    int fd;                    char name[256];                    sprintf(name,"/proc/bus/usb/%s/%s",                            dev->bus->dirname,                            dev->filename);                    fd = open(name, O_RDWR);                    if (fd < 0) {#if DEBUG                        fprintf(stderr,"cannot open %s: %s/n",name,strerror(errno));#endif                    } else {                        V2U_DRIVER* driver = malloc(sizeof(V2U_DRIVER));                        if (driver) {                            driver->fd = fd;                            return driver;                        }                        close(fd);                    }                    break;                } else {                    index++;                }            }        }    }    return NULL;}
开发者ID:aharrison24,项目名称:HAL,代码行数:48,


示例28: usbsign_open

int usbsign_open(int vendorid, int productid,                 int interface, usbsign_handle** dev) {    usb_init();    usb_find_busses();    usb_find_devices();    struct usb_bus* bus;    struct usb_device* usbdev;    int found = 0;    for (bus = usb_get_busses(); bus; bus = bus->next) {        config_debug("BUS: %s",bus->dirname);        for (usbdev = bus->devices; usbdev; usbdev = usbdev->next) {            struct usb_device_descriptor *desc = &(usbdev->descriptor);            config_debug("    Device: %s", usbdev->filename);            config_debug("        %x:%x",desc->idVendor,desc->idProduct);            if (usbdev->descriptor.idVendor == vendorid &&                usbdev->descriptor.idProduct == productid) {                found = 1;                break;            }        }        if (found > 0) {            break;        }    }    if (found > 0) {        *dev = usb_open(usbdev);    } else {        *dev = NULL;    }    if (*dev == NULL) {        config_error("Could not find/open USB device with vid=0x%X pid=0x%X. Is the sign plugged in?",                vendorid, productid);        return -1;    }    int ret = usb_claim_interface(*dev, interface);    if (ret < 0) {        config_error("Could not claim device (%d)", ret);        return ret;    }    return 0;}
开发者ID:EvanDotPro,项目名称:bbusb,代码行数:45,



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


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