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_WRITE |
26 #define USE_WRITE |
27 |
27 |
28 int main(void){ |
28 const char* DEVICE = "/dev/me8100_0a"; |
|
29 |
|
30 int main(int argc, char** argv) { |
29 int err = 0; |
31 int err = 0; |
30 static int file_handle = -1; |
32 static int file_handle = -1; |
31 |
33 |
32 #ifndef USE_WRITE |
34 #ifndef USE_WRITE |
33 unsigned short ctrl_a; |
35 unsigned short ctrl_a; |
34 #endif |
36 #endif |
35 unsigned short value_a; |
37 unsigned short value_a; |
36 |
38 |
37 printf("Write test, PID: %d\n", getpid()); |
39 if (argc > 1) DEVICE = argv[1]; |
|
40 printf("Write test, to %s PID: %d\n", DEVICE, getpid()); |
38 #ifdef USE_WRITE |
41 #ifdef USE_WRITE |
39 printf("Using write()\n"); |
42 printf("Using write()\n"); |
40 #endif |
43 #endif |
41 file_handle = open("/dev/me8100_0a", O_WRONLY, 0); |
|
42 |
44 |
43 if(file_handle < 0){ |
45 |
44 printf("Cannot open path !\n"); |
46 if (-1 == (file_handle = open(DEVICE, O_WRONLY, 0))) { |
45 return 1; |
47 fprintf(stderr, "Can't open %s: %m\n", DEVICE); |
|
48 exit(EXIT_FAILURE); |
46 } |
49 } |
47 |
50 |
48 #ifndef USE_WRITE |
51 #ifndef USE_WRITE |
49 ctrl_a = ME8100_CTRL_ENIO | ME8100_CTRL_SOURCE | ME8100_CTRL_IRQ_MASK; |
52 ctrl_a = ME8100_CTRL_ENIO | ME8100_CTRL_SOURCE | ME8100_CTRL_IRQ_MASK; |
50 err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a); |
53 err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a); |
52 fprintf(stderr, "Can't setup output to port A\n"); |
55 fprintf(stderr, "Can't setup output to port A\n"); |
53 return 1; |
56 return 1; |
54 } |
57 } |
55 #endif |
58 #endif |
56 |
59 |
|
60 value_a = 0xffff; |
|
61 write(file_handle, &value_a, sizeof(value_a)); |
|
62 exit(EXIT_SUCCESS); |
|
63 |
57 for (value_a = 0x01; value_a < 0xffff; ++value_a) { |
64 for (value_a = 0x01; value_a < 0xffff; ++value_a) { |
58 #ifdef USE_WRITE |
65 #ifdef USE_WRITE |
59 write(file_handle, &value_a, sizeof(value_a)); |
66 write(file_handle, &value_a, sizeof(value_a)); |
60 #else |
67 #else |
61 ioctl(file_handle, ME8100_WRITE_DO_A, &value_a); |
68 ioctl(file_handle, ME8100_WRITE_DO_A, &value_a); |
62 #endif |
69 #endif |
63 printf("Wrote %04x\n", value_a); |
70 printf("Wrote %04x\n", value_a); |
64 sleep(3); |
71 sleep(1); |
65 } |
72 } |
66 |
73 |
67 err = close(file_handle); |
74 err = close(file_handle); |
68 if(err){ |
75 if(err){ |
69 printf("Kann Pfad nicht schliessen\n"); |
76 printf("Kann Pfad nicht schliessen\n"); |