| 1 | /* |
| 2 | * Tutorial example #2 |
| 3 | * Part of Comedilib |
| 4 | * |
| 5 | * Copyright (c) 1999,2000 David A. Schleef <[email protected]> |
| 6 | * Copyright (c) 2008 Frank Mori Hess <[email protected]> |
| 7 | * |
| 8 | * This file may be freely modified, distributed, and combined with |
| 9 | * other software, as long as proper attribution is given in the |
| 10 | * source code. |
| 11 | */ |
| 12 | |
| 13 | #include <stdio.h> /* for printf() */ |
| 14 | #include <stdlib.h> |
| 15 | #include <comedilib.h>cxx . . $ `<file>/include/comedilib.h`/ |
| 16 | #include <ctype.h> |
| 17 | #include <math.h> |
| 18 | |
| 19 | int subdevcxx . . $ subdev. = 0; /* change this to your input subdevice */ |
| 20 | int chancxx . . $ chan. = 0; /* change this to your channel */ |
| 21 | int rangecxx . . $ range. = 0; /* more on this later */ |
| 22 | int arefcxx . . $ aref. = AREF_GROUNDcxx . . $ `include/comedi.h:96:9`!; /* more on this later */ |
| 23 | const char filenamecxx . . $ filename.[] = "/dev/comedi0"; |
| 24 | |
| 25 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) |
| 26 | { |
| 27 | comedi_tcxx . . $ comedi_t# *device; |
| 28 | lsampl_tcxx . . $ lsampl_t# data; |
| 29 | double physical_value; |
| 30 | int retval; |
| 31 | comedi_rangecxx . . $ comedi_range# *range_info; |
| 32 | lsampl_tcxx . . $ lsampl_t# maxdata; |
| 33 | |
| 34 | device = comedi_opencxx . . $ comedi_open(d67864c6c007fe39).(filenamecxx . . $ filename.); |
| 35 | if (device == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 36 | comedi_perrorcxx . . $ comedi_perror(85c52e162fed56f9).(filenamecxx . . $ filename.); |
| 37 | return 1; |
| 38 | } |
| 39 | |
| 40 | retval = comedi_data_readcxx . . $ comedi_data_read(ed662314c4dc98c9).(device, subdevcxx . . $ subdev., chancxx . . $ chan., rangecxx . . $ range., arefcxx . . $ aref., |
| 41 | &data); |
| 42 | if (retval < 0) { |
| 43 | comedi_perrorcxx . . $ comedi_perror(85c52e162fed56f9).(filenamecxx . . $ filename.); |
| 44 | return 1; |
| 45 | } |
| 46 | |
| 47 | comedi_set_global_oor_behaviorcxx . . $ comedi_set_global_oor_behavior(711436fe91983c69).(COMEDI_OOR_NANcxx . . $ COMEDI_OOR_NAN.); |
| 48 | range_info = comedi_get_rangecxx . . $ comedi_get_range(60f094977346e00a).(device, subdevcxx . . $ subdev., chancxx . . $ chan., rangecxx . . $ range.); |
| 49 | maxdata = comedi_get_maxdatacxx . . $ comedi_get_maxdata(9f5413f81e406f65).(device, subdevcxx . . $ subdev., chancxx . . $ chan.); |
| 50 | printfcxx . . $ printf(581fddd72a8db8fc).("[0,%d] -> [%g,%g]\n", maxdata, |
| 51 | range_info->mincxx . . $ $anonymous_type_e3831e245d0fb292_0#min., range_info->maxcxx . . $ $anonymous_type_e3831e245d0fb292_0#max.); |
| 52 | physical_value = comedi_to_physcxx . . $ comedi_to_phys(28294eee26a5294e).(data, range_info, maxdata); |
| 53 | if (isnancxx . . $ `<external>/11263917310783833665/math.h:980:11`!(physical_value)) { |
| 54 | printfcxx . . $ printf(581fddd72a8db8fc).("Out of range [%g,%g]", |
| 55 | range_info->mincxx . . $ $anonymous_type_e3831e245d0fb292_0#min., range_info->maxcxx . . $ $anonymous_type_e3831e245d0fb292_0#max.); |
| 56 | } else { |
| 57 | printfcxx . . $ printf(581fddd72a8db8fc).("%g", physical_value); |
| 58 | switch(range_info->unitcxx . . $ $anonymous_type_e3831e245d0fb292_0#unit.) { |
| 59 | case UNIT_voltcxx . . $ `include/comedi.h:930:9`!: printfcxx . . $ printf(581fddd72a8db8fc).(" V"); break; |
| 60 | case UNIT_mAcxx . . $ `include/comedi.h:931:9`!: printfcxx . . $ printf(581fddd72a8db8fc).(" mA"); break; |
| 61 | case UNIT_nonecxx . . $ `include/comedi.h:932:9`!: break; |
| 62 | default: printfcxx . . $ printf(581fddd72a8db8fc).(" (unknown unit %d)", |
| 63 | range_info->unitcxx . . $ $anonymous_type_e3831e245d0fb292_0#unit.); |
| 64 | } |
| 65 | printfcxx . . $ printf(581fddd72a8db8fc).(" (%lu in raw units)\n", (unsigned long)data); |
| 66 | } |
| 67 | return 0; |
| 68 | } |