From b7cb7f23313c7262baa89d920f2a1bc177412fb4 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 8 Nov 2016 13:48:56 +0000 Subject: [PATCH] demo/cmd: bail out if fail to prepare command Check return value of prepare_cmd_lib() and exit if less than 0. Also change prepare_cmd_lib() to write its error message to stderr instead of stdout. --- demo/cmd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/demo/cmd.c b/demo/cmd.c index cd574e0..f15cfe7 100644 --- a/demo/cmd.c +++ b/demo/cmd.c @@ -109,8 +109,11 @@ int main(int argc, char *argv[]) /* prepare_cmd_lib() uses a Comedilib routine to find a * good command for the device. prepare_cmd() explicitly * creates a command, which may not work for your device. */ - prepare_cmd_lib(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd); - //prepare_cmd(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd); + ret = prepare_cmd_lib(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd); + //ret = prepare_cmd(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd); + if(ret < 0){ + exit(1); + } fprintf(stderr, "command before testing:\n"); dump_cmd(stderr, cmd); @@ -234,7 +237,7 @@ int prepare_cmd_lib(comedi_t *dev, int subdevice, int n_scan, int n_chan, unsign * that's bad. */ ret = comedi_get_cmd_generic_timed(dev, subdevice, cmd, n_chan, scan_period_nanosec); if(ret<0){ - printf("comedi_get_cmd_generic_timed failed\n"); + fprintf(stderr,"comedi_get_cmd_generic_timed failed\n"); return ret; }