Specifications
Comedi
12 / 148
It requests data from two channels at a sampling rate of 1kHz and a total of 10000 samples. which are then printed to stdout. You
can pipe the data into a file and plot it with gnuplot. As mentioned above, central in this program is the loop using the standard
C read() command which receives the buffer contents. Below is an extract from tut3.c showing the relevant commands:
/
*
open the device
*
/
dev = comedi_open(options.filename);
if(!dev){
comedi_perror(options.filename);
exit(1);
}
// Print numbers for clipped inputs
comedi_set_global_oor_behavior(COMEDI_OOR_NUMBER);
/
*
Set up channel list
*
/
for(i = 0; i < options.n_chan; i++){
chanlist[i] = CR_PACK(options.channel + i,
options.range,
options.aref);
range_info[i] = comedi_get_range(dev,
options.subdevice,
options.channel, options.range);
maxdata[i] = comedi_get_maxdata(dev,
options.subdevice,
options.channel);
}
/
*
prepare_cmd_lib() uses a Comedilib routine to find a
*
good command for the device. prepare_cmd() explicitly
*
creates a command, which may not work for your device.
*
/
prepare_cmd_lib(dev,
options.subdevice,
options.n_scan,
options.n_chan,
1e9 / options.freq, cmd);
/
*
comedi_command_test() tests a command to see if the
*
trigger sources and arguments are valid for the subdevice.
*
If a trigger source is invalid, it will be logically ANDed
*
with valid values (trigger sources are actually bitmasks),
*
which may or may not result in a valid trigger source.
*
If an argument is invalid, it will be adjusted to the
*
nearest valid value. In this way, for many commands, you
*
can test it multiple times until it passes. Typically,
*
if you can’t get a valid command in two tests, the original
*
command wasn’t specified very well.
*
/
ret = comedi_command_test(dev, cmd);
if(ret < 0){
comedi_perror("comedi_command_test");
exit(1);
}
ret = comedi_command_test(dev, cmd);
if(ret < 0){
comedi_perror("comedi_command_test");
exit(1);
}
fprintf(stderr,"second test returned %d (%s)\n", ret,
cmdtest_messages[ret]);
if(ret!=0){
fprintf(stderr, "Error preparing command\n");
exit(1);
}