Specifications

Comedi
19 / 148
accompanied with various callback functionalities (DMA, interrupts, driver-specific callback functions),
for any number of channels,
with an arbitrary order of channels in each scan (possibly even with repeated channels per scan),
and with various scan triggering sources, external (i.e., hardware pulses) as well as internal (i.e., pulses generated on the DAQ
card itself, or generated by a software trigger instruction).
This command functionality exists in the Comedi API, because various data acquisition devices have the capability to perform
this kind of complex acquisition, driven by either on-board or off-board timers and triggers.
A command specifies a particular data acquisition sequence, which consists of a number of scans, and each scan is comprised of
a number of conversions, which usually corresponds to a single A/D or D/A conversion. So, for example, a scan could consist
of sampling channels 1, 2 and 3 of a particular device, and this scan should be repeated 1000 times, at intervals of 1 millisecond
apart.
The command function is complementary to the configuration instruction function: each channel in the command’s chanlist
should first be configured by an appropriate instruction.
4.5.1 Executing a command
A command is executed by the function comedi_command():
int comedi_command(comedi_t *device, comedi_cmd *command);
The following sections explain the meaning of the comedi_cmd data structure. Filling in this structure can be quite complicated,
and requires good knowledge about the exact functionalities of the DAQ card. So, before launching a command, the application
programmer is adviced to check whether this complex command data structure can be successfully parsed. So, the typical
sequence for executing a command is to first send the command through comedi_command_test() once or twice. The test
will check that the command is valid for the particular device, and often makes some adjustments to the command arguments,
which can then be read back by the user to see the actual values used.
A Comedi program can find out on-line what the command capabilities of a specific device are, by means of the comedi_ge-
t_cmd_src_mask() function.
4.5.2 The command data structure
The command executes according to the information about the requested acquisition, which is stored in the comedi_cmd data
structure:
typedef struct comedi_cmd_struct comedi_cmd;
struct comedi_cmd_struct {
unsigned int subdev; // which subdevice to sample
unsigned int flags; // encode some configuration possibilities
// of the command execution; e.g.,
// whether a callback routine is to be
// called at the end of the command
unsigned int start_src; // event to make the acquisition start
unsigned int start_arg; // parameters that influence this start
unsigned int scan_begin_src; // event to make a particular scan start
unsigned int scan_begin_arg; // parameters that influence this start‘
unsigned int convert_src; // event to make a particular conversion start
unsigned int convert_arg; // parameters that influence this start
unsigned int scan_end_src; // event to make a particular scan terminate
unsigned int scan_end_arg; // parameters that influence this termination