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

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

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

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

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

示例1: iterate_dfu_devices

/* Iterate over all matching DFU capable devices within system */static int iterate_dfu_devices(struct dfu_if *dif,    int (*action)(struct usb_device *dev, void *user), void *user){	struct usb_bus *usb_bus;	struct usb_device *dev;	/* Walk the tree and find our device. */	for (usb_bus = usb_get_busses(); NULL != usb_bus;	     usb_bus = usb_bus->next) {		for (dev = usb_bus->devices; NULL != dev; dev = dev->next) {			int retval;			if (dif && (dif->flags &			    (DFU_IFF_VENDOR|DFU_IFF_PRODUCT)) &&		    	    (dev->descriptor.idVendor != dif->vendor ||		     	    dev->descriptor.idProduct != dif->product))				continue;			if (dif && (dif->flags & DFU_IFF_DEVNUM) &&		    	    (atoi(usb_bus->dirname) != dif->bus ||		     	    dev->devnum != dif->devnum))				continue;			if (!count_dfu_interfaces(dev))				continue;			retval = action(dev, user);			if (retval)				return retval;		}	}	return 0;}
开发者ID:sgiessl,项目名称:dfu-util-branch,代码行数:32,


示例2: main

int main(int argc, char *argv[]){  struct usb_bus *bus;  if (argc > 1 && !strcmp(argv[1], "-v"))    verbose = 1;  usb_init();  usb_set_debug(0);  usb_find_busses();  usb_find_devices();  for (bus = usb_get_busses(); bus; bus = bus->next) {    if (bus->root_dev && !verbose)      print_device(bus->root_dev, 0);    else {      struct usb_device *dev;      for (dev = bus->devices; dev; dev = dev->next)        print_device(dev, 0);    }  }  return 0;}
开发者ID:Habib2014,项目名称:tinyos-2.x-contrib,代码行数:26,


示例3: open_usb

uint8_t open_usb(usb_dev_handle **handle) {	uint16_t vid = 0x16c0;	uint16_t pid = 0x05df;	struct usb_bus *bus;	struct usb_device *dev;	usb_dev_handle *target = NULL;	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 == vid && dev->descriptor.idProduct == pid) {				target = usb_open(dev);			}		}	}	//return (usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0);	//return (usbOpenDevice(&handle, 0x16c0, NULL, 0x05df, NULL) != 0);	if (target != NULL) {		*handle = target;		return 1;	} else {		return 0;	}}
开发者ID:wertarbyte,项目名称:PhysicalPixel,代码行数:26,


示例4: easyAVR_Open

