From c17577318d3842f4f1f51abb9ee43a5a9234d4f1 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 20 Jul 2006 11:51:54 +0000 Subject: [PATCH] Applied patch from David MacMahon . Adds physical units support to comedilib demo programs. I changed one of the format strings to help line up values better in the 'cmd' example. --- demo/README | 1 + demo/cmd.c | 32 ++++++++++++++++++++++++++------ demo/common.c | 8 ++++++-- demo/examples.h | 1 + demo/inp.c | 34 +++++++++++++++++++++++++++++++++- 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/demo/README b/demo/README index 714f344..3a35519 100644 --- a/demo/README +++ b/demo/README @@ -127,4 +127,5 @@ The options are: -g set analog reference to ground -o set analog reference to other -m set analog reference to common + -p display values in physical units diff --git a/demo/cmd.c b/demo/cmd.c index 95f29a2..ee0ad8c 100644 --- a/demo/cmd.c +++ b/demo/cmd.c @@ -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 @@ int prepare_cmd(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", @@ -55,6 +59,7 @@ int main(int argc, char *argv[]) int i; struct timeval start,end; int subdev_flags; + lsampl_t raw; parse_options(argc,argv); @@ -78,9 +83,14 @@ int main(int argc, char *argv[]) exit(1); } + // Print numbers for clipped inputs + comedi_set_global_oor_behavior(COMEDI_OOR_NUMBER); + /* Set up channel list */ for(i=0;i #include #include +#include #include "examples.h" comedi_t *device; @@ -29,6 +30,9 @@ int main(int argc, char *argv[]) { lsampl_t data; int ret; + comedi_range * range_info; + lsampl_t maxdata; + double physical_value; parse_options(argc,argv); @@ -49,7 +53,35 @@ int main(int argc, char *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; } -- 2.26.2