From af2f7409a2fd6073f87f86a7e661208a8c70fdf3 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Mon, 18 Mar 2002 21:50:40 +0000 Subject: [PATCH] Changes to make it a little more robust --- demo/cmd.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/demo/cmd.c b/demo/cmd.c index 9c3f253..82c3f36 100644 --- a/demo/cmd.c +++ b/demo/cmd.c @@ -85,8 +85,8 @@ 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,subdevice,cmd); - prepare_cmd(dev,subdevice,cmd); + prepare_cmd_lib(dev,subdevice,cmd); + //prepare_cmd(dev,subdevice,cmd); fprintf(stderr,"command before testing:\n"); dump_cmd(stderr,cmd); @@ -126,6 +126,10 @@ int main(int argc, char *argv[]) exit(1); } + /* this is only for informational purposes */ + gettimeofday(&start,NULL); + fprintf(stderr,"start time: %ld.%06ld\n",start.tv_sec,start.tv_usec); + /* start the command */ ret=comedi_command(dev,cmd); if(ret<0){ @@ -133,10 +137,6 @@ int main(int argc, char *argv[]) exit(1); } - /* this is only for informational purposes */ - gettimeofday(&start,NULL); - fprintf(stderr,"start time: %ld.%06ld\n",start.tv_sec,start.tv_usec); - while(1){ ret=read(comedi_fileno(dev),buf,BUFSZ); if(ret<0){ @@ -184,11 +184,16 @@ int prepare_cmd_lib(comedi_t *dev,int subdevice,comedi_cmd *cmd) { int ret; + memset(cmd,0,sizeof(*cmd)); + /* This comedilib function will get us a generic timed * command for a particular board. If it returns -1, * that's bad. */ ret = comedi_get_cmd_generic_timed(dev,subdevice,cmd,1e9/freq); - if(ret<0)return ret; + if(ret<0){ + printf("comedi_get_cmd_generic_timed failed\n"); + return ret; + } /* Modify parts of the command */ cmd->chanlist = chanlist; -- 2.26.2