updated status of 6713
[comedilib.git] / perl / mode2lib.perl
1
2 #   A little input demo
3
4 use Comedi qw( :Functions :Constants );
5 use Comedi::Lib;
6
7 use constant AI_DEV => 0;
8 use constant AI_SUB => 0;
9 use constant AO_DEV => 0;
10 use constant AO_SUB => 1;
11 use constant N_SAMPLES => 100;
12
13 $fn = '/dev/comedi0';
14
15 # create a channel list
16 #
17 @ch = ( CR_PACK(0, 0, AREF_GROUND));
18
19 $d = comedi_open($fn) || die "Can't open '$fn': " . comedi_error();
20
21 $freq = $opt_f || 1000;
22
23 # convert the requested frequency into a timer value
24 #
25 ($ret = comedi_get_timer($d, AI_SUB, $freq, $ticks, $actual_freq)) == 0 ||
26     die "Can't get timer: " . comedi_strerror($ret);
27
28 $buf = pack('d*', 100..(100+N_SAMPLES-1));
29
30 ($ret =
31  comedi_timed_1chan($d, AI_SUB, 0, 0, AREF_GROUND, 1000, N_SAMPLES, $buf)) == 0 ||
32     die "Analog input error ($ret): " . comedi_strerror(comedi_errno()) ;
33
34 foreach (unpack('d*', $buf)) {
35     printf("%g\n", $_);
36 }
37
38