5 * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
7 * This file may be freely modified, distributed, and combined with
8 * other software, as long as proper attribution is given in the
12 * Requirements: A board with a digital I/O subdevice. Not just
13 * a 'digital input' or 'digital output' subdevice, but one in
14 * which the channels can be configured between input and output.
20 #include <comedilib.h>
40 void prepare_cmd(comedi_t *dev,comedi_cmd *cmd);
41 void do_cmd(comedi_t *dev,comedi_cmd *cmd);
43 int main(int argc, char *argv[])
50 parse_options(argc,argv);
52 //fn = "/dev/comedi1";
55 dev = comedi_open(fn);
64 if(channel)pin_data=channel;
66 ret = fcntl(comedi_fileno(dev),F_SETFL,O_NONBLOCK);
67 if(ret<0)perror("fcntl");
69 prepare_cmd(dev,&cmd);
77 static unsigned int bits =0;
79 void do_cmd(comedi_t *dev,comedi_cmd *cmd)
81 unsigned int *chanlist;
86 struct timeval timeout;
89 chanlist = cmd->chanlist;
90 n_chans = cmd->chanlist_len;
92 ret=comedi_command_test(dev,cmd);
94 //printf("test ret=%d\n",ret);
96 printf("errno=%d\n",errno);
97 comedi_perror("comedi_command_test");
101 dump_cmd(stdout,cmd);
103 cmd->chanlist = chanlist;
104 cmd->chanlist_len = n_chans;
106 ret=comedi_command_test(dev,cmd);
108 printf("test ret=%d\n",ret);
110 printf("errno=%d\n",errno);
111 comedi_perror("comedi_command_test");
115 dump_cmd(stdout,cmd);
117 cmd->chanlist = chanlist;
118 cmd->chanlist_len = n_chans;
120 ret=comedi_command(dev,cmd);
122 printf("ret=%d\n",ret);
124 printf("errno=%d\n",errno);
125 comedi_perror("comedi_command");
132 FD_SET(comedi_fileno(dev),&rdset);
134 timeout.tv_usec=50000;
135 ret = select(comedi_fileno(dev)+1,&rdset,NULL,NULL,&timeout);
140 fprintf(stderr,"\n");
144 }else if(FD_ISSET(comedi_fileno(dev),&rdset)){
145 ret=read(comedi_fileno(dev),buf,BUFSZ);
157 for(i=0;i<ret/sizeof(sampl_t);i++){
158 fprintf(stderr,"%d",buf[i]>0xa000);
161 fprintf(stderr,"\n");
165 //printf("%d %d\n",buf[i],buf[i]>0xa000);
166 //printf("%d",buf[i]>0xa000);
168 bits|=(buf[i]>0xa000);
174 gettimeofday(&now,NULL);
175 printf(" %08x %ld.%06ld\n",bits,now.tv_sec,now.tv_usec);
179 printf(" %08x\n",bits);
194 unsigned int chanlist[16];
196 * This part of the demo measures channels 1, 2, 3, 4 at a rate of
197 * 10 khz, with the inter-sample time at 10 us (100 khz). The number
198 * of scans measured is 10. This is analogous to the old mode2
201 void prepare_cmd(comedi_t *dev,comedi_cmd *cmd)
203 memset(cmd,0,sizeof(comedi_cmd));
205 /* the subdevice that the command is sent to */
206 cmd->subdev = subdevice;
209 cmd->flags = TRIG_WAKE_EOS;
211 cmd->start_src = TRIG_NOW;
214 cmd->scan_begin_src = TRIG_EXT;
215 cmd->scan_begin_arg = CR_EDGE | CR_INVERT | pin_clk;
218 cmd->convert_src = TRIG_TIMER;
219 cmd->convert_arg = 1;
221 cmd->convert_src = TRIG_ANY;
222 cmd->convert_arg = 0;
225 cmd->scan_end_src = TRIG_COUNT;
226 cmd->scan_end_arg = 1;
228 cmd->stop_src = TRIG_NONE;
231 cmd->chanlist = chanlist;
232 cmd->chanlist_len = 1;
234 chanlist[0]=CR_PACK(pin_data,0,0);