File: info.c

package info (click to toggle)
comedilib 0.11.0%2B5-1.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,544 kB
  • sloc: xml: 19,779; ansic: 14,719; sh: 5,679; cpp: 2,211; ruby: 1,658; perl: 700; makefile: 596; yacc: 439; lex: 86; python: 17
file content (87 lines) | stat: -rw-r--r-- 1,919 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <math.h>
#include <sys/time.h>
#include <string.h>
#include "comedi_test.h"


static const char * const subdevice_types[]={
	"unused",
	"analog input",
	"analog output",
	"digital input",
	"digital output",
	"digital I/O",
	"counter",
	"timer",
	"memory",
	"calibration",
	"processor",
	"serial",
	"pwm"
};


int test_info(void)
{
	int j;
	int type;
	const char *type_str;
	int chan,n_chans;
	int n_ranges;
	comedi_range *rng;

	printf("rev 1\n");

	type = comedi_get_subdevice_type(device,subdevice);
	if(type < (int)(sizeof(subdevice_types) / sizeof(subdevice_types[0]))) {
		type_str = subdevice_types[type];
	}else{
		type_str = "UNKNOWN";
	}
	printf("I: subdevice type: %d (%s)\n",type,type_str);
	if(type==COMEDI_SUBD_UNUSED)
		return 0;
	n_chans=comedi_get_n_channels(device,subdevice);
	printf("  number of channels: %d\n",n_chans);
	if(!comedi_maxdata_is_chan_specific(device,subdevice)){
		printf("  max data value: %d\n",comedi_get_maxdata(device,subdevice,0));
	}else{
		printf("  max data value: (channel specific)\n");
		for(chan=0;chan<n_chans;chan++){
			printf("    chan%d: %d\n",chan,
				comedi_get_maxdata(device,subdevice,chan));
		}
	}
	printf("  ranges:\n");
	if(!comedi_range_is_chan_specific(device,subdevice)){
		n_ranges=comedi_get_n_ranges(device,subdevice,0);
		printf("    all chans:");
		for(j=0;j<n_ranges;j++){
			rng=comedi_get_range(device,subdevice,0,j);
			printf(" [%g,%g]",rng->min,rng->max);
		}
		printf("\n");
	}else{
		for(chan=0;chan<n_chans;chan++){
			n_ranges=comedi_get_n_ranges(device,subdevice,chan);
			printf("    chan%d:",chan);
			for(j=0;j<n_ranges;j++){
				rng=comedi_get_range(device,subdevice,chan,j);
				printf(" [%g,%g]",rng->min,rng->max);
			}
			printf("\n");
		}
	}

	return 0;
}