|
From: tuxd3v <tu...@sa...> - 2015-03-11 15:22:34
|
I guys,
I don't know if this is the right place, but after hours trying to
figure out what's wrong, its the last chance.
I am trying to use libusb1.0 on my machine(Debian 7 amd64).
code usb.c file:
#include <stdio.h>
#include <libusb.h>
void printdev( libusb_device *dev ); //prototype of the function
void printdev( libusb_device *dev ){
libusb_device_descriptor desc;
int r = libusb_get_device_descriptor( dev, &desc );
if ( r < 0 ) {
printf( "failed to get device descriptor\n" );
return 1;
}
printf( "Number of possible configurations: %d ",
(int)desc.bNumConfigurations );
printf( "Device Class: %d ", (int)desc.bDeviceClass );
printf( "VendorID: %d ", desc.idVendor );
printf( "ProductID: %d \n", desc.idProduct );
libusb_config_descriptor *config;
libusb_get_config_descriptor( dev, 0, &config );
printf( "Interfaces: %d ||| ", (int)config->bNumInterfaces );
const libusb_interface *inter;
const libusb_interface_descriptor *interdesc;
const libusb_endpoint_descriptor *epdesc;
for( int i = 0; i < (int)config->bNumInterfaces; i++ ) {
inter = &config->interface[i];
printf( "Number of alternate settings: %d | ",
inter->num_altsetting );
for( int j = 0; j < inter->num_altsetting; j++ ) {
interdesc = &inter->altsetting[ j ];
printf( "Interface Number: %d | ",
(int)interdesc->bInterfaceNumber );
printf( "Number of endpoints: %d | ",
(int)interdesc->bNumEndpoints );
for( int k = 0; k < (int)interdesc->bNumEndpoints; k++ ){
epdesc = &interdesc->endpoint[ k ];
printf( "Descriptor Type: %d | "),
(int)epdesc->bDescriptorType;
printf( "EP Address: %d | ",
(int)epdesc->bEndpointAddress );
}
}
}
printf( "\n\n\n" );
libusb_free_config_descriptor( config );
}
int main( int argc, char *argv[] ) {
libusb_device **devs; //pointer to pointer of device, used to
retrieve a list of devices
libusb_context *ctx = NULL; //a libusb session
int r; //for return values
ssize_t cnt; //holding number of devices in list
ssize_t i; //for iterating through the list
r = libusb_init( &ctx ); //initialize a library session
if(r < 0) {
printf( "Init Error %d", r ); //there was an error
return 1;
}
libusb_set_debug( ctx, 3 ); //set verbosity level to 3, as
suggested in the documentation
cnt = libusb_get_device_list( ctx, &devs ); //get the list of devices
if( cnt < 0 ){
printf( "Get Device Error" ); //there was an error
}
printf( " %d Devices in list.", cnt ); //print total number of usb
devices
for(i = 0; i < cnt ; i++) {
printdev( devs[ i ] ); //print specs of this device
}
libusb_free_device_list( devs, 1 ); //free the list, unref the
devices in it
libusb_exit( ctx ); //close the session
return 0;
}
---------------------------
`locate libusb.h`
/usr/include/libusb-1.0/libusb.h
static libary
/usr/lib/x86_64-linux-gnu/libusb-1.0.a
gcc -c usb.c -I/usr/include/libusb-1.0 -l
gcc -o -L/usr/lib/x86_64-linux-gnu -llibusb-1.0
I can't even compile to get the object file :S
in compilation process I get a:
"usb.c:10:2: error: unknown type name ‘libusb_device_descriptor’
libusb_device_descriptor desc;
"
...
OK I get it...they are structs defenitions not typedef's..
But I think that to turn this lib easier, you should provide typedef's
on linusb.h.
Thanks
tux
|