struct usb_dev_handle* easyAVR_Open(){  struct usb_bus *busses;  usb_set_debug(2);  usb_init();  usb_find_busses();  usb_find_devices();  busses = usb_get_busses();  struct usb_dev_handle* usb_handle;  struct usb_bus *bus;  unsigned char send_data=0xff;  for (bus = busses; bus; bus = bus->next)  {    struct usb_device *dev;    for (dev = bus->devices; dev; dev = dev->next)    {      if (dev->descriptor.idVendor == 0x0400)      {        int i,stat;        //printf("vendor: %i/n",dev->descriptor.idVendor);        usb_handle = usb_open(dev);        stat = usb_set_configuration (usb_handle,1);	return usb_handle;      }    }  }}
开发者ID:BackupTheBerlios,项目名称:usbn2mc-svn,代码行数:35,


示例5: libusb_get_device_list

ssize_t libusb_get_device_list(libusb_context* ctx, libusb_device*** list){	// libusb_device*** list demystified:	// libusb_device*** is the C equivalent to libusb_device**& in C++; such declaration	// allows the scope of this function libusb_get_device_list() to write on a variable	// of type libusb_device** declared within the function scope of the caller.	// libusb_device** is better understood as libusb_device*[], which is an array of	// pointers of type libusb_device*, each pointing to a struct that holds actual data.	usb_find_busses();	usb_find_devices();	usb_bus* bus = usb_get_busses();	std::vector<struct usb_device*> vDevices;	while (bus)	{		struct usb_device* device (bus->devices);		while (device)		{			vDevices.push_back(device);			device = device->next;		};		bus = bus->next;	};	*list = (libusb_device**) malloc(vDevices.size()*sizeof(struct usb_device*));	memcpy(*list, &vDevices[0], vDevices.size()*sizeof(struct usb_device*));	// the number of devices in the outputted list, or LIBUSB_ERROR_NO_MEM on memory allocation failure.	return(vDevices.size());}
开发者ID:CFC-Media-Lab,项目名称:unification,代码行数:27,


示例6: openUSBDevice

void openUSBDevice(void){	usb_init();	usb_find_busses();	usb_find_devices();		USBbus=usb_get_busses();	current_device=NULL;	while(USBbus!=NULL)		{USBdevice=USBbus->devices;		while(USBdevice!=NULL)			{if ((USBdevice->descriptor.idVendor==0x03a3)&&(USBdevice->descriptor.idProduct==0x2b49))				current_device=USBdevice;			USBdevice=USBdevice->next;}		USBbus=USBbus->next;}	if (current_device==NULL)		{printf("/n/nCould not find device/n/n");exit(0);}	fflush(stdout);	current_handle=usb_open(current_device);	if (usb_claim_interface(current_handle, 0) <0)	{		printf("Error - usb_claim_interface/n");		exit(0);	}	if (usb_clear_halt(current_handle,out_ep) <0)	{		printf("Error - usb_clear_halt EP %d/n",out_ep);		exit(0);	}}
开发者ID:Sean3Don,项目名称:opentribot,代码行数:32,


示例7: usb_connect

usb_dev_handle* usb_connect(){    struct usb_bus *bus;    struct usb_device *dev_tmp;    int ret;    ret=usb_find_busses();    ret=usb_find_devices();    for(bus = usb_get_busses(); bus; bus = bus->next)    {        for(dev_tmp = bus->devices; dev_tmp; dev_tmp = dev_tmp->next)        {            if(dev_tmp->descriptor.idVendor == MY_VID                    && dev_tmp->descriptor.idProduct == MY_PID)            {                usb_dev_handle *dev = usb_open(dev_tmp);                if(dev==NULL)                    break;                ret=usb_set_configuration(dev, 1);                ret=usb_claim_interface(dev, 1);                return dev;            }        }    }    return NULL;}
开发者ID:omega-photonics,项目名称:stm32-DTS_rev_C_control,代码行数:29,


示例8: main

int main(void) {    struct usb_bus *bus;    struct usb_device *dev;    usb_dev_handle *udev;    int dev_found, ret;    char buffer[8];        usb_init();    usb_find_busses();    usb_find_devices();    udev = NULL;    dev_found = FALSE;    for (bus = usb_get_busses(); bus && !dev_found; bus = bus->next) {        for (dev = bus->devices; dev && !dev_found; dev = dev->next) {            if ((dev->descriptor.idVendor == 0x04D8) && (dev->descriptor.idProduct == 0x0001)) {                dev_found = TRUE;                udev = usb_open(dev);            }        }    }    if (!dev_found) {        printf("No matching device found.../n");    }    if (udev) {        ret = usb_control_msg(udev, USB_TYPE_VENDOR | USB_RECIP_DEVICE, SET_RA0, 0, 0, buffer, 0, 100);        if (ret < 0) {            printf("Unable to send vendor specific request, ret = %d.../n", ret);        usb_close(udev);        }    }}
开发者ID:JonathanFraser,项目名称:pic-usb,代码行数:33,


示例9: open

int open (const char *pathname, int flags, ...) {	static int (*func) (const char *, int, mode_t) = NULL;	mode_t mode = 0;	va_list args;	int fd;	if (!func)		func = (int (*) (const char *, int, mode_t)) dlsym (RTLD_NEXT, "open");	if (flags & O_CREAT) {		va_start(args, flags);		mode = va_arg(args, mode_t);		va_end(args);	}	if (!strcmp (pathname, "/dev/windrvr6")) {		DPRINTF("opening windrvr6/n");#ifdef NO_WINDRVR		windrvrfd = fd = (*func) ("/dev/null", flags, mode);#else		windrvrfd = fd = (*func) (pathname, flags, mode);#endif		if (!busses) {			usb_init();			usb_find_busses();			usb_find_devices();			busses = usb_get_busses();		}		return fd;	}	return (*func) (pathname, flags, mode);}
开发者ID:edowson,项目名称:leap-platforms,代码行数:35,


示例10: getUsbDeviceHandle

/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////Ausb_dev_handle* getUsbDeviceHandle(const size_t vendor, const size_t product){	usb_init();	usb_find_busses();	usb_find_devices();	usb_bus* busses = usb_get_busses();	for(struct usb_bus* bus = busses; bus; bus = bus->next)	{		for(struct usb_device* devi = bus->devices; devi; devi = devi->next)		{			if(vendor == devi->descriptor.idVendor && product == devi->descriptor.idProduct)			{				usb_dev_handle* handle = usb_open(devi);				if(!handle)					return 0;//				if(usb_claim_interface(handle, 0) < 0)//					return 0;				return handle;			}		}	}	return 0;}
开发者ID:ulrichard,项目名称:mypen,代码行数:27,


示例11: open_port

struct usb_dev_handle * open_port() {	struct usb_bus *busses, *bus;	usb_init();	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) {			printf("idVendor:0x%x/t,ipProduct:0x%x/n",					dev->descriptor.idVendor, dev->descriptor.idProduct);			if (QQ2440_SECBULK_IDVENDOR == dev->descriptor.idVendor					&& QQ2440_SECBULK_IDPRODUCT == dev->descriptor.idProduct) {				printf("Target usb device found!/n");				struct usb_dev_handle *hdev = usb_open(dev);				if (!hdev) {					perror("Cannot open device");				} else {					if (0 != usb_claim_interface(hdev, 0)) {						perror("Cannot claim interface");						usb_close(hdev);						hdev = NULL;					}				}				return hdev;			}		}	}	printf("Target usb device not found!/n");	return NULL;}
开发者ID:cutecheng,项目名称:rounder,代码行数:35,


示例12: init_usb

static struct usb_bus* init_usb(){  usb_init();  usb_find_busses();  usb_find_devices();  return (usb_get_busses());}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:7,


示例13: gusb_init

intgusb_init(const char *portname, gpsdevh **dh){	int req_unit_number = 0;	libusb_unit_data *lud = xcalloc(sizeof (libusb_unit_data), 1);	*dh = (gpsdevh*) lud;// usb_set_debug(99);	usb_init();	gusb_register_ll(&libusb_llops);	/* if "usb:N", read "N" to be the unit number. */	if (strlen(portname) > 4) {		if (0 == strcmp(portname+4, "list")) {			req_unit_number = -1;		} else {			req_unit_number = atoi(portname + 4);		}	}	usb_find_busses();	usb_find_devices();	lud->busses = usb_get_busses();	return garmin_usb_scan(lud, req_unit_number);}
开发者ID:alexbirkett,项目名称:GPSBabel,代码行数:25,


示例14: io_init

int io_init( char *dev ){  struct usb_bus *bus;  struct usb_device *usbdev;    usb_init(); /* initialize the library */  usb_find_busses(); /* find all busses */  usb_find_devices(); /* find all connected devices */  for(bus = usb_get_busses(); bus; bus = bus->next) {      for(usbdev = bus->devices; usbdev; usbdev = usbdev->next) {          if(usbdev->descriptor.idVendor == USB_VID_ATMEL              && usbdev->descriptor.idProduct == USB_PID_SAMBA) {	    	    if( (io_handle = usb_open(usbdev)) ) {	      if( usb_set_configuration( io_handle, 1 ) < 0 ){		usb_close(io_handle);		continue;	      }	      if( usb_claim_interface( io_handle, 1 ) < 0 ){		usb_close(io_handle);		continue;	      }	      return samba_init();	    }	  }	        }  }    fprintf( stderr, "found no compatible usb devices");  return -1;}
开发者ID:StefanieKoch,项目名称:openbeacon,代码行数:35,


示例15: nxt_find

nxt_error_t nxt_find(nxt_t *nxt){  struct usb_bus *busses, *bus;  usb_find_busses();  usb_find_devices();  busses = usb_get_busses();  for (bus = busses; bus != NULL; bus = bus->next)    {      struct usb_device *dev;      for (dev = bus->devices; dev != NULL; dev = dev->next)        {          if (dev->descriptor.idVendor == VENDOR_ATMEL &&              dev->descriptor.idProduct == PRODUCT_SAMBA)            {              nxt->dev = dev;              nxt->is_in_reset_mode = 1;              return NXT_OK;            }          else if (dev->descriptor.idVendor == VENDOR_LEGO &&                   dev->descriptor.idProduct == PRODUCT_NXT)            {              nxt->dev = dev;              return NXT_OK;            }        }    }  return NXT_NOT_PRESENT;}
开发者ID:qreal,项目名称:nxt-tools,代码行数:31,


示例16: TemperCreateFromDeviceNumber

Temper *TemperCreateFromDeviceNumber(int deviceNum, int timeout, int debug){	struct usb_bus *bus;	int n;	n = 0;	for(bus=usb_get_busses(); bus; bus=bus->next) {	    struct usb_device *dev;	    for(dev=bus->devices; dev; dev=dev->next) {		if(debug) {			printf("Found device: %04x:%04x/n",			       dev->descriptor.idVendor,			       dev->descriptor.idProduct);		}		if(dev->descriptor.idVendor == VENDOR_ID &&		   dev->descriptor.idProduct == PRODUCT_ID) {			if(debug) {			    printf("Found deviceNum %d/n", n);			}			if(n == deviceNum) {				return TemperCreate(dev, timeout, debug);			}			n++;		}	    }	}	return NULL;}
开发者ID:olegstepura,项目名称:HID-TEMPerHUM,代码行数:30,


示例17: usb_init

static struct usb_device *find_device(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:run,项目名称:scripts,代码行数:25,


示例18: find_colorhug_device

static struct usb_device *find_colorhug_device (void){	struct usb_bus *bus;	struct usb_bus *busses;	struct usb_device *dev;	struct usb_device *found = NULL;	busses = usb_get_busses();	for (bus = busses; bus; bus = bus->next) {		for (dev = bus->devices; dev; dev = dev->next) {			if (dev->descriptor.idVendor == CH_USB_VID &&			    dev->descriptor.idProduct == CH_USB_PID_FIRMWARE) {				found = dev;				goto out;			}			if (dev->descriptor.idVendor == CH_USB_VID &&			    dev->descriptor.idProduct == CH_USB_PID_FIRMWARE2) {				found = dev;				goto out;			}			if (dev->descriptor.idVendor == CH_USB_VID_LEGACY &&			    dev->descriptor.idProduct == CH_USB_PID2_FIRMWARE) {				found = dev;				goto out;			}		}	}out:	return found;}
开发者ID:hughski,项目名称:colorhug-client,代码行数:31,


示例19: usb_find_busses

struct usb_device* digilent::find_digilent_device(){	struct usb_bus* bus;	struct usb_device* dev;    int i;	usb_find_busses();	usb_find_devices();    for (bus = usb_get_busses(); bus; bus = bus->next) 	{		if (bus->root_dev)		{			for (i = 0; i < bus->root_dev->num_children; i++)		        if (bus->root_dev->children[i]->descriptor.idVendor == USB_VENDOR_ID &&                    bus->root_dev->children[i]->descriptor.idProduct == USB_PRODUCT_ID)					// Found it					return bus->root_dev->children[i];		}		else		{			for (dev = bus->devices; dev; dev = dev->next)                if (dev->descriptor.idVendor == USB_VENDOR_ID &&                    dev->descriptor.idProduct == USB_PRODUCT_ID)					// Found it					return dev;		}    }	return NULL;}
开发者ID:JamesHyunKim,项目名称:xilprg-hunz,代码行数:31,


示例20: FindUsbtinys

void FindUsbtinys(void) {  int usbtinyindex = 1;  if (UsbInit()) {    usb_find_busses();    usb_find_devices();    struct usb_bus *bus = usb_get_busses();    while (bus) {      struct usb_device *device = bus->devices;      while (device) {        if (    device->descriptor.idVendor  == VENDOR_ID            &&  device->descriptor.idProduct == PRODUCT_ID) {          Assert(PortCount < countof(Ports));          Ports[PortCount] = malloc(sizeof(struct UPort));          Assert(Ports[PortCount]);          Ports[PortCount]->kind      = 'u';          Ports[PortCount]->index     = usbtinyindex++;          Ports[PortCount]->character = -1;              // Currently undetermined          Ports[PortCount]->baud      = 0;               // Currently undetermined          ((struct UPort*)Ports[PortCount])->handle = 0; // Currently unconnected          ((struct UPort*)Ports[PortCount])->device = device;          PortCount++;        }        device = device->next;      }      bus = bus->next;    }  }}
开发者ID:dcwbrown,项目名称:dwire-debug,代码行数:35,


示例21: find_devices

static int find_devices(int mode, struct device_info *devinfo, size_t size){	struct usb_bus *bus;	struct usb_device *dev;	struct device_id *id;	int count = 0;	usb_find_busses();	usb_find_devices();	for (bus = usb_get_busses(); bus; bus = bus->next)		for (dev = bus->devices; dev; dev = dev->next) {			id = match_device(mode, dev->descriptor.idVendor,						dev->descriptor.idProduct);			if (!id)				continue;			if (count < size) {				devinfo[count].dev = dev;				devinfo[count].id = id;				count++;			}		}	return count;}
开发者ID:WiseMan787,项目名称:ralink_sdk,代码行数:26,


示例22: Bench_Open

struct usb_dev_handle* Bench_Open(WORD vid, WORD pid, INT interfaceNumber, INT altInterfaceNumber, struct usb_device** deviceForHandle){    struct usb_bus* bus;    struct usb_device* dev;    struct usb_dev_handle* udev;    for (bus = usb_get_busses(); bus; bus = bus->next)    {        for (dev = bus->devices; dev; dev = dev->next)        {            if (dev->descriptor.idVendor == vid && dev->descriptor.idProduct == pid)            {				if ((udev = usb_open(dev)))				{					if (dev->descriptor.bNumConfigurations)					{						if (usb_find_interface(&dev->config[0], interfaceNumber, altInterfaceNumber, NULL) != NULL)						{							if (deviceForHandle) *deviceForHandle = dev;							return udev;						}					}					usb_close(udev);				}            }        }    }    return NULL;}
开发者ID:AndreMiras,项目名称:EFM32-Library,代码行数:30,


示例23: usb_init

int Sdr1kUsb::GetNumDevs(){	if (devcount < 0) {		usb_init();		devcount = 0;	}	int changes = usb_find_busses();	changes += usb_find_devices();	if (changes == 0) return devcount;	devcount = 0;			struct usb_bus* bus = usb_get_busses();	while (bus) {		struct usb_device* dev = bus->devices;		while (dev) {			if (devcount == USB_MAX_DEVICES) break;			int VID = dev->descriptor.idVendor;			int PID = dev->descriptor.idProduct;			for (int i = 0; i < hwcount; i++) {				if (VID == hardware[i].VID && PID == hardware[i].PID) {					device[devcount] = dev;					hw[devcount] = &hardware[i];					devcount++;					break;				}			}			dev = dev->next;		}		bus = bus->next;	}#ifdef SDR1KUSB_INFO	printf("Sdr1kUsb::GetNumDevs = %d/n", devcount);#endif	return devcount;}
开发者ID:8cH9azbsFifZ,项目名称:ghpsdr3-alex,代码行数:35,


示例24: findFortius

bool LibUsb::findFortius(){    struct usb_bus* bus;    struct usb_device* dev;    bool found = false;    //    // Search for an UN-INITIALISED Fortius device    //    for (bus = usb_get_busses(); bus; bus = bus->next) {        for (dev = bus->devices; dev; dev = dev->next) {            if (dev->descriptor.idVendor == FORTIUS_VID && dev->descriptor.idProduct == FORTIUS_INIT_PID) {                found = true;            }            if (dev->descriptor.idVendor == FORTIUS_VID && dev->descriptor.idProduct == FORTIUS_PID) {                found = true;            }            if (dev->descriptor.idVendor == FORTIUS_VID && dev->descriptor.idProduct == FORTIUSVR_PID) {                found = true;            }        }    }    return found;}
开发者ID:AndyBryson,项目名称:GoldenCheetah,代码行数:29,


示例25: usb_init

/* * A helper function initializing libusb and finding our iPhone/iPod which has given DeviceID */struct usb_dev_handle *iUSBInit(int devid){	struct usb_dev_handle *devPhone = 0;	struct usb_device *dev;	struct usb_bus *bus;	usb_init();	usb_find_busses();	usb_find_devices();	printf("Got USB/n");	for(bus = usb_get_busses(); bus; bus = bus->next) {		//printf("Found BUS/n");		for(dev = bus->devices; dev; dev = dev->next) {			//printf("/t%4.4X %4.4X/n", dev->descriptor.idVendor, dev->descriptor.idProduct);			if(dev->descriptor.idVendor == 0x5AC && dev->descriptor.idProduct == devid) {				// z0mg!!!! iPhone 4th Generation//				printf("Found iPhone/iPod in DFU 2.0/n");				devPhone = usb_open(dev);			}		}	}	return devPhone;}
开发者ID:dksite,项目名称:irecovery,代码行数:28,


示例26: usbblaster_enumerate_bus

static int usbblaster_enumerate_bus(void){  int             flag;  // for USB bus scanning stop condition  struct usb_bus *bus;   // pointer on the USB bus    // board detection  usb_init();  usb_find_busses();  usb_find_devices();  flag = 0;    for (bus = usb_get_busses(); bus; bus = bus->next)  {    for (usbblaster_device = bus->devices; usbblaster_device; usbblaster_device = usbblaster_device->next)    {	      if (usbblaster_device->descriptor.idVendor  == ALTERA_VID &&          usbblaster_device->descriptor.idProduct == ALTERA_PID)       {	      flag = 1;	      fprintf(stderr, "Found Altera USB-Blaster/n");	      return APP_ERR_NONE;      }    }    if (flag)      break;  }  fprintf(stderr, "Failed to find USB-Blaster  with VID 0x%0X, PID 0x%0X/n", ALTERA_VID, ALTERA_PID);  return APP_ERR_CABLENOTFOUND;}
开发者ID:FPGA-cores-examples,项目名称:adv_debug_sys,代码行数:31,


示例27: DBG

struct xusb *xusb_find_iface(const char *devpath,	int iface_num,	int ep_out,	int ep_in,	struct xusb_spec *dummy_spec){	struct usb_bus		*bus;	DBG("/n");	xusb_init();	for (bus = usb_get_busses(); bus; bus = bus->next) {		int			bus_num;		char			tmppath[PATH_MAX + 1];		struct usb_device	*dev;		tmppath[0] = '/0';		sscanf(bus->dirname, "%d", &bus_num);		snprintf(tmppath, sizeof(tmppath), "%03d", bus_num);		DBG("Check bus %d: %s ? %s/n", bus_num, tmppath, devpath);		if (strncmp(tmppath, devpath, strlen(tmppath)) != 0)			continue;		DBG("Matched bus %d/n", bus_num);		for (dev = bus->devices; dev; dev = dev->next) {			struct usb_device_descriptor	*dev_desc;			struct usb_config_descriptor	*config_desc;			struct usb_interface		*interface;			struct xusb			*xusb;			int				device_num;			sscanf(dev->filename, "%d", &device_num);			DBG("Check device %d/n", device_num);			snprintf(tmppath, sizeof(tmppath), "%03d/%03d",				bus_num, device_num);			if (strncmp(tmppath, devpath, strlen(tmppath)) != 0)				continue;			dev_desc = &dev->descriptor;			assert(dev_desc);			config_desc = dev->config;			assert(config_desc);			interface = config_desc->interface;			assert(interface);			DBG("Matched device %s: %X:%X/n", tmppath,				dev_desc->idVendor, dev_desc->idProduct);			assert(dummy_spec);			xusb_init_spec(dummy_spec, "<none>",				dev_desc->idVendor, dev_desc->idProduct,				config_desc->bNumInterfaces,				iface_num,				interface->altsetting->bNumEndpoints,				ep_out, ep_in);			xusb = xusb_new(dev, dummy_spec);			if (!xusb)				ERR("xusb allocation failed/n");			return xusb;		}	}	return NULL;}
开发者ID:MattheusNiels,项目名称:BackupCerberus,代码行数:58,


示例28: usb_open_device

/* taken (modified) from avrdude usbasp.c */static int usb_open_device(struct usb_dev_handle **device, int vendor, int product){    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)        {            DEBUG( "Enumerating device list.. VID: 0x%4.4x, PID: 0x%4.4x/n", dev->descriptor.idVendor, dev->descriptor.idProduct);            if (dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product)            {                /* we need to open the device in order to query strings */                handle = usb_open(dev);                if (handle == NULL)                {                    errorCode = USB_ERROR_ACCESS;                    avrdude_message(MSG_INFO, "%s: Warning: cannot open USB device: %s/n", progname, usb_strerror());                    continue;                }                // return with opened device handle                else                {                    avrdude_message(MSG_NOTICE, "Device %p seemed to open OK./n", handle);                    if ((errorCode = usb_set_configuration(handle, 1)) < 0)                    {                        avrdude_message(MSG_INFO, "Could not set configuration. Error code %d, %s./n"                                "You may need to run avrdude as root or set up correct usb port permissions.", errorCode, usb_strerror());                    }                    if ((errorCode = usb_claim_interface(handle, 0)) < 0)                    {                        avrdude_message(MSG_INFO, "Could not claim interface. Error code %d, %s/n"                                "You may need to run avrdude as root or set up correct usb port permissions.", errorCode, usb_strerror());                    }                    errorCode = 0;                    *device = handle;                    return 0;                }            }        }    }    return -1;}
开发者ID:MelanieT,项目名称:avrdude,代码行数:59,


示例29: usb_init

// open the usb devices identified by vendor and product.// claim exlclusive access to the interface and enable bit bang mode// return NULL on failure otherwise a valid usb_dev_handle descriptor//// The standard ftdi232bm vendor and product IDs are: 0x0403, 0x6001usb_dev_handle *ftdibb_open(int vendor, int product,int silent){	usb_dev_handle *dev_handle;	struct usb_bus *busses;	struct usb_bus *bus;	struct usb_device *dev;	int founddev=0;    	usb_init();	usb_find_busses();	usb_find_devices();	busses = usb_get_busses();	for (bus = usb_busses; bus; bus = bus->next) {		for (dev = bus->devices; dev; dev = dev->next) {			if (dev->descriptor.idVendor == vendor 				&& dev->descriptor.idProduct == product) {				dev_handle = usb_open(dev);				if (dev_handle){					founddev=1;						break;				}else{					if (silent==0 || silent==1){						fprintf(stderr,"ftdibb error: Device found but usb_open failed/n");					}					return(NULL); // device found but open fail				}			}		}	}	if(founddev==0){		if (silent==0){			fprintf(stderr,"ftdibb error: Device not connected/n");		}		return(NULL); // device not found 	}	if (usb_claim_interface(dev_handle, 0) != 0) {		usb_close (dev_handle);		if (silent==0 || silent==1){			fprintf(stderr,"ftdibb error: unable to claim exclusive access to ftdi chip. Make sure ftdi_sio is not loaded (check with lsmod) and make sure you have write access to /proc/bus/usb (root right or suid executable)/n");		}		return(NULL); // usb_claim_interface failed	}	// now we are ready to configure the device	// the syntax to send a control urb is this:	// usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout);	// reset  it first	if (usb_control_msg(dev_handle, 0x40, 0, 0, 0, NULL, 0, 4000) != 0){		usb_close (dev_handle);		if (silent==0 || silent==1){			fprintf(stderr,"ftdibb error: Device communication failed during reset/n");		}		return(NULL); // reset fail	}	return(dev_handle);}
开发者ID:cyphunk,项目名称:sectk,代码行数:62,


示例30: pn53x_usb_scan

static size_tpn53x_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const size_t connstrings_len){  (void)context;  usb_prepare();  size_t device_found = 0;  uint32_t uiBusIndex = 0;  struct usb_bus *bus;  for (bus = usb_get_busses(); bus; bus = bus->next) {    struct usb_device *dev;    for (dev = bus->devices; dev; dev = dev->next, uiBusIndex++) {      for (size_t n = 0; n < sizeof(pn53x_usb_supported_devices) / sizeof(struct pn53x_usb_supported_device); n++) {        if ((pn53x_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&            (pn53x_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {          // Make sure there are 2 endpoints available          // with libusb-win32 we got some null pointers so be robust before looking at endpoints:          if (dev->config == NULL || dev->config->interface == NULL || dev->config->interface->altsetting == NULL) {            // Nope, we maybe want the next one, let's try to find another            continue;          }          if (dev->config->interface->altsetting->bNumEndpoints < 2) {            // Nope, we maybe want the next one, let's try to find another            continue;          }          usb_dev_handle *udev = usb_open(dev);          if (udev == NULL)            continue;          // Set configuration          int res = usb_set_configuration(udev, 1);          if (res < 0) {            log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set USB configuration (%s)", _usb_strerror(res));            usb_close(udev);            // we failed to use the device            continue;          }          // pn53x_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));          log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s", bus->dirname, dev->filename);          usb_close(udev);          snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename);          device_found++;          // Test if we reach the maximum "wanted" devices          if (device_found == connstrings_len) {            return device_found;          }        }      }    }  }  return device_found;}
开发者ID:h4ck3rm1k3,项目名称:php5-nfc,代码行数:57,



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


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