added stub for pci-6014
[comedilib.git] / demo / sender.c
1 /*
2  * Digital I/O example
3  * Part of Comedilib
4  *
5  * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
6  *
7  * This file may be freely modified, distributed, and combined with
8  * other software, as long as proper attribution is given in the
9  * source code.
10  */
11 /*
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.
15  */
16
17 #include <stdio.h>
18 #include <comedilib.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 #include <stdlib.h>
22 #include <errno.h>
23 #include <string.h>
24 #include "examples.h"
25
26
27 int chan_dat = 1;
28 int chan_clk = 0;
29
30 int wait1 = usec_to_nsec(0);
31 int wait2 = usec_to_nsec(0);
32
33 comedi_t *device;
34
35 void write_bits(int bits);
36
37
38 int main(int argc, char *argv[])
39 {
40         int ret;
41         int stype;
42         int i;
43
44         parse_options(argc,argv);
45
46         device=comedi_open(filename);
47         if(!device){
48                 comedi_perror(filename);
49                 exit(0);
50         }
51
52         subdevice = 2;
53
54         stype = comedi_get_subdevice_type(device,subdevice);
55         if(stype!=COMEDI_SUBD_DIO){
56                 printf("%d is not a digital I/O subdevice\n",subdevice);
57                 exit(0);
58         }
59
60         printf("configuring pin %d for output...\n",chan_dat);
61         ret=comedi_dio_config(device,subdevice,chan_dat,COMEDI_OUTPUT);
62         
63         printf("configuring pin %d for output...\n",chan_clk);
64         ret=comedi_dio_config(device,subdevice,chan_clk,COMEDI_OUTPUT);
65         
66         for(i=0;i<0x100;i++){
67                 write_bits(i);
68         }
69         //write_bits(0xa5);
70
71         return 0;
72 }
73
74
75 void write_bits(int bits)
76 {
77         comedi_insnlist il;
78         comedi_insn insn[5];
79         lsampl_t data[10];
80         int mask = (1<<chan_dat)|(1<<chan_clk);
81         int i;
82         int bit;
83         int ret;
84
85         il.n_insns = 5;
86         il.insns = insn;
87
88         memset(insn,0,sizeof(insn));
89
90         /* clock low, set data */
91         insn[0].insn = INSN_BITS;
92         insn[0].n = 2;
93         insn[0].data = data + 0;
94         insn[0].subdev = subdevice;
95
96         /* wait 1 */
97         insn[1].insn = INSN_WAIT;
98         insn[1].n = 1;
99         insn[1].data = data + 2;
100
101         /* clock high, same data */
102         insn[2].insn = INSN_BITS;
103         insn[2].n = 2;
104         insn[2].data = data + 4;
105         insn[2].subdev = subdevice;
106
107         /* wait 1 */
108         insn[3].insn = INSN_WAIT;
109         insn[3].n = 1;
110         insn[3].data = data + 6;
111
112         /* clock low, same data */
113         insn[4].insn = INSN_BITS;
114         insn[4].n = 2;
115         insn[4].data = data + 8;
116         insn[4].subdev = subdevice;
117
118
119         for(i=0;i<8;i++){
120                 bit=1<<(7-i);
121 //printf("writing %d\n",bit&bits);
122
123                 data[0] = mask;
124                 data[1] = (bits&bit)?(1<<chan_dat):0;
125
126                 data[2] = wait1;
127                 data[3] = 0;
128
129                 data[4] = mask;
130                 data[5] = ((bits&bit)?(1<<chan_dat):0)|(1<<chan_clk);
131
132                 data[6] = wait2;
133                 data[7] = 0;
134
135                 data[8] = mask;
136                 data[9] = (bits&bit)?(1<<chan_dat):0;
137
138                 ret = comedi_do_insnlist(device,&il);
139
140 //              printf("comedi_do_insnlist returned %d\n",ret);
141         }
142
143 }
144