Listing 1. Sample Program for Acquiring Voltage from One Channel

#include <stdio.h>
#include <comedilib.h>

const char *filename = "/dev/comedi0";
int main(int argc, char *argv[])
{
  lsampl_t data;
  int ret;
  comedi_t *device;

  /* Which device on the card do we want to use? */
  int subdevice = 0;
  /* Which channel to use */
  int channel   = 0;
  /* Which of the available ranges to use */
  int range     = 0;
  /* Measure with a ground reference */
  int analogref = AREF_GROUND;

  device = comedi_open(filename);
  if(!device){
    /* We couldn't open the device - error out */
    comedi_perror(filename);
    exit(0);
  }

  /* Read in a data value */
  ret=comedi_data_read(device,subdevice,
    channel,range,analogref,&data);

  if(ret<0){
    /* Some error happened */
    comedi_perror(filename);
    exit(0);
  }

  printf("Got a data value: %d\n", data);
  return 0;
}

