2 * A very small one-shot input demo
5 * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
7 * This file may be freely modified, distributed, and combined with
8 * other software, as long as proper attribution is given in the
16 #include <comedilib.h>
29 int main(int argc, char *argv[])
33 comedi_range * range_info;
35 double physical_value;
36 struct parsed_options options;
38 init_parsed_options(&options);
39 parse_options(&options, argc, argv);
41 device = comedi_open(options.filename);
43 comedi_perror(options.filename);
48 printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n",
49 options.filename, options.subdevice, options.channel, options.range, options.aref);
52 ret = comedi_data_read(device, options.subdevice, options.channel, options.range, options.aref, &data);
54 comedi_perror(options.filename);
58 if(options.physical) {
59 comedi_set_global_oor_behavior(COMEDI_OOR_NAN);
60 range_info = comedi_get_range(device, options.subdevice, options.channel, options.range);
61 maxdata = comedi_get_maxdata(device, options.subdevice, options.channel);
63 printf("[0,%d] -> [%g,%g]\n", maxdata,
64 range_info->min, range_info->max);
66 physical_value = comedi_to_phys(data, range_info, maxdata);
67 if(isnan(physical_value)) {
68 printf("Out of range [%g,%g]",
69 range_info->min, range_info->max);
71 printf("%g", physical_value);
72 switch(range_info->unit) {
73 case UNIT_volt: printf(" V"); break;
74 case UNIT_mA: printf(" mA"); break;
75 case UNIT_none: break;
76 default: printf(" (unknown unit %d)",
80 printf(" (%lu raw units)", (unsigned long)data);
84 printf("%lu", (unsigned long)data);