Has anyone used libusb for accessing usb devices here?
Andrew Falanga
af300wsm at gmail.com
Wed Jul 23 04:20:56 UTC 2008
On Tuesday 22 July 2008 08:38:58 Lowell Gilbert wrote:
> "Andrew Falanga" <af300wsm at gmail.com> writes:
> > I'd like to know if anyone here on the list has ever used libusb
> > (http://libusb.sourceforge.net) for accessing usb devices. I
> > successfully compiled and installed it on my FreeBSD 7 laptop but when
> > I run a test program no USB HUBs are found. The same test on a Fedora
> > box works fine. I was wondering what the magic is for FreeBSD since
> > the web site claims the package works on FreeBSD.
>
> libusb is in ports, and a number of other ports use it.
> (See "make search key=libusb".)
> That should provide a variety of working examples.
Ok, I've installed from the ports collection this time (at home now on my
6.2p11 box) and I'm seeing busses in my computer. However, when I plug in my
USB thumb drive, a Sandisk Cruizer Micro that the kernel does see as da0
(verified in /var/log/messages), I don't get any devices shown. Below is the
code to the program I'm using. It's a hack of the basic example on the
libusb.sourceforge.net website docs.
#include <iostream>
#include <usb.h>
int main(void) {
usb_init();
struct usb_bus *busses;
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
if(busses)
std::cout << "we found some busses" << std::endl;
else
std::cout << "no busses were found" << std::endl;
struct usb_bus *bus;
int c, i, a, bussCount(0);
/* ... */
for (bus = busses; bus; bus = bus->next) {
std::cout << "enumerating buss: " << ++bussCount << std::endl;
struct usb_device *dev;
// loop through each device and display its vid pid
for (dev = bus->devices; dev; dev = dev->next) {
struct usb_device_descriptor* pUsbDev = &dev->descriptor;
if(pUsbDev->bDeviceClass == 0x09)
std::cout << "Device is a HUB\n";
if(pUsbDev->bDeviceClass == 0x07)
std::cout << "Device is a printer:\n";
if(pUsbDev->bDeviceClass == 0x08)
std::cout << "Device is a mass storage device:\n";
std::cout << "Device Class: "
<< (int)pUsbDev->bDeviceClass << std::endl;
std::cout << "VID: "
<< std::dec << pUsbDev->idVendor << " "
<< std::hex << pUsbDev->idVendor << std::endl;
std::cout << "PID: "
<< std::dec << pUsbDev->idProduct << " "
<< std::hex << pUsbDev->idProduct << std::endl;
if(dev->num_children > 0) {
struct usb_device* pChild = *(dev->children);
while(pChild) {
std::cout << "Childs device class: "
<< std::dec << pChild->descriptor.bDeviceClass
<< " "
<< std::hex << pChild->descriptor.bDeviceClass
<< std::endl;
pChild = pChild->next;
}
}
}
}
return 0;
}
Any ideas why I'm not seeing any devices?
Andy
More information about the freebsd-questions
mailing list