rewrite
This commit is contained in:
parent
644fca15d2
commit
3aeb987160
1 changed files with 50 additions and 27 deletions
77
demo/mode2.c
77
demo/mode2.c
|
@ -1,15 +1,17 @@
|
|||
/*
|
||||
A little input demo for mode 2
|
||||
A little input demo for mode 4
|
||||
|
||||
Mode 2 uses two different timers to convert samples.
|
||||
The primary timer determines the time between scans,
|
||||
and the secondary timer determines the time between
|
||||
samples in a scan.
|
||||
Mode 4 uses an external trigger to repeatedly trigger a
|
||||
scan of samples. (This is different from mode 3, which
|
||||
triggers an individual sample.) Thus, for each external
|
||||
trigger, n_chan samples are converted.
|
||||
|
||||
The time between scans is in trigval; the time
|
||||
between samples is selected by trigval1. Conversion
|
||||
from seconds or Hz is done using the standard timer
|
||||
routines.
|
||||
If you have multiple external trigger lines, the
|
||||
particular trigger line is selected by trigval.
|
||||
|
||||
The time between samples in a scan is selected
|
||||
by trigval1. Conversion from seconds or Hz is done
|
||||
using the standard timer routines.
|
||||
|
||||
*/
|
||||
|
||||
|
@ -22,42 +24,63 @@
|
|||
#include <getopt.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define N_SCANS 10
|
||||
#define N_CHANS 16
|
||||
#define N_SCANS 4
|
||||
#define N_CHANS 4
|
||||
|
||||
int subdevice = 0;
|
||||
int chan=0;
|
||||
int range = 0;
|
||||
int aref = AREF_GROUND;
|
||||
int channels[N_CHANS] = { 0, 1, 2, 3 };
|
||||
double freq = 1000;
|
||||
int range = 0;
|
||||
int aref = 3;
|
||||
int external_trigger_number = 0;
|
||||
|
||||
#define N_SAMPLES 1000
|
||||
#define N_SAMPLES (N_CHANS*N_SCANS)
|
||||
|
||||
double data[N_SAMPLES];
|
||||
sampl_t data[N_SAMPLES];
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *fn = NULL;
|
||||
int i;
|
||||
comedi_trig it;
|
||||
int err;
|
||||
int n,i;
|
||||
comedi_t *dev;
|
||||
double actual_freq;
|
||||
unsigned int chan[N_CHANS];
|
||||
|
||||
fn = "/dev/comedi0";
|
||||
fn = "/dev/comedi3";
|
||||
|
||||
dev = comedi_open(fn);
|
||||
|
||||
#if 0
|
||||
for(i=0;i<10;i++){
|
||||
range=comedi_find_range(dev,subdevice,chan,0,-i,i);
|
||||
printf("%d\n",range);
|
||||
}
|
||||
#endif
|
||||
comedi_timed_1chan(dev,subdevice,chan,range,aref,freq,N_SAMPLES,data);
|
||||
it.subdev = 0;
|
||||
it.mode = 2;
|
||||
it.flags = 0;
|
||||
it.n_chan = 1;
|
||||
it.chanlist = chan;
|
||||
it.data = data;
|
||||
it.n = N_SCANS;
|
||||
it.trigsrc = 0;
|
||||
it.trigvar = 10000;
|
||||
it.trigvar1 = 10000;
|
||||
|
||||
for(i=0;i<N_SAMPLES;i++){
|
||||
printf("%g\n",data[i]);
|
||||
/* pack the channel list */
|
||||
for(i=0;i<N_CHANS;i++){
|
||||
chan[i] = CR_PACK(channels[i], range, aref);
|
||||
}
|
||||
|
||||
if ((err = comedi_trigger(dev, &it)) < 0) {
|
||||
perror("ioctl");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if((n=read(comedi_fileno(dev),data,N_SAMPLES*sizeof(sampl_t)))<0){
|
||||
perror("read");
|
||||
exit(1);
|
||||
}
|
||||
printf("number of samples read=%d\ndata[0]=%d\ndata[N-1]=%d\n",
|
||||
n/sizeof(sampl_t),data[0],data[N_SAMPLES-1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue