From 545b9420d5b665eba08c2b96d21bbcebf07d53c4 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Thu, 24 Feb 2005 20:46:56 +0000 Subject: [PATCH] added some error checks --- demo/tut2.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/demo/tut2.c b/demo/tut2.c index 056f4b7..4416602 100644 --- a/demo/tut2.c +++ b/demo/tut2.c @@ -16,6 +16,7 @@ int subdev = 0; /* change this to your input subdevice */ int chan = 0; /* change this to your channel */ 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[]) { @@ -24,11 +25,32 @@ int main(int argc, char *argv[]) int maxdata; double volts; comedi_range *cr; - - cf = comedi_open("/dev/comedi0"); + int retval; + + cf = comedi_open(filename); + if(cf == NULL) + { + 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); - comedi_data_read(cf, subdev, chan, range, aref, &data); + if(cr == NULL) + { + comedi_perror(filename); + return 1; + } + retval = comedi_data_read(cf, subdev, chan, range, aref, &data); + if(retval < 0) + { + comedi_perror(filename); + return 1; + } volts = comedi_to_phys(data, cr, maxdata); printf("%d %g\n", data, volts); -- 2.26.2