Home » Source Code » » lsusb.c

lsusb.c ( File view )

From:
  • By 2010-08-29
  • View(s):12
  • Download(s):0
  • Point(s): 1
			/*
 * libusb example program to list devices on the bus
 * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdio.h>
#include <sys/types.h>

#include <libusb/libusb.h>

static void print_devs(libusb_device **devs)
{

	libusb_device *dev;
	int i = 0;

	while ((dev = devs[i++]) != NULL) {

		struct libusb_device_descriptor desc;
		int r = libusb_get_device_descriptor(dev, &desc);
		if (r < 0) {

			fprintf(stderr, "failed to get device descriptor");
			return;
		
}

		printf("%04x:%04x (bus %d, device %d)\n",
			desc.idVendor, desc.idProduct,
			libusb_get_bus_number(dev), libusb_get_device_address(dev));
	
}

}

int main(void)
{

	libusb_device **devs;
	int r;
	ssize_t cnt;

	r = libusb_init(NULL);
	if (r < 0)
		return r;

	cnt = libusb_get_device_list(NULL, &devs);
	if (cnt < 0)
		return (int) cnt;

	print_devs(devs);
	libusb_free_device_list(devs, 1);

	libusb_exit(NULL);
	return 0;

}

			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
aclocal.m4311.63 kB23-11-09 01:21
AUTHORS400.00 B15-11-09 20:16
ChangeLog53.40 kB23-11-09 01:21
compile3.62 kB20-12-07 03:15
config.guess44.40 kB20-06-08 12:30
config.h.in2.25 kB23-11-09 01:21
config.sub32.86 kB20-06-08 12:30
configure402.91 kB23-11-09 01:21
configure.ac3.96 kB23-11-09 01:18
COPYING25.82 kB20-12-07 03:14
depcomp17.16 kB20-12-07 03:15
doxygen.cfg.in52.78 kB02-11-08 23:05
Makefile.am182.00 B21-11-08 18:58
Makefile.in9.79 kB23-11-09 01:21
dpfp.c10.53 kB07-11-09 18:11
dpfp_threaded.c11.37 kB25-06-08 12:00
lsusb.c1.61 kB22-11-09 01:12
Makefile.am356.00 B21-11-08 00:24
Makefile.in17.82 kB23-11-09 01:21
INSTALL9.20 kB20-12-07 03:14
install-sh12.88 kB20-12-07 03:15
core.c53.94 kB07-11-09 20:47
descriptor.c18.97 kB11-06-09 04:39
io.c86.80 kB22-11-09 01:02
libusb.h40.60 kB23-11-09 01:17
libusbi.h28.49 kB23-11-09 01:17
Makefile.am512.00 B23-11-09 01:17
Makefile.in25.37 kB23-11-09 01:21
darwin_usb.c54.01 kB22-11-09 01:10
darwin_usb.h4.27 kB22-11-09 01:06
linux_usbfs.c57.96 kB23-11-09 01:17
linux_usbfs.h4.03 kB07-11-09 20:47
sync.c10.95 kB14-09-09 04:30
libusb-1.0.pc.in245.00 B04-01-08 08:42
ltmain.sh237.57 kB23-11-09 01:21
Makefile.am621.00 B27-08-09 23:55
Makefile.in25.03 kB23-11-09 01:21
missing10.87 kB20-12-07 03:15
NEWS1.09 kB23-11-09 01:20
PORTING3.76 kB15-06-08 23:57
README684.00 B18-09-09 16:30
THANKS215.00 B11-08-08 06:10
TODO290.00 B29-06-08 10:05
<os>0.00 B22-12-09 19:27
<doc>0.00 B22-12-09 19:27
<examples>0.00 B22-12-09 19:27
<libusb>0.00 B22-12-09 19:27
<libusb-1.0.6>0.00 B22-12-09 19:27
...
Sponsored links

lsusb.c (401.92 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D