char buf[BUFSZ];
#define N_CHANS 256
-unsigned int chanlist[N_CHANS];
+static unsigned int chanlist[N_CHANS];
+static comedi_range * range_info[N_CHANS];
+static lsampl_t maxdata[N_CHANS];
int prepare_cmd_lib(comedi_t *dev,int subdevice,comedi_cmd *cmd);
void do_cmd(comedi_t *dev,comedi_cmd *cmd);
+void print_datum(lsampl_t raw, int i);
+
char *cmdtest_messages[]={
"success",
"invalid source",
int i;
struct timeval start,end;
int subdev_flags;
+ lsampl_t raw;
parse_options(argc,argv);
exit(1);
}
+ // Print numbers for clipped inputs
+ comedi_set_global_oor_behavior(COMEDI_OOR_NUMBER);
+
/* Set up channel list */
for(i=0;i<n_chan;i++){
chanlist[i]=CR_PACK(channel+i,range,aref);
+ range_info[i]=comedi_get_range(dev,subdevice,channel,range);
+ maxdata[i]=comedi_get_maxdata(dev,subdevice,channel);
}
/* prepare_cmd_lib() uses a Comedilib routine to find a
else
bytes_per_sample = sizeof(sampl_t);
for(i = 0; i < ret / bytes_per_sample; i++){
- if(subdev_flags & SDF_LSAMPL)
- printf("%d ",((lsampl_t *)buf)[i]);
- else
- printf("%d ",((sampl_t *)buf)[i]);
+ if(subdev_flags & SDF_LSAMPL) {
+ raw = ((lsampl_t *)buf)[i];
+ } else {
+ raw = ((sampl_t *)buf)[i];
+ }
+ print_datum(raw,col);
col++;
if(col==n_chan){
printf("\n");
return 0;
}
-
+void print_datum(lsampl_t raw, int i) {
+ double physical_value;
+ if(!physical) {
+ printf("%d ",raw);
+ } else {
+ physical_value = comedi_to_phys(raw,range_info[i],maxdata[i]);
+ printf("%#8.6g ",physical_value);
+ }
+}
char *filename="/dev/comedi0";
-int verbose;
+int verbose = 0;
int value=0;
int subdevice=0;
int n_chan=4;
int n_scan=1000;
double freq=1000.0;
+int physical = 0;
int parse_options(int argc, char *argv[])
int c;
- while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:n:N:F:vdgom"))) {
+ while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:n:N:F:pvdgom"))) {
switch (c) {
case 'f':
filename = optarg;
case 'F':
freq = strtoul(optarg,NULL,0);
break;
+ case 'p':
+ physical = 1;
+ break;
case 'v':
verbose = 1;
break;
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
+#include <math.h>
#include "examples.h"
comedi_t *device;
{
lsampl_t data;
int ret;
+ comedi_range * range_info;
+ lsampl_t maxdata;
+ double physical_value;
parse_options(argc,argv);
exit(0);
}
- printf("%d\n",data);
+ if(physical) {
+ comedi_set_global_oor_behavior(COMEDI_OOR_NAN);
+ range_info = comedi_get_range(device,subdevice,channel,range);
+ maxdata = comedi_get_maxdata(device,subdevice,channel);
+ if(verbose) {
+ printf("[0,%d] -> [%g,%g]\n", maxdata,
+ range_info->min, range_info->max);
+ }
+ physical_value = comedi_to_phys(data,range_info,maxdata);
+ if(isnan(physical_value)) {
+ printf("Out of range [%g,%g]",
+ range_info->min, range_info->max);
+ } else {
+ printf("%g",physical_value);
+ switch(range_info->unit) {
+ case UNIT_volt: printf(" V"); break;
+ case UNIT_mA: printf(" mA"); break;
+ case UNIT_none: break;
+ default: printf(" (unknown unit %d)",
+ range_info->unit);
+ }
+ if(verbose) {
+ printf(" (%d raw units)", data);
+ }
+ }
+ } else {
+ printf("%d",data);
+ }
+ printf("\n");
return 0;
}