]> rtime.felk.cvut.cz Git - mf6xx.git/blob - src/HuLinux-2.4.3/samples/EncoderIn/EncConfig.c
cdfbe95da00b5598810833929c0d20864d7d434f
[mf6xx.git] / src / HuLinux-2.4.3 / samples / EncoderIn / EncConfig.c
1 /* Humusoft data acquisition library.\r
2  *\r
3  * Example that shows configuration of\r
4  * encoder.\r
5  */\r
6 \r
7 /* Copyright 2002-2007 Humusoft s.r.o. */\r
8 \r
9 #include <stdio.h>\r
10 \r
11 #include "hudaqlib.h"\r
12 \r
13 \r
14 int main(int argc, char* argv[])\r
15 {\r
16         HUDAQHANDLE h;\r
17         int value;\r
18 \r
19         /* open a handle to the first MF624 device in the system */\r
20         h = HudaqOpenDevice("MF624", 1, 0);\r
21         if (h==0)\r
22         {\r
23                 printf("\nData acquisition device not found.\n");\r
24                 return(-1);\r
25         }\r
26 \r
27         /* Configure encoder to count input pulses. */  \r
28         if(HudaqSetParameter(h, 0, HudaqEncMODE, HudaqEncMODERISING) != HUDAQSUCCESS)\r
29         {\r
30                 printf("\nCannot switch encoder to counting mode.\n");\r
31                 HudaqCloseDevice(h);\r
32                 return(-2);\r
33         }\r
34 \r
35         /* Turn on hardware filter for input signal. */  \r
36         if(HudaqSetParameter(h, 0, HudaqEncFILTER, 1) != HUDAQSUCCESS)\r
37         {\r
38                 printf("\nCannot filter input signal.\n");\r
39         }      \r
40 \r
41         printf("Counting external pulses on input A by encoder, press Enter to continue.\n");\r
42         getchar();\r
43 \r
44         /* Read encoder 0 value, print it. */\r
45         value = HudaqEncRead(h,0);\r
46         printf("Encoder channel 0, value read %d.\n", 0, value);\r
47 \r
48         /* close the device handle */\r
49         HudaqCloseDevice(h);\r
50 \r
51         return(0);\r
52 }\r
53 \r