5 COMEDILIB - Linux Control and Measurement Device Interface Library
6 Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation, version 2.1
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <sys/types.h>
31 #include <sys/ioctl.h>
36 #include <libinternal.h>
38 INTERNAL int __comedi_init=0;
40 INTERNAL void initialize(void)
46 if( (s=getenv("COMEDILIB_LOGLEVEL")) ){
47 __comedi_loglevel=strtol(s,NULL,0);
48 DEBUG(3,"setting loglevel to %d\n",__comedi_loglevel);
52 comedi_t *comedi_open(const char *fn)
59 if(!(it=malloc(sizeof(comedi_t))))
61 memset(it,0,sizeof(comedi_t));
63 if((it->fd=open(fn,O_RDWR))<0){
68 if(ioctl_devinfo(it->fd,&it->devinfo)<0)
71 it->n_subdevices=it->devinfo.n_subdevs;
75 it->magic=COMEDILIB_MAGIC;
86 /* this is an example of how we do versioned symbols */
87 __asm__(".symver comedi_open_0,comedi_open@");
90 int comedi_close(comedi_t *it)
97 for(i=0;i<it->n_subdevices;i++){
99 if(s->type==COMEDI_SUBD_UNUSED)
102 if(s->subd_flags&SDF_FLAGS){
105 if(s->subd_flags&SDF_MAXDATA){
106 free(s->maxdata_list);
108 if(s->subd_flags&SDF_RANGETYPE){
109 free(s->range_type_list);
110 free(s->rangeinfo_list);
114 if(s->cmd_mask)free(s->cmd_mask);
115 if(s->cmd_timed)free(s->cmd_timed);
118 free(it->subdevices);
125 int comedi_cancel(comedi_t *it,unsigned int subdevice)
127 return ioctl(it->fd,COMEDI_CANCEL,subdevice);
130 int comedi_poll(comedi_t *it,unsigned int subdevice)
132 return ioctl(it->fd,COMEDI_POLL,subdevice);
135 int comedi_fileno(comedi_t *it)
143 int comedi_trigger(comedi_t *it,comedi_trig *t)
148 return ioctl_trigger(it->fd,t);
151 int comedi_command(comedi_t *it,comedi_cmd *t)
154 ret = ioctl(it->fd,COMEDI_CMD,t);
155 __comedi_errno = errno;
156 switch(__comedi_errno){
158 __comedi_errno = ECMDNOTSUPP;
164 int comedi_command_test(comedi_t *it,comedi_cmd *t)
167 ret = ioctl(it->fd,COMEDI_CMDTEST,t);
168 __comedi_errno = errno;
169 switch(__comedi_errno){
171 __comedi_errno = ECMDNOTSUPP;
177 int comedi_do_insnlist(comedi_t *it,comedi_insnlist *il)
180 ret = ioctl(it->fd,COMEDI_INSNLIST,il);
181 __comedi_errno = errno;
185 int comedi_do_insn(comedi_t *it,comedi_insn *insn)
187 if(it->has_insn_ioctl){
188 return ioctl(it->fd,COMEDI_INSN,insn);
196 ret = ioctl(it->fd,COMEDI_INSNLIST,&il);
203 int comedi_lock(comedi_t *it,unsigned int subdevice)
205 return ioctl(it->fd,COMEDI_LOCK,subdevice);
208 int comedi_unlock(comedi_t *it,unsigned int subdevice)
210 return ioctl(it->fd,COMEDI_UNLOCK,subdevice);