Debian Codegraph @

demo/inp.c

raw symbols SCIP
1 /*
2 * A very small one-shot input demo
3 * Part of Comedilib
4 *
5 * Copyright (c) 1999,2000 David A. Schleef <[email protected]>
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 A little input demo
13 */
14
15 #include <stdio.h>
16 #include <comedilib.h>cxx . . $ `<file>/include/comedilib.h`/
17 #include <fcntl.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <errno.h>
21 #include <getopt.h>
22 #include <ctype.h>
23 #include <math.h>
24 #include "examples.h"cxx . . $ `<file>/demo/examples.h`/
25
26 comedi_tcxx . . $ comedi_t# *devicecxx . . $ device.;
27
28
29 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
30 {
31 lsampl_tcxx . . $ lsampl_t# data;
32 int ret;
33 comedi_rangecxx . . $ comedi_range# * range_info;
34 lsampl_tcxx . . $ lsampl_t# maxdata;
35 double physical_value;
36 struct parsed_optionscxx . . $ parsed_options# options;
37
38 init_parsed_optionscxx . . $ init_parsed_options(8caace97c9c42d8f).(&options);
39 parse_optionscxx . . $ parse_options(b6aabb1543a6f628).(&options, argc, argv);
40
41 devicecxx . . $ device. = comedi_opencxx . . $ comedi_open(d67864c6c007fe39).(options.filenamecxx . . $ parsed_options#filename.);
42 if(!devicecxx . . $ device.){
43 comedi_perrorcxx . . $ comedi_perror(85c52e162fed56f9).(options.filenamecxx . . $ parsed_options#filename.);
44 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
45 }
46
47 if(options.verbosecxx . . $ parsed_options#verbose.){
48 printfcxx . . $ printf(581fddd72a8db8fc).("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
49 options.filenamecxx . . $ parsed_options#filename., options.subdevicecxx . . $ parsed_options#subdevice., options.channelcxx . . $ parsed_options#channel., options.rangecxx . . $ parsed_options#range., options.arefcxx . . $ parsed_options#aref.);
50 }
51
52 ret = comedi_data_readcxx . . $ comedi_data_read(ed662314c4dc98c9).(devicecxx . . $ device., options.subdevicecxx . . $ parsed_options#subdevice., options.channelcxx . . $ parsed_options#channel., options.rangecxx . . $ parsed_options#range., options.arefcxx . . $ parsed_options#aref., &data);
53 if(ret < 0){
54 comedi_perrorcxx . . $ comedi_perror(85c52e162fed56f9).(options.filenamecxx . . $ parsed_options#filename.);
55 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
56 }
57
58 if(options.physicalcxx . . $ parsed_options#physical.) {
59 comedi_set_global_oor_behaviorcxx . . $ comedi_set_global_oor_behavior(711436fe91983c69).(COMEDI_OOR_NANcxx . . $ COMEDI_OOR_NAN.);
60 range_info = comedi_get_rangecxx . . $ comedi_get_range(60f094977346e00a).(devicecxx . . $ device., options.subdevicecxx . . $ parsed_options#subdevice., options.channelcxx . . $ parsed_options#channel., options.rangecxx . . $ parsed_options#range.);
61 maxdata = comedi_get_maxdatacxx . . $ comedi_get_maxdata(9f5413f81e406f65).(devicecxx . . $ device., options.subdevicecxx . . $ parsed_options#subdevice., options.channelcxx . . $ parsed_options#channel.);
62 if(options.verbosecxx . . $ parsed_options#verbose.) {
63 printfcxx . . $ printf(581fddd72a8db8fc).("[0,%d] -> [%g,%g]\n", maxdata,
64 range_info->mincxx . . $ $anonymous_type_e3831e245d0fb292_0#min., range_info->maxcxx . . $ $anonymous_type_e3831e245d0fb292_0#max.);
65 }
66 physical_value = comedi_to_physcxx . . $ comedi_to_phys(28294eee26a5294e).(data, range_info, maxdata);
67 if(isnancxx . . $ `<external>/11263917310783833665/math.h:980:11`!(physical_value)) {
68 printfcxx . . $ printf(581fddd72a8db8fc).("Out of range [%g,%g]",
69 range_info->mincxx . . $ $anonymous_type_e3831e245d0fb292_0#min., range_info->maxcxx . . $ $anonymous_type_e3831e245d0fb292_0#max.);
70 } else {
71 printfcxx . . $ printf(581fddd72a8db8fc).("%g", physical_value);
72 switch(range_info->unitcxx . . $ $anonymous_type_e3831e245d0fb292_0#unit.) {
73 case UNIT_voltcxx . . $ `include/comedi.h:930:9`!: printfcxx . . $ printf(581fddd72a8db8fc).(" V"); break;
74 case UNIT_mAcxx . . $ `include/comedi.h:931:9`!: printfcxx . . $ printf(581fddd72a8db8fc).(" mA"); break;
75 case UNIT_nonecxx . . $ `include/comedi.h:932:9`!: break;
76 default: printfcxx . . $ printf(581fddd72a8db8fc).(" (unknown unit %d)",
77 range_info->unitcxx . . $ $anonymous_type_e3831e245d0fb292_0#unit.);
78 }
79 if(options.verbosecxx . . $ parsed_options#verbose.) {
80 printfcxx . . $ printf(581fddd72a8db8fc).(" (%lu raw units)", (unsigned long)data);
81 }
82 }
83 } else {
84 printfcxx . . $ printf(581fddd72a8db8fc).("%lu", (unsigned long)data);
85 }
86 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
87
88 return 0;
89 }
90