- From: Klaas Gadeyne <Klaas.Gadeyne_at_mech.kuleuven.ac.be>
- Date: Mon, 11 Aug 2003 10:46:22 +0200 (CEST)
Hi,
I have some questions and remarks with respect to the
comedilib documentation, in particular the part from section
3.2 "Converting samples to voltages" until 3.4, and the corresponding part
of the comedi function reference.
- comedi_get_range() (from the function reference 7.4)
#include <comedilib.h>
comedi_range * comedi_get_range(comedi_t * device, unsigned int
subdevice, unsigned int channel, unsigned int range);
The documentation does not mention the fact that range is one of
the possible ranges to be used for that channel and thus it should be
a number between 0 and comedi_get_n_ranges().
- comedi_to_phys()
<quote>
"Could it get easier?", you say. Well, yes. Use the function
comedi_to_phys(), which converts data values to physical units. Call
it using something like
volts=comedi_to_phys(it,data,range,maxdata);
</quote>
However, there are only 3 params to that function. I think it would be
better to change the above into:
double unit = comedi_to_phys(lsampl_t data, comedi_range * range, lsampl_t maxdata);
(replace "unit" with the unit defined in the comedi_range struct).
- The program in section 3.4 is obsolete. It doesn't even compile!
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;
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);
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?
Regards,
Klaas
Received on 2003-08-11Z07:46:22