![]() |
RTXI 1.3
|
00001 /* 00002 * Multi-channel, multi-range one-shot input demo 00003 * Part of Comedilib 00004 * 00005 * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org> 00006 * 00007 * This file may be freely modified, distributed, and combined with 00008 * other software, as long as proper attribution is given in the 00009 * source code. 00010 */ 00011 /* 00012 This demo opens /dev/comedi0 and looks for an analog input 00013 subdevice. If it finds one, it measures one sample on each 00014 channel for each input range. The value NaN indicates that 00015 the measurement was out of range. 00016 */ 00017 00018 #include <stdio.h> 00019 #include <comedilib.h> 00020 #include <fcntl.h> 00021 #include <unistd.h> 00022 #include <stdlib.h> 00023 #include <errno.h> 00024 #include <getopt.h> 00025 #include <ctype.h> 00026 #include "examples.h" 00027 00028 comedi_t *device; 00029 00030 00031 int main(int argc, char *argv[]) 00032 { 00033 int n_chans,chan; 00034 int n_ranges; 00035 int range; 00036 int maxdata; 00037 lsampl_t data; 00038 double voltage; 00039 struct parsed_options options; 00040 00041 init_parsed_options(&options); 00042 options.subdevice = -1; 00043 parse_options(&options, argc, argv); 00044 00045 device = comedi_open(options.filename); 00046 if(!device){ 00047 comedi_perror(options.filename); 00048 exit(-1); 00049 } 00050 00051 if(options.subdevice < 0) 00052 { 00053 options.subdevice = comedi_find_subdevice_by_type(device, COMEDI_SUBD_AI, 0); 00054 if(options.subdevice<0){ 00055 printf("no analog input subdevice found\n"); 00056 exit(-1); 00057 } 00058 } 00059 n_chans = comedi_get_n_channels(device, options.subdevice); 00060 for(chan = 0; chan < n_chans; ++chan){ 00061 printf("%d: ", chan); 00062 00063 n_ranges = comedi_get_n_ranges(device, options.subdevice, chan); 00064 00065 maxdata = comedi_get_maxdata(device, options.subdevice, chan); 00066 for(range = 0; range < n_ranges; range++){ 00067 comedi_data_read(device, options.subdevice, chan, options.range, options.aref, &data); 00068 voltage = comedi_to_phys(data, comedi_get_range(device, options.subdevice, chan, options.range), maxdata); 00069 printf("%g ", voltage); 00070 } 00071 printf("\n"); 00072 } 00073 return 0; 00074 } 00075