int main(int argc, char *argv[]) { lsampl_t data; int ret; struct parsed_options options; init_parsed_options(&options); parse_options(&options, argc, argv); device=comedi_open(options.filename); if(!device){ comedi_perror(options.filename); exit(-1); } data = options.value; if(options.verbose){ printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n", data, options.filename, options.subdevice, options.channel, options.range, options.aref); } ret = comedi_apply_calibration(device, options.subdevice, options.channel, options.range, options.aref, NULL); if(ret < 0){ comedi_perror(options.filename); exit(0); } return 0; }
int main(int argc, char *argv[]) { comedi_cmd cmd; int i; struct parsed_options options; init_parsed_options(&options); parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ perror(options.filename); exit(1); } fcntl(comedi_fileno(device), F_SETFL, O_NONBLOCK); for(i = 0; i < n_chans; i++){ chanlist[i] = CR_PACK(options.channel + i, options.range, options.aref); } prepare_cmd(device, &cmd, options.subdevice); do_cmd(device, &cmd); return 0; }
int main(int argc, char *argv[]) { struct sigaction sa; int ret; sigset_t sigset; int flags; struct parsed_options options; init_parsed_options(&options); parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ perror(options.filename); exit(1); } out_subd = 2; config_output(); fcntl(comedi_fileno(device), F_SETOWN, getpid()); flags = fcntl(comedi_fileno(device),F_GETFL); ret = fcntl(comedi_fileno(device),F_SETFL,flags|O_ASYNC); //ret = fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK|O_ASYNC); if(ret<0)perror("fcntl"); memset(&sa,0,sizeof(sa)); sa.sa_handler = &sigio_handler; ret = sigaction(SIGIO,&sa,NULL); if(ret<0)perror("sigaction"); sigemptyset(&sigset); sigaddset(&sigset,SIGIO); ret = sigprocmask(SIG_UNBLOCK,&sigset,NULL); if(ret<0)perror("sigprocmask"); #if 0 { struct sched_param p; memset(&p,0,sizeof(p)); p.sched_priority = 1; ret = sched_setscheduler(0,SCHED_FIFO,&p); if(ret<0)perror("sched_setscheduler"); } #endif do_cmd_1(device, options.subdevice); return 0; }
int main(int argc, char *argv[]) { int ret; int stype; int i; struct parsed_options options; init_parsed_options(&options); options.subdevice = -1; parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ comedi_perror(options.filename); exit(-1); } if(options.subdevice < 0) { options.subdevice = comedi_find_subdevice_by_type(device, COMEDI_SUBD_DIO, 0); if(options.subdevice < 0){ fprintf(stderr,"No dio subdevice found.\n"); exit(-1); } } stype = comedi_get_subdevice_type(device, options.subdevice); if(stype != COMEDI_SUBD_DIO){ printf("%d is not a digital I/O subdevice\n", options.subdevice); exit(-1); } printf("configuring pin %d for output...\n", chan_dat); ret = comedi_dio_config(device, options.subdevice, chan_dat, COMEDI_OUTPUT); printf("configuring pin %d for output...\n", chan_clk); ret = comedi_dio_config(device, options.subdevice, chan_clk, COMEDI_OUTPUT); for(i = 0; i < 0x100; i++){ write_bits(options.subdevice, i); } //write_bits(0xa5); return 0; }
int main(int argc, char *argv[]) { int ret; comedi_cmd cmd; struct parsed_options options; init_parsed_options(&options); parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ perror(options.filename); exit(1); } out_subd = 0; config_output(); ret = fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK|O_ASYNC); if(ret<0)perror("fcntl"); #if 0 { struct sched_param p; memset(&p,0,sizeof(p)); p.sched_priority = 1; ret = sched_setscheduler(0,SCHED_FIFO,&p); if(ret<0)perror("sched_setscheduler"); } #endif prepare_cmd(device, &cmd, options.subdevice); do_cmd(device,&cmd); return 0; }
int main(int argc, char *argv[]) { int retval; lsampl_t routing; struct parsed_options options; init_parsed_options(&options); options.freq = 0.; parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ comedi_perror(options.filename); exit(-1); } routing = options.value; printf("Selecting routing %d for channel %d on subdevice %d.\n", routing, options.channel, options.subdevice); retval = comedi_set_routing(device, options.subdevice, options.channel, routing); if(retval < 0) comedi_perror("comedi_do_insn"); return retval; }
int main(int argc, char *argv[]) { int ret; int stype; struct parsed_options options; init_parsed_options(&options); parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ comedi_perror(options.filename); exit(-1); } stype = comedi_get_subdevice_type(device, options.subdevice); if(stype != COMEDI_SUBD_DIO){ printf("%d is not a digital I/O subdevice\n", options.subdevice); exit(-1); } printf("configuring pin %d on subdevice %d ", options.channel, options.subdevice); if(options.value) { printf("for output.\n"); ret = comedi_dio_config(device, options.subdevice, options.channel, COMEDI_OUTPUT); }else { printf("for input.\n"); ret = comedi_dio_config(device, options.subdevice, options.channel, COMEDI_INPUT); } if(ret < 0){ comedi_perror("comedi_dio_config"); exit(-1); } return 0; }
int main(int argc, char *argv[]) { unsigned period_ns; int retval; lsampl_t clock_selection; struct parsed_options options; init_parsed_options(&options); options.freq = 0.; parse_options(&options, argc, argv); device = comedi_open(options.filename); if(!device){ comedi_perror(options.filename); exit(-1); } if(options.freq > 0.) period_ns = 1e9 / options.freq; else period_ns = 0; clock_selection = options.value; printf("Selecting master clock %d for channel %d on subdevice %d.\n", clock_selection, options.channel, options.subdevice); if(period_ns) { printf("Clock period = %d nanoseconds.\n", period_ns); }else { printf("Clock period unspecified.\n"); } retval = comedi_set_clock_source(device, options.subdevice, options.channel, clock_selection, period_ns); if(retval < 0) comedi_perror("comedi_set_clock_source"); comedi_close(device); return retval; }
int main(int argc, char *argv[]) { int ret; comedi_insn insn; lsampl_t d[5]; comedi_t *device; int freq; struct parsed_options options; init_parsed_options(&options); options.freq = -1; // we hijack this option to switch it on or off options.n_scan = -1; options.value = -1; parse_options(&options, argc, argv); if ((options.value==-1)&&(options.n_scan==-1)&&(options.freq==-1)) { fprintf(stderr, "Usage: %s OPTIONS duty_cycle\n" "options: \n" " -N 0 switches PWM off\n" " -N 1 switches PWM on\n" " -N 2 enquires the max value for the duty cycle\n" " -F FREQ sets the PWM frequency\n", argv[0]); } device = comedi_open(options.filename); if(!device){ comedi_perror(options.filename); exit(-1); } options.subdevice = comedi_find_subdevice_by_type(device,COMEDI_SUBD_PWM,0); if (options.verbose) printf("PWM subdevice autodetection gave subdevice number %d\n", options.subdevice); if(options.n_scan==2) { printf("%d\n",comedi_get_maxdata(device,options.subdevice,0)); comedi_close(device); exit(0); } insn.insn=INSN_CONFIG; insn.data=d; insn.subdev=options.subdevice; insn.chanspec=CR_PACK(0,0,0); if(options.n_scan==1) { d[0] = INSN_CONFIG_ARM; d[1] = 0; insn.n=2; ret=comedi_do_insn(device,&insn); if(ret < 0){ fprintf(stderr,"Could not switch on:%d\n",ret); comedi_perror(options.filename); exit(-1); } } if(options.n_scan==0) { d[0] = INSN_CONFIG_DISARM; d[1] = 0; insn.n=1; ret=comedi_do_insn(device,&insn); if(ret < 0){ fprintf(stderr,"Could not switch off:%d\n",ret); comedi_perror(options.filename); exit(-1); } } if(options.freq>0) { freq = options.freq; d[0] = INSN_CONFIG_PWM_SET_PERIOD; d[1] = 1E9/freq; insn.n=2; ret=comedi_do_insn(device,&insn); if(ret < 0){ fprintf(stderr,"Could set frequ:%d\n",ret); comedi_perror(options.filename); exit(-1); } } d[0] = INSN_CONFIG_GET_PWM_STATUS; insn.n=2; ret=comedi_do_insn(device,&insn); if(ret < 0){ fprintf(stderr,"Could not get status:%d insn=%d\n", ret, d[0]); comedi_perror(options.filename); exit(-1); } if (options.verbose) { if (d[1]) fprintf(stderr, "PWM is on.\n"); else fprintf(stderr, "PWM is off.\n"); } d[0] = INSN_CONFIG_PWM_GET_PERIOD; insn.n=2; ret=comedi_do_insn(device,&insn); if(ret < 0){ fprintf(stderr,"Could get frequ:%d\n",ret); comedi_perror(options.filename); exit(-1); } freq = 1E9 / d[1]; if (options.verbose) fprintf(stderr,"PWM frequency is %d\n", freq); if (options.value>=0) if(comedi_data_write(device, options.subdevice, options.channel, 0, 0, options.value)<0) { fprintf(stderr,"error setting the pwm duty cycle on "); comedi_perror(options.filename); exit(1); } return 0; }
int main(int argc, char **argv) { int i, j; long int procid; char outstring1[100]; FILE *in, *image1, *image2, *image3, *image4, *out; struct parsed_options options; unsigned short *samples = NULL; umask(000); init_parsed_options(&options); parse_options(&options, argc, argv); nice(10); sprintf(instring,"%s/process_rt_data_running",options.tmpdir); out = fopen(instring, "r"); if (out != NULL) { fprintf(stderr, "\nrprocess_rt_data found a lock file ... "); fscanf(out, "%lu", &procid); fprintf(stderr, "\n PID: %lu", procid); fclose(out); sprintf(outstring1,"/proc/%lu/cmdline",procid); out = fopen(outstring1, "r"); if (out != NULL) { fscanf(out, "%s", outstring1); sprintf(instring,"process_real_time_data"); //if( strncmp(outstring1,"/home/radio",11)==0 ) if (strstr(outstring1, instring) != NULL) { fprintf(stderr, "\n Process Exists. Exiting ...\n\n"); fclose(out); exit(0); } fclose(out); } sprintf(instring,"%s/process_rt_data_running",options.tmpdir); remove(instring); fprintf(stderr, "\n Process Does Not Exist. Lock File Removed\n"); } sprintf(instring,"%s/process_rt_data_running",options.tmpdir); out = fopen(instring, "w"); if (out != NULL) { fprintf(out, "%lu", (long unsigned int) getpid()); fclose(out); } else { fprintf(stderr, "Couldn't write lock file %s?!", instring); exit(-1); } /* initialize the images */ for (i = 0; i < 512; i++) for (j = 0; j < IMAGE_WIDTH; j++) { im1o[i][j] = 20.; im2o[i][j] = 20.; im3o[i][j] = 20.; im4o[i][j] = 20.; } /* initialize Hann window */ for (i = 0; i < 1024; i++) { hann[i] = 0.5 * (1 - cos(2*M_PI*i/1023)); } /* initialize the fftw3 plans */ plan_forward1 = fftw_plan_r2r_1d(1024, fft_samples1, out1, FFTW_R2HC, FFTW_MEASURE); plan_forward2 = fftw_plan_r2r_1d(1024, fft_samples2, out2, FFTW_R2HC, FFTW_MEASURE); plan_forward3 = fftw_plan_r2r_1d(1024, fft_samples3, out3, FFTW_R2HC, FFTW_MEASURE); plan_forward4 = fftw_plan_r2r_1d(1024, fft_samples4, out4, FFTW_R2HC, FFTW_MEASURE); while (1) { /* read in the new data */ read_new_samples(samples, &options); /* fft the new data */ fft_new_samples(samples); sprintf(instring,"%s/hf2_display_running",options.tmpdir); in = fopen(instring, "r"); if (in != NULL) { write_data = 1; fclose(in); } else write_data = 0; sprintf(instring,"%s/levels.grayscale",options.tmpdir); in = fopen(instring, "r"); if (in != NULL) { fscanf(in, "%d %d", &gray_min, &gray_max); fclose(in); } else { gray_min = 0; gray_max = 60.; } if (old_gray_min != gray_min || old_gray_max != gray_max) rescale_images(); if (write_data) { sprintf(instring,"%s/test.data",options.tmpdir); out = fopen(instring, "w"); } else { printf("hf2_display not running?\n"); } for (i = 0; i < 512; i++) { x[i] = i * df; memcpy(*(im1+i),&im1[i][1],IMAGE_WIDTH-1); memcpy(*(im2+i),&im2[i][1],IMAGE_WIDTH-1); memcpy(*(im3+i),&im3[i][1],IMAGE_WIDTH-1); memcpy(*(im4+i),&im4[i][1],IMAGE_WIDTH-1); memcpy((im1o+i),&im1o[i][1],(IMAGE_WIDTH-1)*sizeof(float)); memcpy((im2o+i),&im2o[i][1],(IMAGE_WIDTH-1)*sizeof(float)); memcpy((im3o+i),&im3o[i][1],(IMAGE_WIDTH-1)*sizeof(float)); memcpy((im4o+i),&im4o[i][1],(IMAGE_WIDTH-1)*sizeof(float)); r1 = out1[i]; r2 = out2[i]; r3 = out3[i]; r4 = out4[i]; im1o[512 - i][IMAGE_WIDTH-1] = r1; im2o[512 - i][IMAGE_WIDTH-1] = r2; im3o[512 - i][IMAGE_WIDTH-1] = r3; im4o[512 - i][IMAGE_WIDTH-1] = r4; v1 = a + r1 * b + 0.5; v2 = a + r2 * b + 0.5; v3 = a + r3 * b + 0.5; v4 = a + r4 * b + 0.5; if (v1 < 0) v1 = 0; if (v2 < 0) v2 = 0; if (v3 < 0) v3 = 0; if (v4 < 0) v4 = 0; if (v1 > 255) v1 = 255; if (v2 > 255) v2 = 255; if (v3 > 255) v3 = 255; if (v4 > 255) v4 = 255; im1[512 - i][IMAGE_WIDTH-1] = 255 - (unsigned char) v1; im2[512 - i][IMAGE_WIDTH-1] = 255 - (unsigned char) v2; im3[512 - i][IMAGE_WIDTH-1] = 255 - (unsigned char) v3; im4[512 - i][IMAGE_WIDTH-1] = 255 - (unsigned char) v4; if (write_data) fprintf(out, "%.0f %.2f %.2f %.2f\n", x[i], r1, r2, r3); } if (write_data) { fclose(out); sprintf(instring,"%s/test.image1",options.tmpdir); image1 = fopen(instring, "w"); fprintf(image1, "P5\n%i 512\n255\n",IMAGE_WIDTH); fwrite(im1, sizeof(im1), 1, image1); fclose(image1); sprintf(instring,"%s/test.image2",options.tmpdir); image2 = fopen(instring, "w"); fprintf(image2, "P5\n%i 512\n255\n",IMAGE_WIDTH); fwrite(im2, sizeof(im2), 1, image2); fclose(image2); sprintf(instring,"%s/test.image3",options.tmpdir); image3 = fopen(instring, "w"); fprintf(image3, "P5\n%i 512\n255\n",IMAGE_WIDTH); fwrite(im3, sizeof(im3), 1, image3); fclose(image3); sprintf(instring,"%s/test.image4",options.tmpdir); image4 = fopen(instring, "w"); fprintf(image4, "P5\n%i 512\n255\n",IMAGE_WIDTH); fwrite(im4, sizeof(im4), 1, image4); fclose(image4); } usleep(1e4); } return (0); }
static PyObject* comediModule(PyObject* self, PyObject* args) { char *device; int subdevice; int channel; int range; int aref; int n_chan; int n_scan; float freq; if (!PyArg_ParseTuple(args, "siiiiiif", &device, &subdevice, &channel, &range, &aref, &n_chan, &n_scan, &freq)) return NULL; comedi_t *dev; comedi_cmd c,*cmd=&c; int ret; int total=0; int i; struct timeval start,end; int subdev_flags; lsampl_t raw; struct parsed_options options; init_parsed_options(&options); options.filename = device; options.subdevice = subdevice; options.channel = channel; options.range = range; options.aref = aref; options.n_chan = n_chan; options.n_scan = n_scan; options.freq = freq; /* open the device */ dev = comedi_open(options.filename); if(!dev){ comedi_perror(options.filename); exit(1); } // Print numbers for clipped inputs comedi_set_global_oor_behavior(COMEDI_OOR_NUMBER); /* Set up channel list */ for(i = 0; i < options.n_chan; i++){ chanlist[i] = CR_PACK(options.channel + i, options.range, options.aref); range_info[i] = comedi_get_range(dev, options.subdevice, options.channel, options.range); maxdata[i] = comedi_get_maxdata(dev, options.subdevice, options.channel); } prepare_cmd_lib(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd); fprintf(stderr, "command before testing:\n"); dump_cmd(stderr, cmd); ret = comedi_command_test(dev, cmd); if(ret < 0){ comedi_perror("comedi_command_test"); if(errno == EIO){ fprintf(stderr,"Ummm... this subdevice doesn't support commands\n"); } exit(1); } fprintf(stderr,"first test returned %d (%s)\n", ret, cmdtest_messages[ret]); dump_cmd(stderr, cmd); ret = comedi_command_test(dev, cmd); if(ret < 0){ comedi_perror("comedi_command_test"); exit(1); } fprintf(stderr,"second test returned %d (%s)\n", ret, cmdtest_messages[ret]); if(ret!=0){ dump_cmd(stderr, cmd); fprintf(stderr, "Error preparing command\n"); exit(1); } /* this is only for informational purposes */ gettimeofday(&start, NULL); fprintf(stderr,"start time: %ld.%06ld\n", start.tv_sec, start.tv_usec); /* start the command */ ret = comedi_command(dev, cmd); if(ret < 0){ comedi_perror("comedi_command"); exit(1); } subdev_flags = comedi_get_subdevice_flags(dev, options.subdevice); const int ndim = 2; npy_intp nd[2] = {n_scan, n_chan}; PyObject *myarray; double *array_buffer; myarray = PyArray_SimpleNew(ndim, nd, NPY_DOUBLE); Py_INCREF(myarray); array_buffer = (double *)PyArray_DATA(myarray); while(1){ ret = read(comedi_fileno(dev),buf,BUFSZ); if(ret < 0){ /* some error occurred */ perror("read"); break; }else if(ret == 0){ /* reached stop condition */ break; }else{ static int col = 0; double j = 0.0; int bytes_per_sample; total += ret; if(options.verbose)fprintf(stderr, "read %d %d\n", ret, total); if(subdev_flags & SDF_LSAMPL) bytes_per_sample = sizeof(lsampl_t); else bytes_per_sample = sizeof(sampl_t); for(i = 0; i < ret / bytes_per_sample; i++){ if(subdev_flags & SDF_LSAMPL) { raw = ((lsampl_t *)buf)[i]; } else { raw = ((sampl_t *)buf)[i]; } *array_buffer++ = print_datum(raw, col, 1); col++; if(col == options.n_chan){ col=0; j++; printf("\n"); } } } } /* this is only for informational purposes */ gettimeofday(&end,NULL); fprintf(stderr,"end time: %ld.%06ld\n", end.tv_sec, end.tv_usec); end.tv_sec -= start.tv_sec; if(end.tv_usec < start.tv_usec){ end.tv_sec--; end.tv_usec += 1000000; } end.tv_usec -= start.tv_usec; fprintf(stderr,"time: %ld.%06ld\n", end.tv_sec, end.tv_usec); return myarray; }
int main(int argc, char *argv[]) { comedi_cmd cmd; int err; int n, m, k; comedi_t *dev; unsigned int chanlist[100]; unsigned int maxdata; comedi_range *rng; int ret; struct parsed_options options; int fn = 256*256; sampl_t *data, *dp; float v; init_parsed_options(&options); options.subdevice = -1; options.n_chan = 100000;/* default number of samples */ parse_options(&options, argc, argv); dev = comedi_open( options.filename ); if(dev == NULL){ fprintf(stderr, "error opening %s\n", options.filename); return -1; } if(options.subdevice < 0) options.subdevice = comedi_find_subdevice_by_type(dev, COMEDI_SUBD_AI, 0); maxdata = comedi_get_maxdata(dev, options.subdevice, options.channel); rng = comedi_get_range(dev, options.subdevice, options.channel, options.range); memset(&cmd,0,sizeof(cmd)); /* cmd.subdev = options.subdevice; cmd.flags = 0; cmd.start_src = TRIG_INT; cmd.start_arg = 0; cmd.scan_begin_src = TRIG_TIMER; cmd.scan_begin_arg = 1e9 / options.freq; cmd.convert_src = TRIG_TIMER; cmd.convert_arg = 1e9 / options.freq / 50; cmd.scan_end_src = TRIG_COUNT; cmd.scan_end_arg = options.n_chan; cmd.stop_src = TRIG_COUNT; cmd.stop_arg = fn; cmd.stop_src = TRIG_NONE; cmd.stop_arg = 0; */ cmd.scan_begin_src = TRIG_TIMER; cmd.flags = TRIG_ROUND_NEAREST; err = comedi_get_cmd_generic_timed( dev, options.subdevice, &cmd, options.n_chan, 1e9 / options.freq ); cmd.start_src = TRIG_INT; cmd.start_arg = 0; cmd.scan_end_arg = options.n_chan; cmd.stop_src = TRIG_NONE; cmd.stop_arg = 0; cmd.chanlist = chanlist; cmd.chanlist_len = options.n_chan; for ( k=0; k<options.n_chan; k++ ) chanlist[k] = CR_PACK(k, options.range, options.aref); dump_cmd(stderr,&cmd); if ( cmd.scan_begin_arg > 1e9 / options.freq ) { fprintf( stderr, "frequency too high! Maximum possible is %g Hz\n", 1.0e9/cmd.scan_begin_arg ); comedi_close( dev ); return 1; } err = comedi_command_test(dev, &cmd); if (err > 0 && err != 4 ) { fprintf( stderr, "comedi_command_test returned %d\n", err ); dump_cmd(stdout,&cmd); exit(1); } err = comedi_command_test(dev, &cmd); if (err > 0 && err != 4 ) { fprintf( stderr, "comedi_command_test returned %d\n", err ); dump_cmd(stdout,&cmd); exit(1); } dump_cmd(stderr,&cmd); /* init data buffer: */ data = (sampl_t *)malloc( fn*sizeof( sampl_t ) ); if(data == NULL ){ perror("malloc\n"); exit(1); } fprintf( stderr, "execute command ...\n" ); if ((err = comedi_command(dev, &cmd)) < 0) { comedi_perror("comedi_command"); exit(1); } fprintf( stderr, "start analog input ...\n" ); ret = comedi_internal_trigger(dev, options.subdevice, 0); if(ret < 0){ perror("comedi_internal_trigger\n"); exit(1); } n = 0; while( 1 ) { m = read(comedi_fileno(dev),(void *)data,fn*sizeof( sampl_t)); if(m<0){ if ( errno != EAGAIN ) { perror("read"); exit(0); } else { fprintf( stderr, "... no more data can be read! Try later.\n" ); usleep( 100000 ); } } else { m /= sizeof( sampl_t); fprintf( stderr, "read %d samples\n",m); n+=m; } } comedi_cancel( dev, cmd.subdev ); fprintf( stderr, "finished\n" ); /* save data: */ dp = data; for ( k=0; k<n; k++ ) { v = comedi_to_phys(*dp, rng, maxdata); printf( "%g\n", v ); /* printf( "%d\n", *dp );*/ ++dp; } free( data ); comedi_close( dev ); return 0; }
int main(int argc, char *argv[]) { comedi_t *dev; comedi_cmd c,*cmd=&c; int ret; int total=0; int i; struct timeval start,end; int subdev_flags; lsampl_t raw; struct parsed_options options; init_parsed_options(&options); parse_options(&options, argc, argv); /* The following variables used in this demo * can be modified by command line * options. When modifying this demo, you may want to * change them here. */ options.filename = "/dev/comedi0"; options.subdevice = 0; options.channel = 0; options.range = 6; options.aref = AREF_DIFF; options.n_chan = 8; options.n_scan = 100000; options.freq = 1000.0; options.physical = 1; /* open the device */ dev = comedi_open(options.filename); if(!dev){ comedi_perror(options.filename); exit(1); } // Print numbers for clipped inputs comedi_set_global_oor_behavior(COMEDI_OOR_NUMBER); /* Set up channel list */ //for(i = 0; i < options.n_chan/2; i++){ for(i = 0; i < options.n_chan; i++){ chanlist[i] = CR_PACK(options.channel + i, options.range, options.aref); range_info[i] = comedi_get_range(dev, options.subdevice, options.channel, options.range); maxdata[i] = comedi_get_maxdata(dev, options.subdevice, options.channel); } /* for(i = options.n_chan/2; i < options.n_chan; i++){ fprintf(stderr,"%d: %d\n", i, options.channel + i + 8); chanlist[i] = CR_PACK(options.channel + i + 8, options.range, options.aref); range_info[i] = comedi_get_range(dev, options.subdevice, options.channel, options.range); maxdata[i] = comedi_get_maxdata(dev, options.subdevice, options.channel); } */ /* prepare_cmd_lib() uses a Comedilib routine to find a * good command for the device. prepare_cmd() explicitly * creates a command, which may not work for your device. */ prepare_cmd_lib(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd); //prepare_cmd(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd); fprintf(stderr, "command:\n"); dump_cmd(stderr, cmd); /* this is only for informational purposes */ gettimeofday(&start, NULL); fprintf(stderr,"start time: %ld.%06ld\n", start.tv_sec, start.tv_usec); /* start the command */ ret = comedi_command(dev, cmd); if(ret < 0){ comedi_perror("comedi_command"); exit(1); } subdev_flags = comedi_get_subdevice_flags(dev, options.subdevice); while(1){ ret = read(comedi_fileno(dev),buf,BUFSZ); if(ret < 0){ /* some error occurred */ perror("read"); continue; }else if(ret == 0){ /* reached stop condition */ break; }else{ static int col = 0; int bytes_per_sample; total += ret; if(options.verbose)fprintf(stderr, "read %d %d\n", ret, total); if(subdev_flags & SDF_LSAMPL) bytes_per_sample = sizeof(lsampl_t); else bytes_per_sample = sizeof(sampl_t); for(i = 0; i < ret / bytes_per_sample; i++){ if(subdev_flags & SDF_LSAMPL) { raw = ((lsampl_t *)buf)[i]; } else { raw = ((sampl_t *)buf)[i]; } print_datum(raw, col, options.physical); col++; if(col == options.n_chan){ printf("\n"); col=0; } } } } /* this is only for informational purposes */ gettimeofday(&end,NULL); fprintf(stderr,"end time: %ld.%06ld\n", end.tv_sec, end.tv_usec); end.tv_sec -= start.tv_sec; if(end.tv_usec < start.tv_usec){ end.tv_sec--; end.tv_usec += 1000000; } end.tv_usec -= start.tv_usec; fprintf(stderr,"time: %ld.%06ld\n", end.tv_sec, end.tv_usec); return 0; }