Specifications
Comedi
13 / 148
/
*
start the command
*
/
ret = comedi_command(dev, cmd);
if(ret < 0){
comedi_perror("comedi_command");
exit(1);
}
subdev_flags = comedi_get_subdevice_flags(dev, options.subdevice);
while(1){
ret = read(comedi_fileno(dev),buf,BUFSZ);
if(ret < 0){
/
*
some error occurred
*
/
perror("read");
break;
}else if(ret == 0){
/
*
reached stop condition
*
/
break;
}else{
static int col = 0;
int bytes_per_sample;
total += ret;
if(options.verbose)fprintf(stderr, "read %d %d\n", ret, total);
if(subdev_flags & SDF_LSAMPL)
bytes_per_sample = sizeof(lsampl_t);
else
bytes_per_sample = sizeof(sampl_t);
for(i = 0; i < ret / bytes_per_sample; i++){
if(subdev_flags & SDF_LSAMPL) {
raw = ((lsampl_t
*
)buf)[i];
} else {
raw = ((sampl_t
*
)buf)[i];
}
print_datum(raw, col);
col++;
if(col == options.n_chan){
printf("\n");
col=0;
}
}
}
}
}
/
*
*
This prepares a command in a pretty generic way. We ask the
*
library to create a stock command that supports periodic
*
sampling of data, then modify the parts we want.
*
/
int prepare_cmd_lib(comedi_t
*
dev, int subdevice, int n_scan, int n_chan,
unsigned scan_period_nanosec, comedi_cmd
*
cmd)
{
int ret;
memset(cmd,0,sizeof(
*
cmd));
/
*
This comedilib function will get us a generic timed
*
command for a particular board. If it returns -1,
*
that’s bad.
*
/
ret = comedi_get_cmd_generic_timed(dev, subdevice, cmd, n_chan, scan_period_nanosec);
if(ret<0){
printf("comedi_get_cmd_generic_timed failed\n");
return ret;