Specifications

Comedi
14 / 148
}
/
*
Modify parts of the command
*
/
cmd->chanlist = chanlist;
cmd->chanlist_len = n_chan;
if(cmd->stop_src == TRIG_COUNT) cmd->stop_arg = n_scan;
return 0;
}
For advanced programmers the function comedi_get_buffer_contents() is useful to check if there is actually data in the
ringbuffer so that a call of read() can be avoided for example when the data readout is called by a timer call-back function.
3.5 Further examples
See the demo subdirectory of Comedilib for more example programs. The directory contains a README file with descriptions
of the various demo programs.
4 Acquisition and configuration functions
This Section gives an overview of all Comedi functions with which application programmers can implement their data acquisi-
tion. (With ‘acquisition’ we mean all possible kinds of interfacing with the cards: input, output, configuration, streaming, etc.)
Section 5 explains the function calls in full detail.
4.1 Functions for single acquisition
The simplest form of using Comedi is to get one single sample to or from an interface card. This sections explains how to do
such simple digital and analog acquisitions.
4.1.1 Single digital acquisition
Many boards supported by Comedi have digital input and output channels; i.e., channels that can only produce a 0 or a 1. Some
boards allow the direction (input or output) of each channel to be specified independently in software.
Comedi groups digital channels into a subdevice, which is a group of digital channels that have the same characteristics. For
example, digital output lines will be grouped into a digital output subdevice, bidirectional digital lines will be grouped into a
digital I/O subdevice. Thus, there can be multiple digital subdevices on a particular board.
Individual bits on a digital I/O device can be read and written using the functions comedi_dio_read() and comedi_dio-
_write():
int comedi_dio_read(comedi_t *device, unsigned int subdevice, unsigned int channel, unsigned int *bit);
int comedi_dio_write(comedi_t *device, unsigned int subdevice, unsigned int channel, unsigned int bit);
The device parameter is a pointer to a successfully opened Comedi device. The subdevice and channel parameters are
positive integers that indicate which subdevice and channel is used in the acquisition. The integer bit contains the value of the
acquired bit.
The direction of bidirectional lines can be configured using the function comedi_dio_config():
int comedi_dio_config(comedi_t *device, unsigned int subdevice, unsigned int channel, unsigned int dir);
The parameter dir should be either COMEDI_INPUT or COMEDI_OUTPUT. Many digital I/O subdevices group channels into
blocks for configuring direction. Changing one channel in a block changes the entire block.
Multiple channels can be read and written simultaneously using the function comedi_dio_bitfield2():