added comedi_data_read_hint() and fixed comedi_data_read_n()
authorFrank Mori Hess <fmhess@speakeasy.net>
Mon, 29 Apr 2002 19:50:32 +0000 (19:50 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Mon, 29 Apr 2002 19:50:32 +0000 (19:50 +0000)
include/comedilib.h
lib/data.c

index 75be94f3abf3cfe513a4e0a493076ee723a1dcaf..df0104b46e386ec8e79c23b4d56c1c4d2db9b424 100644 (file)
@@ -118,6 +118,8 @@ lsampl_t comedi_from_phys(double data,comedi_range *rng,lsampl_t maxdata);
 /* syncronous stuff */
 int comedi_data_read(comedi_t *it,unsigned int subd,unsigned int chan,
        unsigned int range,unsigned int aref,lsampl_t *data);
+int comedi_data_read_hint(comedi_t *it,unsigned int subd,unsigned int chan,
+       unsigned int range,unsigned int aref);
 int comedi_data_read_delayed(comedi_t *it,unsigned int subd,unsigned int chan,
        unsigned int range,unsigned int aref,lsampl_t *data, unsigned int nano_sec);
 int comedi_data_write(comedi_t *it,unsigned int subd,unsigned int chan,
index 590c37f1109c30fc4b556f5fd27cc1adcdd71be5..fdec01b4eb1494e0b46120c1716d0bb872482b31 100644 (file)
@@ -85,46 +85,15 @@ int comedi_data_write(comedi_t *it,unsigned int subdev,unsigned int chan,unsigne
        }
 }
 
-
-int comedi_data_read_n(comedi_t *it,unsigned int subdev,unsigned int chan,
-               unsigned int range, unsigned int aref,lsampl_t *data,
-               unsigned int n)
+int comedi_data_read_n(comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range,
+               unsigned int aref, lsampl_t *data, unsigned int n)
 {
        subdevice *s;
-       comedi_insn insn;
 
        if(!valid_chan(it,subdev,chan))
                return -1;
 
-       s=it->subdevices+subdev;
-
-       if(it->has_insnlist_ioctl){
-
-               memset(&insn,0,sizeof(insn));
-
-               insn.insn = INSN_READ;
-               insn.n = 1;
-               insn.data = data;
-               insn.subdev = subdev;
-               insn.chanspec = CR_PACK(chan,range,aref);
-
-               return comedi_do_insn(it,&insn);
-       }else{
-               /* There's no need to be fast for a case that is
-                * obsolete. */
-               return comedi_data_read(it,subdev,chan,range,aref,data);
-       }
-}
-
-int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range,
-               unsigned int aref,lsampl_t *data)
-{
-       subdevice *s;
-
-       if(!valid_chan(it,subdev,chan))
-               return -1;
-
-       s=it->subdevices+subdev;
+       s = it->subdevices + subdev;
 
        if(it->has_insnlist_ioctl){
                comedi_insn insn;
@@ -132,7 +101,7 @@ int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned
                memset(&insn,0,sizeof(insn));
 
                insn.insn = INSN_READ;
-               insn.n = 1;
+               insn.n = n;
                insn.data = data;
                insn.subdev = subdev;
                insn.chanspec = CR_PACK(chan,range,aref);
@@ -143,22 +112,23 @@ int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned
                        mode:           0,
                        flags:          0,
                        n_chan:         1,
-                       n:              1,
+                       n:              n,
                        trigsrc:        0,
                        trigvar:        0,
                        trigvar1:       0,
                };
                int ret;
-               sampl_t sdata;
+               sampl_t sdata[n];
+               unsigned int i;
 
                chan=CR_PACK(chan,range,aref);
-       
+
                cmd.subdev=subdev;
                cmd.chanlist=&chan;
                if(s->subd_flags & SDF_LSAMPL){
                        cmd.data=(sampl_t *)data;
                }else{
-                       cmd.data=&sdata;
+                       cmd.data=sdata;
                }
 
                ret=ioctl_trigger(it->fd,&cmd);
@@ -166,13 +136,27 @@ int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned
                        return ret;
 
                if(!(s->subd_flags & SDF_LSAMPL)){
-                       *data=sdata;
+                       for( i = 0; i < n; i++)
+                               data[i] = sdata[i];
                }
 
                return 0;
        }
 }
 
+int comedi_data_read(comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range,
+       unsigned int aref, lsampl_t *data)
+{
+       return comedi_data_read_n(it, subdev, chan, range, aref, data, 1);
+}
+
+int comedi_data_read_hint(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range,
+unsigned int aref)
+{
+       lsampl_t dummy_data;
+       return comedi_data_read_n(it, subdev, chan, range, aref, &dummy_data, 0);
+}
+
 int comedi_data_read_delayed( comedi_t *it, unsigned int subdev, unsigned int chan, unsigned int range,
        unsigned int aref, lsampl_t *data, unsigned int nano_sec)
 {
@@ -187,7 +171,7 @@ int comedi_data_read_delayed( comedi_t *it, unsigned int subdev, unsigned int ch
        s = it->subdevices + subdev;
 
        memset( insn, 0, sizeof(insn) );
-       memset( ilist, 0, sizeof(ilist) );
+       memset( &ilist, 0, sizeof(ilist) );
 
        // setup, no conversions
        insn[0].insn = INSN_READ;