~ubuntu-branches/ubuntu/feisty/comedilib/feisty

« back to all changes in this revision

Viewing changes to testing/inttrig.c

  • Committer: Bazaar Package Importer
  • Author(s): David Schleef
  • Date: 2003-09-23 18:11:12 UTC
  • Revision ID: james.westby@ubuntu.com-20030923181112-sat05jyh702rb1at
Tags: upstream-0.7.21
ImportĀ upstreamĀ versionĀ 0.7.21

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 comedi_internal_trigger(comedi_t *device,unsigned int subdevice,
 
18
        unsigned int trignum)
 
19
{
 
20
        comedi_insn insn;
 
21
        lsampl_t data = 0;
 
22
 
 
23
#ifndef INSN_INTTRIG
 
24
#define INSN_INTTRIG            ( 6 | INSN_MASK_WRITE|INSN_MASK_SPECIAL)
 
25
#endif
 
26
        memset(&insn,0,sizeof(insn));
 
27
        insn.subdev = subdevice;
 
28
        insn.insn = INSN_INTTRIG;
 
29
        insn.n = 1;
 
30
        insn.data = &data;
 
31
 
 
32
        return comedi_do_insn(device,&insn);
 
33
}
 
34
 
 
35
 
 
36
int test_cmd_start_inttrig(void)
 
37
{
 
38
        comedi_cmd cmd;
 
39
        char buf[BUFSZ];
 
40
        unsigned int chanlist[1];
 
41
        int go;
 
42
        int total=0;
 
43
        int ret;
 
44
        unsigned int flags;
 
45
 
 
46
        flags = comedi_get_subdevice_flags(device,subdevice);
 
47
        if(!(flags&SDF_CMD) || flags&SDF_WRITEABLE){
 
48
                printf("not applicable\n");
 
49
                return 0;
 
50
        }
 
51
 
 
52
        if(comedi_get_cmd_src_mask(device,subdevice,&cmd)<0){
 
53
                printf("  not supported\n");
 
54
                return 0;
 
55
        }
 
56
 
 
57
        if(!(cmd.start_src&TRIG_INT)){
 
58
                printf("  not supported\n");
 
59
                return 0;
 
60
        }
 
61
 
 
62
        if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
 
63
                printf("  not supported\n");
 
64
                return 0;
 
65
        }
 
66
 
 
67
        if(realtime)cmd.flags |= TRIG_RT;
 
68
        cmd.chanlist = chanlist;
 
69
        cmd.start_src = TRIG_INT;
 
70
        cmd.start_arg = 0;
 
71
        cmd.scan_end_arg = 1;
 
72
        cmd.stop_arg = 100;
 
73
        cmd.chanlist_len = 1;
 
74
        chanlist[0] = CR_PACK(0,0,0);
 
75
 
 
76
        ret = comedi_command(device,&cmd);
 
77
        if(ret!=0){
 
78
                printf("E: comedi_command() returned %d, expecting 0\n",ret);
 
79
        }
 
80
 
 
81
        ret = comedi_internal_trigger(device,subdevice,0);
 
82
        if(ret<0){
 
83
                printf("E: comedi_internal_trigger(): %s\n",strerror(errno));
 
84
        }
 
85
 
 
86
        go=1;
 
87
        while(go){
 
88
                ret = read(comedi_fileno(device),buf,BUFSZ);
 
89
                if(ret<0){
 
90
                        if(errno==EAGAIN){
 
91
                                usleep(10000);
 
92
                        }else{
 
93
                                go = 0;
 
94
                                printf("E: read: %s\n",strerror(errno));
 
95
                        }
 
96
                }else if(ret==0){
 
97
                        go = 0;
 
98
                }else{
 
99
                        total += ret;
 
100
                        if(verbose)
 
101
                                printf("read %d %d\n",ret,total);
 
102
                }
 
103
        }
 
104
 
 
105
        return 0;
 
106
}
 
107
 
 
108