2000-10-19 06:28:27 +00:00
|
|
|
/*
|
|
|
|
* Multi-channel, multi-range one-shot input demo
|
|
|
|
* Part of Comedilib
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* This file may be freely modified, distributed, and combined with
|
|
|
|
* other software, as long as proper attribution is given in the
|
|
|
|
* source code.
|
|
|
|
*/
|
2000-02-02 05:14:23 +00:00
|
|
|
/*
|
|
|
|
This demo opens /dev/comedi0 and looks for an analog input
|
|
|
|
subdevice. If it finds one, it measures one sample on each
|
|
|
|
channel for each input range. The value NaN indicates that
|
|
|
|
the measurement was out of range.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <comedilib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2003-01-01 23:07:02 +00:00
|
|
|
#include <stdlib.h>
|
2000-02-02 05:14:23 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <ctype.h>
|
2000-10-19 06:28:27 +00:00
|
|
|
#include "examples.h"
|
2000-02-02 05:14:23 +00:00
|
|
|
|
|
|
|
comedi_t *device;
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int n_chans,chan;
|
|
|
|
int n_ranges;
|
|
|
|
int range;
|
|
|
|
int maxdata;
|
|
|
|
lsampl_t data;
|
|
|
|
double voltage;
|
2007-01-03 21:14:53 +00:00
|
|
|
struct parsed_options options;
|
2000-02-02 05:14:23 +00:00
|
|
|
|
2007-01-03 21:14:53 +00:00
|
|
|
init_parsed_options(&options);
|
|
|
|
options.subdevice = -1;
|
|
|
|
parse_options(&options, argc, argv);
|
2000-02-02 05:14:23 +00:00
|
|
|
|
2007-01-03 21:14:53 +00:00
|
|
|
device = comedi_open(options.filename);
|
2000-02-02 05:14:23 +00:00
|
|
|
if(!device){
|
2007-01-03 21:14:53 +00:00
|
|
|
comedi_perror(options.filename);
|
|
|
|
exit(-1);
|
2000-02-02 05:14:23 +00:00
|
|
|
}
|
|
|
|
|
2007-01-03 21:14:53 +00:00
|
|
|
if(options.subdevice < 0)
|
|
|
|
{
|
|
|
|
options.subdevice = comedi_find_subdevice_by_type(device, COMEDI_SUBD_AI, 0);
|
|
|
|
if(options.subdevice<0){
|
|
|
|
printf("no analog input subdevice found\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2000-02-02 05:14:23 +00:00
|
|
|
}
|
2007-01-03 21:14:53 +00:00
|
|
|
n_chans = comedi_get_n_channels(device, options.subdevice);
|
|
|
|
for(chan = 0; chan < n_chans; ++chan){
|
|
|
|
printf("%d: ", chan);
|
2000-02-02 05:14:23 +00:00
|
|
|
|
2007-01-03 21:14:53 +00:00
|
|
|
n_ranges = comedi_get_n_ranges(device, options.subdevice, chan);
|
2000-02-02 05:14:23 +00:00
|
|
|
|
2007-01-03 21:14:53 +00:00
|
|
|
maxdata = comedi_get_maxdata(device, options.subdevice, chan);
|
|
|
|
for(range = 0; range < n_ranges; range++){
|
2014-01-09 15:23:13 +00:00
|
|
|
comedi_data_read(device, options.subdevice, chan, range, options.aref, &data);
|
|
|
|
voltage = comedi_to_phys(data, comedi_get_range(device, options.subdevice, chan, range), maxdata);
|
2007-01-03 21:14:53 +00:00
|
|
|
printf("%g ", voltage);
|
2000-02-02 05:14:23 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2007-01-03 21:14:53 +00:00
|
|
|
return 0;
|
2000-02-02 05:14:23 +00:00
|
|
|
}
|
|
|
|
|