doc/dio_funcref.txt: Some DocBook mark-up changes.
[comedilib.git] / testing / inttrig.c
1
2 #include <stdio.h>
3 #include <comedilib.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <sys/ioctl.h>
7 #include <errno.h>
8 #include <getopt.h>
9 #include <ctype.h>
10 #include <math.h>
11 #include <sys/time.h>
12 #include <string.h>
13 #include "comedi_test.h"
14
15 #define BUFSZ 2000
16
17 int test_cmd_start_inttrig(void)
18 {
19         comedi_cmd cmd;
20         char buf[BUFSZ];
21         unsigned int chanlist[1];
22         int go;
23         int total=0;
24         int ret;
25         unsigned int flags;
26
27         flags = comedi_get_subdevice_flags(device,subdevice);
28         if(!(flags&SDF_CMD) || (comedi_get_read_subdevice(device)!=subdevice)){
29                 printf("not applicable\n");
30                 return 0;
31         }
32
33         if(comedi_get_cmd_src_mask(device,subdevice,&cmd)<0){
34                 printf("  not supported\n");
35                 return 0;
36         }
37
38         if(!(cmd.start_src&TRIG_INT)){
39                 printf("  not supported\n");
40                 return 0;
41         }
42
43         if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){
44                 printf("  not supported\n");
45                 return 0;
46         }
47
48         if(realtime)cmd.flags |= TRIG_RT;
49         cmd.chanlist = chanlist;
50         cmd.start_src = TRIG_INT;
51         cmd.start_arg = 0;
52         cmd.scan_end_arg = 1;
53         cmd.stop_arg = 100;
54         cmd.chanlist_len = 1;
55         chanlist[0] = CR_PACK(0,0,0);
56
57         ret = comedi_command(device,&cmd);
58         if(ret!=0){
59                 printf("E: comedi_command() returned %d, expecting 0\n",ret);
60         }
61
62         ret = comedi_internal_trigger(device,subdevice,0);
63         if(ret<0){
64                 printf("E: comedi_internal_trigger(): %s\n",strerror(errno));
65         }
66
67         go=1;
68         while(go){
69                 ret = read(comedi_fileno(device),buf,BUFSZ);
70                 if(ret<0){
71                         if(errno==EAGAIN){
72                                 usleep(10000);
73                         }else{
74                                 go = 0;
75                                 printf("E: read: %s\n",strerror(errno));
76                         }
77                 }else if(ret==0){
78                         go = 0;
79                 }else{
80                         total += ret;
81                         if(verbose)
82                                 printf("read %d %d\n",ret,total);
83                 }
84         }
85
86         return 0;
87 }
88
89