Handle IRQ with Comedi

70 views
Skip to first unread message

Sebas Inc

unread,
Feb 13, 2012, 9:41:16 PM2/13/12
to Comedi: Linux Control and Measurement Device Interface
hi,

somebody know handle interrupt in linux (Ubuntu)?
For example, if a digital pin of my NI_DAQ changes his state, i want
to run a routine (in Cpp, C++) for read a GPS in the serial port.


Thank you

Ian Abbott

unread,
Feb 15, 2012, 6:05:05 AM2/15/12
to comed...@googlegroups.com

There isn't an easy way to do this. One thing you can do is set up a
streaming "read" command on some subdevice using the digital pin as an
external trigger. The basic idea is that some thread in your
application can do a blocking read() to read some data from the
subdevice and then call the routine to read the GPS. You could also use
select() or poll() on the file to wait for it to become readable.

For NI DAQ cards, suitable subdevices for performing streaming read
commands are the AI subdevice (subdevice 0) or either of the GPCT
subdevices (11 or 12). However, because the main /dev/comedi0 (or
/dev/comedi1 etc.) file can only do the read() file operation on its
default "read" subdevice (which is subdevice 0 for NI DAQ), if you want
to set up a "read" command on subdevice 11 or 12, you need to open the
specific comedi subdevice file, for example "/dev/comedi0_subd11" and
set up the "read" command using that specific file descriptor.

For the "read" command itself, you want to set it up as follows:

cmd.subdev = the subdevice you want to read, which should be the "read"
subdevice for the /dev/comediX_subdY file you opened.

cmd.flags = TRIG_WAKE_EOS

cmd.start_src = TRIG_NOW (or TRIG_INT if you want to trigger it later)

cmd.start_arg = 0

cmd.scan_begin_src = TRIG_EXT

cmd.scan_begin_arg = CR_CHAN(ext trigger source) possibly ORed with
CR_INVERT

cmd.convert_src = TRIG_NOW (for GPCT subdevice) or TRIG_TIMER (for AI
subdevice)

cmd.convert_arg = 0

cmd.scan_end_src = TRIG_COUNT

cmd.scan_end_arg = 1

cmd.stop_src = TRIG_NONE

cmd.stop_arg = 0

cmd.chanlist_len = 1

cmd.chanlist = pointer to channel list of length 1 containing a valid
channel

If all is well with the command, it should read one sample of data from
the channel every time an external trigger occurs. The TRIG_WAKE_EOS
flag should result in the driver getting an interrupt after every scan
with one new scan of data in its internal buffer that can be read by the
read() system call, or will wake up any select() or poll() waiting for
the device to become readable.

--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

juan....@gmail.com

unread,
Feb 15, 2012, 7:40:01 AM2/15/12
to comed...@googlegroups.com
W
--
You received this message because you are subscribed to the Google Groups "Comedi: Linux Control and Measurement Device Interface" group.
To post to this group, send email to comed...@googlegroups.com.
To unsubscribe from this group, send email to comedi_list...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/comedi_list?hl=en.

Sebas Inc

unread,
Feb 15, 2012, 10:25:48 PM2/15/12
to Comedi: Linux Control and Measurement Device Interface
Ok! thanks,...
The trigger for mi routine is one of the digital ports of my NI_DAQ,
so
how should i write my code to do this?, I mean, i'm thinking of
something
this way:


Setting NI_DAQ;
When trigger occurs -> call routine() { code }


Is it possible?
The routine code should read serial port, but this is not a problem
because i've
a piece of code that can do that.

Thanks a lot!

Sebas Inc

unread,
Feb 22, 2012, 9:02:55 PM2/22/12
to Comedi: Linux Control and Measurement Device Interface
where are these functions (poll(),select(),etc)?...

Ian Abbott

unread,
Feb 23, 2012, 5:45:41 AM2/23/12
to comed...@googlegroups.com
On 2012/02/23 02:02 AM, Sebas Inc wrote:
> where are these functions (poll(),select(),etc)?...

They are POSIX functions in your system C library (libc). Use the 'man'
command for a description:

man 2 select
man 2 poll

Note: use the comedi_fileno() function to convert a valid 'comedi_t'
handle (as returned by comedi_open() on success) to a file descriptor
for with select(), poll(), read(), write(), etc.

Reply all
Reply to author
Forward
0 new messages