comedi_data_read — read single sample from channel


#include <comedilib.h>
int comedi_data_read(comedi_t * device,
 unsigned int subdevice,
 unsigned int channel,
 unsigned int range,
 unsigned int aref,
 lsampl_t * data);


Reads a single sample on the channel specified by the Comedi device device, the subdevice subdevice, and the channel channel. For the A/D conversion (if appropriate), the device is configured to use range specification range and (if appropriate) analog reference type aref. Analog reference types that are not supported by the device are silently ignored.

The function comedi_data_read reads one data value from the specified channel and stores the value in *data.

WARNING: comedi_data_read does not do any pausing to allow multiplexed analog inputs to settle before starting an analog to digital conversion. If you are switching between different channels and need to allow your analog input to settle for an accurate reading, use comedi_data_read_delayed, or set the input channel at an earlier time with comedi_data_read_hint.

Data values returned by this function are unsigned integers less than or equal to the maximum sample value of the channel, which can be determined using the function comedi_get_maxdata. Conversion of data values to physical units can be performed by the functions comedi_to_phys (linear conversion) or comedi_to_physical (non-linear polynomial conversion).

Return value

On success, comedi_data_read returns 1 (the number of samples read). If there is an error, -1 is returned.