Switched to use comedi_to_physical instead of deprecated comedi_to_phys.

This commit is contained in:
Frank Mori Hess 2008-02-08 16:23:36 +00:00
parent 9a472f9f4a
commit f6a4444de8

View file

@ -3,6 +3,7 @@
* Part of Comedilib
*
* Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
* Copyright (c) 2008 Frank Mori Hess <fmhess@users.sourceforge.net>
*
* This file may be freely modified, distributed, and combined with
* other software, as long as proper attribution is given in the
@ -10,6 +11,7 @@
*/
#include <stdio.h> /* for printf() */
#include <stdlib.h>
#include <comedilib.h>
int subdev = 0; /* change this to your input subdevice */
@ -18,41 +20,89 @@ int range = 0; /* more on this later */
int aref = AREF_GROUND; /* more on this later */
const char filename[] = "/dev/comedi0";
int main(int argc, char *argv[])
/* initialize a comedi_polynomial_t so it can be used with comedi_to_physical */
int get_converter(comedi_t *device, unsigned subdevice, unsigned channel,
unsigned range, comedi_polynomial_t *converter)
{
comedi_t *cf;
lsampl_t data;
int maxdata;
double volts;
comedi_range *cr;
int retval;
cf = comedi_open(filename);
if(cf == NULL)
int flags;
flags = comedi_get_subdevice_flags(device, subdevice);
if(flags < 0)
{
comedi_perror(filename);
return 1;
}
maxdata = comedi_get_maxdata(cf, subdev, chan);
if(maxdata == 0)
{
comedi_perror(filename);
return 1;
}
cr = comedi_get_range(cf, subdev, chan, range);
if(cr == NULL)
{
comedi_perror(filename);
return 1;
comedi_perror("comedi_get_subdevice_flags");
return -1;
}
retval = comedi_data_read(cf, subdev, chan, range, aref, &data);
if(retval < 0)
if(flags & SDF_SOFT_CALIBRATED) /* board uses software calibration */
{
comedi_perror(filename);
return 1;
char *calibration_file_path = comedi_get_default_calibration_path(device);
/* parse a calibration file which was produced by the
comedi_soft_calibrate program */
comedi_calibration_t* parsed_calibration =
comedi_parse_calibration_file(calibration_file_path);
free(calibration_file_path);
if(parsed_calibration == NULL)
{
comedi_perror("comedi_parse_calibration_file");
return -1;
}
/* get the comedi_polynomial_t for the subdevice/channel/range
we are interested in */
retval = comedi_get_softcal_converter(subdevice, channel, range,
COMEDI_TO_PHYSICAL, parsed_calibration, converter);
comedi_cleanup_calibration(parsed_calibration);
if(retval < 0)
{
comedi_perror("comedi_get_softcal_converter");
return -1;
}
}else /* board uses hardware calibration */
{
retval = comedi_get_hardcal_converter(device, subdevice, channel, range,
COMEDI_TO_PHYSICAL, converter);
if(retval < 0)
{
comedi_perror("comedi_get_hardcal_converter");
return -1;
}
}
volts = comedi_to_phys(data, cr, maxdata);
printf("%d %g\n", data, volts);
return 0;
}
int main(int argc, char *argv[])
{
comedi_t *it;
lsampl_t data;
double physical_value;
int retval;
comedi_polynomial_t converter;
it = comedi_open(filename);
if(it == NULL)
{
comedi_perror(filename);
return -1;
}
retval = comedi_data_read(it, subdev, chan, range, aref, &data);
if(retval < 0)
{
comedi_perror(filename);
return -1;
}
retval = get_converter(it, subdev, chan, range, &converter);
if(retval < 0)
{
return -1;
}
physical_value = comedi_to_physical(data, &converter);
printf("%d %g\n", data, physical_value);
return 0;
}