- From: rph <rph_at_inventati.org>
- Date: Sun, 29 Aug 2004 13:37:56 +0200
I'm trying to acquire the 16 analog input channels of my ni-daq 6024E pcmcia and I'm encountering problems in the command data structure. I must acquire each channel with a sampling frequency of 100 Hz and the acquisition must be continuous (TRIG_NONE).
with the following (working) C++ code:
#include <iostream>
#include <comedilib.h>
using namespace std;
int main(int argc, char* argv)
{
int freq = 100; // sample frequency
comedi_t* device = comedi_open("/dev/comedi0");
int subdevice = comedi_find_subdevice_by_type(device,COMEDI_SUBD_AI,0);
int aref = AREF_GROUND;
int channel = 0;
int n_chan = 16;
int range = 0;
comedi_range* rng = comedi_get_range(device,subdevice,channel,range);
unsigned int chanlist[n_chan];
for (int i=0;i<n_chan;i++)
chanlist[i]=CR_PACK(channel+i,range,aref);
sampl_t maxdata = comedi_get_maxdata(device,subdevice,channel);
int data_len = n_chan;
sampl_t data[data_len];
memset(data,0,sizeof(data));
comedi_cmd c,*cmd=&c;
memset(cmd,0,sizeof(*cmd));
int n_scan = 10;
cmd->subdev = subdevice;
cmd->flags = 0;
cmd->start_src = TRIG_NOW;
cmd->start_arg = 0;
cmd->scan_begin_src = TRIG_TIMER;
cmd->scan_begin_arg = 1000000000/freq;
cmd->convert_src = TRIG_TIMER;
cmd->convert_arg = 0;
cmd->scan_end_src = TRIG_COUNT;
cmd->scan_end_arg = n_chan;
cmd->stop_src = TRIG_NONE;
cmd->stop_arg = 0;
cmd->chanlist = chanlist;
cmd->chanlist_len = n_chan;
cout << "test cmd 1: " << comedi_command_test(device,cmd) << endl;
cout << "test cmd 2: " << comedi_command_test(device,cmd) << endl;
int ret=comedi_command(device,cmd);
if(ret!=0){
comedi_perror("comedi_command");
exit(1);
}
int total=0;
while(total<n_scan)
{
int ret=read(comedi_fileno(device),data,sizeof(data));
cout << "output for channel 0: "
<< comedi_to_phys(data[0],rng,maxdata)
<< endl;
total++;
}
if(cmd->stop_src == TRIG_NONE)
comedi_cancel(device,subdevice);
return 0;
}
I get this strange output for channel 0 when the card isn't plugged to any external system, because channel values must be random and that's not what I get:
test cmd 1: 3
test cmd 2: 0
output for channel 0: 0.002442
output for channel 0: 0.002442
output for channel 0: 0.002442
output for channel 0: 0.002442
output for channel 0: 0.002442
output for channel 0: 0.002442
output for channel 0: 0.002442
output for channel 0: 0.002442
output for channel 0: 0.002442
output for channel 0: 0.002442
In fact, if I just change the stop events to:
cmd->stop_src = TRIG_COUNT;
cmd->stop_arg = n_scan;
I get the right output:
test cmd 1: 3
test cmd 2: 0
output for channel 0: -7.04518
output for channel 0: -0.148962
output for channel 0: -0.124542
output for channel 0: -0.0512821
output for channel 0: -0.046398
output for channel 0: -0.0854701
output for channel 0: -0.148962
output for channel 0: -0.227106
output for channel 0: -0.310134
output for channel 0: -0.388278
Can anyone help me in develpoing the right code?
Thanks,
Raphael Bartalesi
Received on 2004-08-29Z10:37:56