changes
authorDavid Schleef <ds@schleef.org>
Tue, 5 Sep 2000 18:10:55 +0000 (18:10 +0000)
committerDavid Schleef <ds@schleef.org>
Tue, 5 Sep 2000 18:10:55 +0000 (18:10 +0000)
demo/cmd.c
demo/insn.c
demo/mode2.c

index 269ac27fcb1931a003cbb130a74744162f66a456..e535cc78f1ed2ef0ad8322fbe35413d24c507b5a 100644 (file)
@@ -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)
index 9b3053079e76a01d72cb17673451f0256b2a5482..2df47076b71f5c03006f0a25464914dac50c3e8f 100644 (file)
@@ -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;
 }
 
index fd17b433fb4c2df9d80af2318ab23bfab7f7672a..c57d1a36d0c554a6a73d2798b59cf1ab8de2ad3a 100644 (file)
@@ -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;
 }