/* * Example of using commands - asynchronous input * Part of Comedilib * * Copyright (c) 1999,2000 David A. Schleef * * This file may be freely modified, distributed, and combined with * other software, as long as proper attribution is given in the * source code. */ /* * An example for directly using Comedi commands. Comedi commands * are used for asynchronous acquisition, with the timing controlled * by on-board timers or external events. */ #include #include #include #include #include #include #include #include #include #include "examples.h" unsigned int chanlist[256]; void *map; int prepare_cmd_lib(comedi_t *dev,int subdevice,comedi_cmd *cmd); int prepare_cmd(comedi_t *dev,int subdevice,comedi_cmd *cmd); int main(int argc, char *argv[]) { comedi_t *dev; comedi_cmd c,*cmd=&c; int size; int front, back; int ret; int i; parse_options(argc,argv); dev = comedi_open(filename); if(!dev){ comedi_perror(filename); exit(1); } size = comedi_get_buffer_size(dev,subdevice); fprintf(stderr,"buffer size is %d\n",size); map=mmap(NULL,size,PROT_READ,MAP_SHARED,comedi_fileno(dev),0); fprintf(stderr,"map=%p\n",map); if( map == MAP_FAILED ){ perror( "mmap" ); exit(1); } for(i=0;ichanlist = chanlist; cmd->chanlist_len = n_chan; cmd->scan_end_arg = n_chan; if(cmd->stop_src==TRIG_COUNT)cmd->stop_arg = n_scan; return 0; } int prepare_cmd(comedi_t *dev,int subdevice,comedi_cmd *cmd) { memset(cmd,0,sizeof(*cmd)); cmd->subdev = subdevice; cmd->flags = 0; cmd->start_src = TRIG_NOW; cmd->start_arg = 0; cmd->scan_begin_src = TRIG_TIMER; cmd->scan_begin_arg = 1e9/freq; cmd->convert_src = TRIG_TIMER; cmd->convert_arg = 1; cmd->scan_end_src = TRIG_COUNT; cmd->scan_end_arg = n_chan; cmd->stop_src = TRIG_NONE; cmd->stop_arg = 0; cmd->chanlist = chanlist; cmd->chanlist_len = n_chan; return 0; }