From: David Schleef Date: Tue, 5 Sep 2000 18:10:55 +0000 (+0000) Subject: changes X-Git-Tag: r0_7_11~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e7a0f5f10c98a56eb31f73aa8278c523f5016383;p=comedilib.git changes --- diff --git a/demo/cmd.c b/demo/cmd.c index 269ac27..e535cc7 100644 --- a/demo/cmd.c +++ b/demo/cmd.c @@ -39,10 +39,14 @@ int main(int argc, char *argv[]) fn = "/dev/comedi0"; dev = comedi_open(fn); + if(!dev){ + perror(fn); + exit(1); + } - //fcntl(comedi_fileno(dev),F_SETFL,O_NONBLOCK); + fcntl(comedi_fileno(dev),F_SETFL,O_NONBLOCK); - do_cmd_2(dev); + do_cmd_1(dev); return 0; } @@ -103,14 +107,15 @@ static void do_cmd(comedi_t *dev,comedi_cmd *cmd) usleep(10000); }else{ go = 0; + perror("read"); } + }else if(ret==0){ + go = 0; }else{ total+=ret; + printf("read %d %d\n",ret,total); } - printf("read %d %d\n",ret,total); } - perror("ack"); - printf("errno=%d\n",errno); } static void do_cmd_1(comedi_t *dev) diff --git a/demo/insn.c b/demo/insn.c index 9b30530..2df4707 100644 --- a/demo/insn.c +++ b/demo/insn.c @@ -35,7 +35,7 @@ comedi_t *device; * */ -#define N_SAMPLES 10 +#define N_SAMPLES 1 int main(int argc, char *argv[]) { @@ -69,6 +69,7 @@ int main(int argc, char *argv[]) insn[0].n=2; insn[0].data=(void *)&t1; +//#if 0 /* Instruction 1: do 10 analog input reads */ insn[1].insn=INSN_READ; insn[1].n=N_SAMPLES; @@ -80,6 +81,12 @@ int main(int argc, char *argv[]) insn[2].insn=INSN_GTOD; insn[2].n=2; insn[2].data=(void *)&t2; +//#endif +#if 0 + insn[1].insn=INSN_GTOD; + insn[1].n=2; + insn[1].data=(void *)&t2; +#endif ret=comedi_do_insnlist(device,&il); if(ret<0){ @@ -93,6 +100,9 @@ int main(int argc, char *argv[]) } printf("final time: %ld.%06ld\n",t2.tv_sec,t2.tv_usec); + printf("difference (us): %ld\n",(t2.tv_sec-t1.tv_sec)*1000000+ + (t2.tv_usec-t1.tv_usec)); + return 0; } diff --git a/demo/mode2.c b/demo/mode2.c index fd17b43..c57d1a3 100644 --- a/demo/mode2.c +++ b/demo/mode2.c @@ -36,7 +36,7 @@ int external_trigger_number = 0; #define N_SAMPLES (N_CHANS*N_SCANS) -sampl_t data[N_SAMPLES]; +sampl_t data[4096]; int main(int argc, char *argv[]) @@ -44,12 +44,12 @@ int main(int argc, char *argv[]) char *fn = NULL; comedi_trig it; int err; - int n,i; + int n,i,m; comedi_t *dev; double actual_freq; unsigned int chan[N_CHANS]; - fn = "/dev/comedi3"; + fn = "/dev/comedi0"; dev = comedi_open(fn); @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) it.n_chan = 1; it.chanlist = chan; it.data = data; - it.n = N_SCANS; + it.n = 0; //N_SCANS; it.trigsrc = 0; it.trigvar = 10000; it.trigvar1 = 10000; @@ -74,12 +74,21 @@ int main(int argc, char *argv[]) exit(1); } - if((n=read(comedi_fileno(dev),data,N_SAMPLES*sizeof(sampl_t)))<0){ - perror("read"); - exit(1); + m=0; + while(1){ + if((n=read(comedi_fileno(dev),data,4096*sizeof(sampl_t)))<0){ + perror("read"); + exit(1); + } + if(n==0){ + perror("damn"); + exit(1); + } + n/=sizeof(sampl_t); + m+=n; + printf("read=%d total=%d data[0]=%d data[N-1]=%d\n", + n,m,data[0],data[n-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; }