using NI DAQ16XE50

Hello
	Im trying to get data from a NI DAQ16XE50. I just installed comedi and
comedilib and inserted the card and it was recognized and the
comedi_test was fine. Then i wrote this program to get data using a call
back function. The function is called but only about 4000 times also
when i print the data its always the same..i even change the data to see
if its being overwritten...its not. Any clues why this could be
happening? Im at my wits end..any help would be much appreciated

Muks



#include <linux/kernel.h>
#include <linux/module.h>
#include <comedi.h>
#include <comedilib.h>


#define MAX_CHAN 8
#define FREQ 200

comedi_t *dev;
unsigned int subd = 0;
static sampl_t data[10240];
comedi_cmd cmd;
unsigned int chanlist[MAX_CHAN];



static long period;
int freq;


MODULE_PARM(freq,"i");

int do_cmd(void)
{

  int ret;
  int i;
  int num_ranges = 0;
  period = 1000000000/freq;

  cmd.subdev = subd;
  cmd.flags = 0;

  cmd.start_src = TRIG_NOW;
  cmd.start_arg = 0;

  cmd.scan_begin_src = TRIG_TIMER;
  cmd.scan_begin_arg = period;

  cmd.convert_src = TRIG_TIMER;
  cmd.convert_arg = 100000;

  cmd.scan_end_src = TRIG_COUNT;
  cmd.scan_end_arg = MAX_CHAN;

  cmd.stop_src = TRIG_NONE;
  cmd.stop_arg = 0;

  cmd.chanlist = chanlist;
  cmd.chanlist_len = MAX_CHAN;

  //Creatting the channels list, the number '5' is hardware
  // dependient and could not work with all the ADC cards
  for(i=0;i<MAX_CHAN;i++)
  {
    num_ranges = comedi_get_n_ranges(dev,subd,i);
    chanlist[i] = CR_PACK(i,num_ranges,AREF_DIFF);
  }

  cmd.data=data;
  cmd.data_len=10240*sizeof(sampl_t);
  printk(" Running Comedi Command Test...");
  ret = comedi_command_test(dev,&cmd);
  if(ret == 0)
	  printk("Success\n");
  else
  {
	comedi_perror("comedi command test\n");
	printk("Failure...returned %d",ret);
	return ret;
  }

  cmd.chanlist = chanlist;
  cmd.chanlist_len = MAX_CHAN;
  cmd.data=data;
  cmd.data_len=MAX_10240*sizeof(sampl_t);
  printk(" Running Comedi Command Test...");
  ret = comedi_command_test(dev,&cmd);
  if(ret == 0)
	  printk("Success\n");
  else
  {
	printk("Failure...returned %d",ret);
	return ret;
  }

  cmd.chanlist = chanlist;
  cmd.chanlist_len = MAX_CHAN;
  cmd.data=data;
  cmd.data_len=10240*sizeof(sampl_t);
  printk("\n Comedi Command....");
  ret = comedi_command(dev,&cmd);
  if(ret == 0)
  	printk("Success\n");
  else
	printk("Failure...returned %d\n",ret);

  return ret;
}
static int callback(unsigned int i, void * arg)
{
	static int printcount = 0;
	static int coun = 0;
	printk("\n IN CALL BACK\n");
	if(printcount++ == 100)
	{
		printk("\n IN CALL BACK %d %d %d %d %d
%d\n",coun++,data[0],data[1],data[2],data[3],data[4]);
		printk("%s\n",str);
		printcount = 0;
	}
	data[2]=9; //just to check if its overwriiten next time around
	return 0;
}


int init_module(void)
{

      int ret=0;
      printk("Inializing Comedi - DAQ\n");
      if(freq==0)
	freq = FREQ;
      dev = comedi_open("/dev/comedi0");

      if(dev)
              printk("comedi_open..Success\n");
      else
              printk("comedi_open..Failure\n");

      ret = comedi_lock(dev,subd);
      printk("comedi_lock: %d\n",ret);

      ret = comedi_register_callback
		      (dev,subd,COMEDI_CB_EOS,callback,NULL);
	printk(" ret = %d",ret);

      do_cmd();
      return 0;
}


-- 
Muks Raju <muks_at_ieee.org>

Received on 2002-12-20Z23:20:58