equal
deleted
inserted
replaced
18 #include <stdio.h> |
18 #include <stdio.h> |
19 #include <fcntl.h> |
19 #include <fcntl.h> |
20 #include <unistd.h> |
20 #include <unistd.h> |
21 #include <sys/ioctl.h> |
21 #include <sys/ioctl.h> |
22 #include <signal.h> |
22 #include <signal.h> |
23 |
23 #include <stdlib.h> |
24 #include "me8100.h" |
24 #include "me8100.h" |
25 |
25 |
26 #define USE_READ |
26 #define USE_READ |
27 |
27 |
28 int main(void){ |
28 const char* DEVICE = "/dev/me8100_0a"; |
29 int err = 0; |
|
30 static int file_handle = -1; |
|
31 |
29 |
|
30 int main(int argc, char** argv) { |
|
31 static int file_handle; |
32 unsigned short value_a; |
32 unsigned short value_a; |
33 |
33 |
34 printf("Read test, PID: %d\n", getpid()); |
34 if (argc > 1) DEVICE = argv[1]; |
|
35 |
|
36 printf("Read test, from %s, PID: %d\n", DEVICE, getpid()); |
35 #ifdef USE_READ |
37 #ifdef USE_READ |
36 printf("Using read()\n"); |
38 printf("Using read()\n"); |
37 #endif |
39 #endif |
38 /* file_handle = open("/dev/me8100_0a", O_RDONLY | O_NDELAY, 0); */ |
|
39 file_handle = open("/dev/me8100_0a", O_RDONLY, 0); |
|
40 |
40 |
41 if(file_handle < 0){ |
41 if (-1 == (file_handle = open(DEVICE, O_RDONLY, 0))) { |
42 printf("Cannot open path !\n"); |
42 fprintf(stderr, "Can't open %s: %m\n", DEVICE); |
43 return 1; |
43 exit(EXIT_FAILURE); |
44 } |
44 } |
45 |
45 |
46 for (;;sleep(1)) { |
46 for (;;sleep(1)) { |
47 #ifdef USE_READ |
47 #ifdef USE_READ |
48 int n; |
48 int n; |
59 ioctl(file_handle, ME8100_READ_DI_A, &value_a); |
59 ioctl(file_handle, ME8100_READ_DI_A, &value_a); |
60 #endif |
60 #endif |
61 printf("Read %04x\n", value_a); |
61 printf("Read %04x\n", value_a); |
62 } |
62 } |
63 |
63 |
64 err = close(file_handle); |
64 if(0 != close(file_handle)) { |
65 if(err){ |
65 perror("Can't close device"); |
66 printf("Kann Pfad nicht schliessen\n"); |
66 exit(EXIT_FAILURE); |
67 return 1; |
|
68 } |
67 } |
69 |
68 |
70 return 0; |
69 return 0; |
71 } |
70 } |
72 /* |
71 /* |