- From: Jan Gukelberger <g.u.g.i_at_gmx.de>
- Date: Sun, 24 Sep 2006 23:46:19 +0200
On Wed, 2006-09-20 at 09:54 +1000, Wensheng Wang wrote:
> Thanks, Jan
>
> 在 2006-09-20三的 00:17 +0200,Jan Gukelberger写道:
> > Hi Wensheng,
> >
> > On Tue, 2006-09-19 at 16:04 +1000, Wensheng Wang wrote:
> > > Hi guys,
> > > I am working with comedi but have problems now.
> > > I tried to use select() call to scan data incoming, it
> > > seemed that I always got timeout and the device file
> > > change couldn't be reported (my digital I/O card
> > > doesn't support comedi_command).
> >
> > I'm not sure what you are trying to do. If your card does not support
> > commands, you cannot "wait for data".
> > You can read the state of a digital input channel via comedi_dio_read().
> >
> With your respond now I can stop trying select(), poll() or something
> stupid else, but I really need to scan all these digital I/O channel and
> only
> read updated data.
> Could you show me how to use comedi_dio_read() or other
> methods to get the only updated data ? Thank you very much
> in advance.
I'm afraid, AFAIK there is no such predefined comedi function.
So you'd have to keep the state read previously in a buffer and compare
with the current state to decide if anything has changed.
Something like:
unsigned previous = 0, current = 0, changed_bits = 0;
while( !stopped )
{
comedi_dio_bitfield( dev, sub, 0, ¤t );
changed_bits = current ^ previous;
if( changed_bits )
process_data( current, changed_bits );
previous = current;
sleep_some_appropriate_time();
}
HTH,
Jan
Received on 2006-09-24Z20:46:19