13 #include "comedi_test.h"
15 static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd);
16 static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd);
20 int test_read_select(void)
24 unsigned int chanlist[1];
31 struct timeval timeout;
33 if(comedi_get_cmd_fast_1chan(device,subdevice,&cmd)<0){
34 printf(" not supported\n");
38 cmd.chanlist = chanlist;
40 cmd.stop_arg = length;
42 chanlist[0] = CR_PACK(0,0,0);
44 //fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK);
46 comedi_command(device,&cmd);
51 FD_SET(comedi_fileno(device),&rdset);
53 timeout.tv_usec = 10000;
54 ret = select(comedi_fileno(device)+1,&rdset,NULL,NULL,&timeout);
58 if(verbose)printf("timeout\n");
60 ret = read(comedi_fileno(device),buf,BUFSZ);
61 if(verbose)printf("read==%d\n",ret);
64 printf("E: got EAGAIN!\n");
81 static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd)
83 memset(cmd,0,sizeof(*cmd));
89 cmd->start_src = TRIG_ANY;
90 cmd->scan_begin_src = TRIG_ANY;
91 cmd->convert_src = TRIG_ANY;
92 cmd->scan_end_src = TRIG_ANY;
93 cmd->stop_src = TRIG_ANY;
95 return comedi_command_test(it,cmd);
99 static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd)
103 ret = comedi_get_cmd_src_mask(it,s,cmd);
106 cmd->chanlist_len = 1;
108 cmd->scan_end_src = TRIG_COUNT;
109 cmd->scan_end_arg = 1;
111 if(cmd->convert_src&TRIG_TIMER){
112 if(cmd->scan_begin_src&TRIG_FOLLOW){
113 cmd->convert_src = TRIG_TIMER;
114 cmd->scan_begin_src = TRIG_FOLLOW;
116 cmd->convert_src = TRIG_TIMER;
117 cmd->scan_begin_src = TRIG_TIMER;
120 printf("can't do timed?!?\n");
123 if(cmd->stop_src&TRIG_COUNT){
124 cmd->stop_src=TRIG_COUNT;
126 }else if(cmd->stop_src&TRIG_NONE){
127 cmd->stop_src=TRIG_NONE;
130 printf("can't find a good stop_src\n");
134 ret=comedi_command_test(it,cmd);
137 ret=comedi_command_test(it,cmd);
139 if(ret==4 || ret==0){