usb_dev_handle *open_dev(void)
{
struct usb_bus *bus;
struct usb_device *device;
for(bus = usb_get_busses(); bus; bus = bus->next)
{
for(device = bus->devices; device; device = device->next)
{
if(device->descriptor.idVendor == MY_VID
&& device->descriptor.idProduct == MY_PID)
{
myDev = device;
return usb_open(device);
}
}
}
return NULL;
}
{
usb_dev_handle *udh; /* the device handle */
char tmp[BUF_SIZE];
int a;
int noverruns = 0;
int overrun;
int total_reads = 10000;
int i;
int buf[SAMPELS_PER_READ];
int bufsize = sizeof(buf);
char * tempBuf[4*SAMPELS_PER_READ];
usb_init(); /* initialize the library */
usb_find_busses(); /* find all busses */
usb_find_devices(); /* find all connected devices */
if(!(udh = open_dev()))
{
printf("error: device not found!\n");
return 0;
}
if(usb_set_configuration(udh, 1) < 0)
{
printf("error: setting config 1 failed\n");
usb_close(udh);
return 0;
}
if(usb_claim_interface(udh, 0) < 0 )
{
printf("error: claiming interface 0 failed\n");
usb_close(udh);
return 0;
}
if(!(bulk_udh = usb_open(myDev)))
{
printf("error: device not found!\n");
return 0;
}
if(usb_set_configuration(bulk_udh, 1) < 0)
{
printf("error: setting config 1 failed\n");
usb_close(bulk_udh);
return 0;
}
if (usb_claim_interface (bulk_udh, USRP_RX_INTERFACE) < 0){
printf("error: claming interface on bulk_udh failed!\n");
usb_close (bulk_udh);
return 0;
}
if (usb_set_altinterface (bulk_udh,USRP_RX_ALTINTERFACE) < 0){
printf("error: setting altinterface failed!\n");
usb_release_interface (bulk_udh, USRP_RX_INTERFACE);
usb_close (bulk_udh);
return 0;
}
set_rx_freq (0, 106.2);
set_nchannels (1);
set_pga (0, 0);
set_mux(0x32103210); // Board A only
set_decim_rate(8);
set_ddc_phase(0,0);
printf("USRP Transfer Starts\n");
// Do USRP Samples Reading
for (i = 0; i < 100; i++)
{
read(&buf, bufsize, &overrun);
if (overrun)
{
printf ("USRP Rx Overrun\n");
noverruns++;
}
// Do whatever you want with the data
}
printf("USRP Transfer Stopped\n");
usb_release_interface(udh, 0);
usb_close(udh);
return 0;
}
However, the claiming of interface always fails on bulk_udh. Please guide me in this regard as to what I am doing wrong?
Thanks.