- From: Klaas Gadeyne <Klaas.Gadeyne_at_mech.kuleuven.ac.be>
- Date: Mon, 11 Aug 2003 14:27:47 +0200 (CEST)
> > - 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...
If I put a signal of 30 mV (+- 10 mV, with a scope's "persist" option) on
an analog input of a NI-6024E card and I use the following program
======================================================================
#include <stdio.h> /* for printf() */
#include <comedilib.h>
int subdev = 0; /* change this to your input subdevice */
int chan = 1; // I do use channel 1
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);
comedi_data_read(cf,subdev,chan,i,AREF_GROUND,&data);
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;
}
======================================================
I get sometimes very weard results
this is the output:
[klaas_at_f012 /tmp]$
$ ./a.out
MaxData = 4095
NumRanges = 4
Range Struct (min, max, unit) = -10.000000, 10.000000, 0
Convert data (2051) into volts with the above range_struct: 0.017094
Range Struct (min, max, unit) = -5.000000, 5.000000, 0
Convert data (2046) into volts with the above range_struct: -0.003663
Range Struct (min, max, unit) = -0.500000, 0.500000, 0
Convert data (2206) into volts with the above range_struct: 0.038706
Range Struct (min, max, unit) = -0.050000, 0.050000, 0
Convert data (1025) into volts with the above range_struct: -0.024969
This does not do what I expect does it. The first three results could be
fine, but the last one should definitively be better. Or am I completely
missing something?
klaas
Received on 2003-08-11Z11:27:47