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;
}
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)
*
*/
-#define N_SAMPLES 10
+#define N_SAMPLES 1
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;
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){
}
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;
}
#define N_SAMPLES (N_CHANS*N_SCANS)
-sampl_t data[N_SAMPLES];
+sampl_t data[4096];
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);
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;
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;
}