discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Claiming interface 2 (RX) fails!


From: Ujala Qasim
Subject: [Discuss-gnuradio] Claiming interface 2 (RX) fails!
Date: Thu, 12 Mar 2009 21:03:23 +0500

Hi!

I am trying to write a program in C that interfaces between USRP and Windows, this is my initial code:

#include "usb.h"
#include "usrp_spi_defs.h"
#include "usrp_commands.h"
#include "fpga_regs_standard.h"
#include "ad9862.h"
#include "usrp_interfaces.h"
#include <stdio.h>
#include <math.h>

#define SAMPELS_PER_READ (512)

struct usb_device *myDev;
struct usb_dev_handle *bulk_udh;

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;
}

int main(void)
{
  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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]