(unknown charset) Re: Comedi problem: reading analog input

Oh yeah.  comedi_t * is an opaque type to clients of the library (your
program) and you should never dereference it in non-comedi-library code.

The comedi_data_read() call should be:

comedi_data_read(cf,subdev,chan,range,aref,&data);


On Thu, 13 Jun 2002, [iso-8859-1] ANDRES ESCOBAR wrote:

>  --- "Calin A. Culianu" <calin_at_ajvar.org> escribió: >
> On Thu, 13 Jun 2002, [iso-8859-1] ANDRES ESCOBAR
> > wrote:
> >
> > > Hi all,
> > >
> > > I tried to read an analog input channel.
> > >
> > >
> > > The segment of code and the problem are as
> > follows:
> > >
> > >
> > > #include <stdio.h> /* for printf() */
> > > #include <comedi.h> /* also included by
> > comedilib.h */
> > > #include <comedilib.h> /* 'cuz we're using
> > comedilib
> > > */
> > >
> > > int subdev = 0;         /* change this to your
> > input
> > > subdevice */
> > > int chan = 0;           /* change this to your
> > channel
> > > */
> > > int range = 0;          /* more on this later */
> > > int aref = 0;           /* more on this later */
> > >
> > > int main(int argc,char *argv[])
> > >
> > > {
> > >         comedi_t *cf;
> > >         int chan=0;
> > >         lsampl_t data;
> > > 	int maxdata,rangetype;
> > > 	double volts;
> > >
> > >         cf=comedi_open("/dev/comedi0");
> > >
> > > 	maxdata=comedi_get_maxdata(cf,subdev,chan);
> > >
> > > 	rangetype=comedi_get_rangetype(cf,subdev,chan);
> > >
> > >
> > >
> >
> comedi_data_read(cf->fd,subdev,chan,range,aref,&data);
> > >
> > >
> > volts=comedi_to_phys(data,rangetype,range,maxdata);
> > >
> > >         printf("%d %g\n",data,volts);
> > >
> > >         return 0;
> > > }
> > >
> > >
> > > the name of the program is secondcomedi.c, and
> > then a
> > > try to compile:
> > >
> > > control:/home# cc secondcomedi.c -lcomedi -o
> > > secondcomedi
> > >
> > > and I obtain:
> > >
> > > secondcomedi.c: In function `main':
> > > secondcomedi.c:25: dereferencing pointer to
> > incomplete
> > > type
> > > secondcomedi.c:27: warning: passing arg 2 of
> > > `comedi_to_phys' makes pointer from integer
> > without a
> > > cast
> > > secondcomedi.c:27 too many arguments to function
> > > `comedi_to phys'
> >
> >
> > comedi_to_phys() takes a comedi_range * argument,
> > not an int/int pair as
> > you have.  change the comedi_to_phys() call to:
> >
> >
> >
> volts=comedi_to_phys(data,comedi_get_range(cf,subdev,chan,range),maxdata);
> >
> >
> > >
> > >
> > > what is wrong?
> > >
> > > Thanks.
>
>
>
>
> I make the changes:
>
>
>
> #include <stdio.h> /* for printf() */
> #include <comedi.h> /* also included by comedilib.h */
> #include <comedilib.h> /* 'cuz we're using comedilib
> */
>
> int subdev = 0;         /* change this to your input
> subdevice */
> int chan = 0;           /* change this to your channel
> */
> int range = 0;
> int aref = 0;
>
> int main(int argc,char *argv[])
>
> {
>         comedi_t *cf;
>         int chan=0;
>         lsampl_t data;
> 	int maxdata,rangetype;
> 	double volts;
>
>         cf=comedi_open("/dev/comedi0");
>
> 	maxdata=comedi_get_maxdata(cf,subdev,chan);
>
> 	rangetype=comedi_get_rangetype(cf,subdev,chan);
>
>
> comedi_data_read(cf->fd,subdev,chan,range,aref,&data);
>
>
> volts=comedi_to_phys(data,comedi_get_range(cf,subdev,chan,range),maxdata);
>
>         printf("%d %g\n",data,volts);
>
>         return 0;
> }
>
>
>
> and I obtain again:
>
> secondcomedi.c: In function `main':
> secondcomedi.c:25: dereferencing pointer to incomplete
> type
>
>
>
> Cobertura especial de la Copa Mundial de la FIFA Corea-Japón 2002, sólo en Yahoo! Deportes:
> http://ar.sports.yahoo.com/fifaworldcup/
>
>
> _______________________________________________
> comedi mailing list
> comedi_at_stm.lbl.gov
> http://stm.lbl.gov/cgi-bin/mailman/listinfo/comedi
>

Received on 2002-06-13Z21:09:37