-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.c
54 lines (45 loc) · 1.17 KB
/
simple.c
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
/***
* simple.c
*
* About as easy a bogio app as you can get.
*
* Compile to a.out with:
* gcc simple.c `pkg-config --cflags --libs bogio`
***/
#include <stdio.h>
#include <bogio.h>
/* Number of frames to read before termination */
#define MAXFRAMES 120
int main(int argc, char *argv[])
{
bogio_spec bspec;
bogio_buf *bbuf;
int fr, ch;
bspec.comedi_device = "/dev/comedi0";
bspec.channels = 8;
bspec.sample_rate = 2;
bspec.oversampling = 0;
bspec.subdevice = 0;
bspec.range = 0; /* +/- 4.096V */
bspec.aref = AREF_GROUND;
/* Open the device to read data */
bogio_open(&bspec);
/* Allocate a buffer for 1 frame of data */
bbuf = bogio_allocate_buf(&bspec, 1U);
/* Carry on reading samples and printing them */
for (fr = 0; fr < MAXFRAMES; fr++) {
printf("%02i:", fr);
/* Read one frame of samples, blocking, into bbuf */
bogio_read_frames(&bspec, bbuf, 1U, 1);
for (ch = 0; ch < bbuf->spf; ch++)
/* Print only these channels... */
if (ch == 5)
printf(" %5.3f", bbuf->samples[ch]);
printf("\n");
}
/* Shut sown the comedi framework and free the buffer */
bogio_close(&bspec);
bogio_release_buf(bbuf);
/* That's all folks */
return 0;
}