From 653d264765e7647ed80489ad15da75a1ed67c37d Mon Sep 17 00:00:00 2001 From: David Schleef Date: Thu, 30 Mar 2000 00:17:55 +0000 Subject: [PATCH] added command support --- lib/Makefile | 2 +- lib/command.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 lib/command.c diff --git a/lib/Makefile b/lib/Makefile index 6ffbdbf..afcc160 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,7 +2,7 @@ CFLAGS=-fPIC -Wall -O2 -I../include -I. OBJS=comedi.o timer.o sv.o range.o ioctl.o filler.o timed.o error.o \ - dio.o data.o get.o + dio.o data.o get.o command.o libcomedi.a: $(OBJS) #gcc -shared -Wl,-soname,libcomedi.so,-T,version_script -o libcomedi.so.${VERSION_CODE} $(OBJS) -lm diff --git a/lib/command.c b/lib/command.c new file mode 100644 index 0000000..d1aedd1 --- /dev/null +++ b/lib/command.c @@ -0,0 +1,156 @@ +/* + lib/command.c + comedi library routines + + COMEDILIB - Control and Measurement Device Interface Library + Copyright (C) 2000 David A. Schleef + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + + +int comedi_data_write(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range, + unsigned int aref,lsampl_t data) +{ + comedi_trig cmd={ + mode: 0, + flags: TRIG_WRITE, + n_chan: 1, + n: 1, + trigsrc: 0, + trigvar: 0, + trigvar1: 0, + }; + sampl_t sdata=data; + + if(!valid_chan(it,subdev,chan)) + return -1; + + chan=CR_PACK(chan,range,aref); + + cmd.subdev=subdev; + if(it->subdevices[subdev].subd_flags & SDF_LSAMPL){ + cmd.data=(sampl_t *)(&data); + }else{ + cmd.data=&sdata; + } + cmd.chanlist=&chan; + + return ioctl_trigger(it->fd,&cmd); +} + + +int comedi_data_read(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range, + unsigned int aref,lsampl_t *data) +{ + comedi_trig cmd={ + mode: 0, + flags: 0, + n_chan: 1, + n: 1, + trigsrc: 0, + trigvar: 0, + trigvar1: 0, + }; + int ret; + sampl_t sdata; + + if(!valid_chan(it,subdev,chan)) + return -1; + + chan=CR_PACK(chan,range,aref); + + cmd.subdev=subdev; + cmd.chanlist=&chan; + if(it->subdevices[subdev].subd_flags & SDF_LSAMPL){ + cmd.data=(sampl_t *)data; + }else{ + cmd.data=&sdata; + } + + ret=ioctl_trigger(it->fd,&cmd); + if(ret<0) + return ret; + + if(!(it->subdevices[subdev].subd_flags & SDF_LSAMPL)){ + *data=sdata; + } + + return 0; +} + +#if 1 +/* + I don't like this function, which is why it is marked out. + The problem is the sampl_t/lsampl_t fiasco, which is beginning + to be a PITA. + */ +int comedi_data_read_n(comedi_t *it,unsigned int subdev,unsigned int chan,unsigned int range, + unsigned int aref,unsigned int n,lsampl_t *data) +{ + comedi_trig cmd; + unsigned int i; + int ret; + + if(!valid_chan(it,subdev,chan)) + return -1; + + if(n==0) + return 0; + + chan=CR_PACK(chan,range,aref); + + memset(&cmd,0,sizeof(cmd)); + cmd.mode=0; + cmd.n_chan=1; + cmd.subdev=subdev; + cmd.chanlist=&chan; + + i=0; + while(ifd,&cmd); + if(ret<0) + goto out; + + i+=ret; + } +out: + if(i==0)return -1; + + return (int)i; +} +#endif + + + -- 2.26.2