- From: Jiri Baum <jiri_at_baum.com.au>
- Date: Mon, 11 Aug 2003 21:51:03 +1000
Klaas:
> Maybe the following program can clarify some things for the new
> comedi-user (at least, it did for me) at the end of section 3.2 or
> 3.3 of the documentation.
> #include <stdio.h> /* for printf() */
> #include <comedilib.h>
> int subdev = 0; /* change this to your input subdevice */
> int chan = 0; /* change this to your channel */
> int main(int argc,char *argv[])
> {
> comedi_t *cf;
> int num_ranges,i, maxdata;
> comedi_range crange;
> comedi_range * crange_p = &crange;
Surely crange is superfluous, and this should just be
comedi_range * crange_p = 0;
? (Alternatively, this might be declared inside the for-loop.)
> lsampl_t data;
> cf=comedi_open("/dev/comedi0");
> maxdata=comedi_get_maxdata(cf,subdev,chan);
> printf("MaxData = %d\n",maxdata);
> num_ranges = comedi_get_n_ranges(cf,subdev,chan);
> printf("NumRanges = %d\n",num_ranges);
> for (i = 0; i < num_ranges ; i++)
> {
> crange_p = comedi_get_range(cf, subdev, chan, i);
> printf("Range Struct (min, max, unit) = %f, %f, %d\n",
> crange_p->min, crange_p->max, crange_p->unit);
Presumably here should go
data = comedi_data_read(...);
? However, this could be dangerous if the input to the device is
incompatible with one or more of the ranges...
> printf("Convert data (%d) into volts with the above
> range_struct: %f\n",
> data, comedi_to_phys(data,crange_p,maxdata));
> }
> return 0;
> }
> - Still, I remain with one question. Why do you still have to pass
> the "unsigned int range, unsigned int aref" arguments to
> comedi_data_read() if you're using the above "device independent"
> code?
How else would the device know which range and zero reference to use?
You aren't telling it any other way...
Jiri
--
Jiri Baum <jiri_at_baum.com.au> http://www.csse.monash.edu.au/~jirib
MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools
Received on 2003-08-11Z10:51:03