Index: demo/cmd.c
===================================================================
RCS file: /cvs/comedi/comedilib/demo/cmd.c,v
retrieving revision 1.20
diff -u -r1.20 cmd.c
--- demo/cmd.c	28 Dec 2005 17:11:35 -0000	1.20
+++ demo/cmd.c	19 Jul 2006 20:00:27 -0000
@@ -29,7 +29,9 @@
 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);
@@ -37,6 +39,8 @@
 
 void do_cmd(comedi_t *dev,comedi_cmd *cmd);
 
+void print_datum(lsampl_t raw, int i);
+
 char *cmdtest_messages[]={
 	"success",
 	"invalid source",
@@ -55,6 +59,7 @@
 	int i;
 	struct timeval start,end;
 	int subdev_flags;
+	lsampl_t raw;
 	
 	parse_options(argc,argv);
 
@@ -78,9 +83,14 @@
 		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
@@ -157,10 +167,12 @@
 			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");
@@ -313,4 +325,12 @@
 	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("%.6g\t",physical_value);
+	}
+}
Index: demo/common.c
===================================================================
RCS file: /cvs/comedi/comedilib/demo/common.c,v
retrieving revision 1.1
diff -u -r1.1 common.c
--- demo/common.c	14 Jul 2001 00:53:30 -0000	1.1
+++ demo/common.c	19 Jul 2006 20:00:27 -0000
@@ -17,7 +17,7 @@
 
 
 char *filename="/dev/comedi0";
-int verbose;
+int verbose = 0;
 
 int value=0;
 int subdevice=0;
@@ -27,6 +27,7 @@
 int n_chan=4;
 int n_scan=1000;
 double freq=1000.0;
+int physical = 0;
 
 
 int parse_options(int argc, char *argv[])
@@ -34,7 +35,7 @@
 	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;
@@ -60,6 +61,9 @@
 		case 'F':
 			freq = strtoul(optarg,NULL,0);
 			break;
+		case 'p':
+			physical = 1;
+			break;
 		case 'v':
 			verbose = 1;
 			break;
Index: demo/examples.h
===================================================================
RCS file: /cvs/comedi/comedilib/demo/examples.h,v
retrieving revision 1.3
diff -u -r1.3 examples.h
--- demo/examples.h	14 Jul 2001 00:50:52 -0000	1.3
+++ demo/examples.h	19 Jul 2006 20:00:27 -0000
@@ -17,6 +17,7 @@
 extern int channel;
 extern int aref;
 extern int range;
+extern int physical;
 extern int verbose;
 extern int n_chan;
 extern int n_scan;
Index: demo/inp.c
===================================================================
RCS file: /cvs/comedi/comedilib/demo/inp.c,v
retrieving revision 1.5
diff -u -r1.5 inp.c
--- demo/inp.c	1 Jan 2003 23:07:02 -0000	1.5
+++ demo/inp.c	19 Jul 2006 20:00:27 -0000
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <getopt.h>
 #include <ctype.h>
+#include <math.h>
 #include "examples.h"
 
 comedi_t *device;
@@ -29,6 +30,9 @@
 {
 	lsampl_t data;
 	int ret;
+	comedi_range * range_info;
+	lsampl_t maxdata;
+	double physical_value;
 
 	parse_options(argc,argv);
 
@@ -49,7 +53,35 @@
 		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;
 }
Index: README
===================================================================
RCS file: /cvs/comedi/comedilib/demo/README,v
retrieving revision 1.9
diff -u -r1.9 README
--- README	13 Mar 2005 17:04:47 -0000	1.9
+++ README	19 Jul 2006 20:25:36 -0000
@@ -127,4 +127,5 @@
   -g		set analog reference to ground
   -o		set analog reference to other
   -m		set analog reference to common
+  -p		display values in physical units
 

