- From: Muks Raju <muks_at_ieee.org>
- Date: Thu, 18 Sep 2003 11:42:21 -0400
The reason i used it is because i couldnt get the comedi command thing
to work right with the NI DAQ. We initially abandoned this method since
many people said that the callback and cmd
feature was broken in comedi for this daq. The call back function was
being called but the data was not being copied into the variables.
Anyways i revisited this problem a few months later and saw that
somebody had overcome the problem by using comedi_fc so i tried it and
it worked except for these crazy bugs. Could you give me some more
information about why I shouldnt use it and is there any other way. If i
dont use this function then i just dont get the data into the required
variables. Ill attach my code just in case there is some glaring
deffect. Would be much obliged for any assistance.
Thanks
Muks
const unsigned int subd = 0;
unsigned int ai_chanspec[MAX_CHAN]; // packed comedi AI
channel
comedi_cmd ai_cmd; // main AI comedi command
sampl_t ai_data[MAX_CHAN]; // comedi AI data points
comedi_t *daq_dev; // DAQ device id
char daq_read_data(char *str)
{
int i;
int n;
str[0]='K';
str[1]='I';
str[2]=' ';
for(i=0,n=3;i<MAX_CHAN;i++,n+=6)
sprintf(str+n,"%05d ",ai_data[i+1]);
return n;
}
int callback(unsigned int flags,void *arg)
{
comedi_subdevice *sub;
sub = ((comedi_device *)daq_dev)->subdevices;
cfc_read_array_from_buffer(sub,ai_data, MAX_CHAN*sizeof(sampl_t));
return 0;
}
static int init_daq(void)
{
int error_flag = 0;
int i=0;
memset(&ai_cmd,0,sizeof(ai_cmd));
for(i=0;i<=MAX_CHAN;i++)
ai_chanspec[i] = CR_PACK(i,VALRANGE,AREF);
ai_cmd.chanlist = ai_chanspec;
ai_cmd.chanlist_len = MAX_CHAN;
ai_cmd.data = ai_data;
ai_cmd.data_len = MAX_CHAN*sizeof(sampl_t);
ai_cmd.subdev = 0;
ai_cmd.flags = 0;
ai_cmd.start_src = TRIG_NOW;
ai_cmd.start_arg = 0;
ai_cmd.scan_begin_src = TRIG_TIMER;
ai_cmd.scan_begin_arg = SAMPLE_PERIOD;
ai_cmd.convert_src = TRIG_TIMER;
ai_cmd.convert_arg = SAMPLE_DURATION;
ai_cmd.scan_end_src = TRIG_COUNT;
ai_cmd.scan_end_arg = MAX_CHAN;
ai_cmd.stop_src = TRIG_NONE;
ai_cmd.stop_arg = 0;
rt_printk("\n Done assigning command structure \n");
if((daq_dev = comedi_open(DAQ_DEV_NAME))==NULL)
{
rt_printk("Error.. cannot open comedi device\n");
return -1;
}
if(!(error_flag = comedi_lock(daq_dev,AI_SUBD)))
error_flag = comedi_register_callback(
daq_dev,0,COMEDI_CB_EOS, &callback,(void *)0);
return(error_flag);
}
int init_module(void)
{
printk("Inializing Comedi - DAQ\n");
if(init_daq() == -1)
rt_printk("couldnt init DAQ channels.. check cmd\n");
if(comedi_command(daq_dev,&ai_cmd))
rt_printk("command not correct\n");
return 0;
}
void cleanup_module(void)
{
int ret;
//return value
ret = comedi_cancel(daq_dev,0);
printk("comedi_cancel: %d\n",ret);
ret = comedi_unlock(daq_dev,subd);
printk("comedi_unlock: %d\n",ret);
comedi_close(daq_dev);
printk("comedi_close:\n");
On Thu, 2003-09-18 at 10:55, Frank Mori Hess wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tuesday 16 September 2003 03:09 pm, Muks Raju wrote:
> > Hello.. im using the NI DAQ Ai 16XE50 to read data from 8 Analog Inputs.
> > I have however noticed that to get data from the 8 analog inputs i need
> > to read 9 channels. I dont know why this is so. Also Im using the
> > command structure with a call back function where I read the data into
> > the variables using cfc_read_array_from_buffer.
> > Now I have noticed that data from channel 0 is available in
> > ai_cmd.data[1].. and so on.. i.e data for channel n is in
> > ai_cmd.data[n+1]. why is this so? Anybody working with the same card and
> > having similar issues?
> >
>
> It's a bug to use cfc_read_array_from_buffer() in anything but a driver.
> What made you decide to use it in the first place?
>
> - --
> Frank
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iD8DBQE/acd35vihyNWuA4URAohEAJ9p55pbhqmPV9MZ9+wNAxuWBwD5TQCfaEW2
> 8CQ3AJKwE0v3xPJqMHIk9po=
> =AeHq
> -----END PGP SIGNATURE-----
>
>
> _______________________________________________
> comedi mailing list
> comedi_at_comedi.org
> https://cvs.comedi.org/cgi-bin/mailman/listinfo/comedi
Received on 2003-09-18Z14:42:21