--- a/me8100_test_dio/wtest.c Fri Jan 25 16:55:00 2002 +0100
+++ b/me8100_test_dio/wtest.c Fri Jan 25 20:26:01 2002 +0100
@@ -21,6 +21,7 @@
#include <sys/ioctl.h>
#include <signal.h>
#include <stdlib.h>
+#include <string.h>
#include "me8100.h"
#define USE_WRITE
@@ -28,19 +29,16 @@
const char* DEVICE = "/dev/me8100_0a";
int main(int argc, char** argv) {
- int err = 0;
- static int file_handle = -1;
-
-#ifndef USE_WRITE
- unsigned short ctrl_a;
-#endif
- unsigned short value_a;
+ char dev = 0;
+ static int file_handle;
+ unsigned short value;
if (argc > 1) DEVICE = argv[1];
+ dev = DEVICE[strlen(DEVICE) - 1];
+
printf("Write test, to %s PID: %d\n", DEVICE, getpid());
-#ifdef USE_WRITE
printf("Using write()\n");
-#endif
+
if (-1 == (file_handle = open(DEVICE, O_WRONLY, 0))) {
@@ -48,33 +46,19 @@
exit(EXIT_FAILURE);
}
-#ifndef USE_WRITE
- ctrl_a = ME8100_CTRL_ENIO | ME8100_CTRL_SOURCE | ME8100_CTRL_IRQ_MASK;
- err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a);
- if (err) {
- fprintf(stderr, "Can't setup output to port A\n");
- return 1;
- }
-#endif
+ for (value = 0x00;;++value) {
+ int val;
+ if (value > 0xff) value = 0;
- value_a = 0xffff;
- write(file_handle, &value_a, sizeof(value_a));
- exit(EXIT_SUCCESS);
-
- for (value_a = 0x01; value_a < 0xffff; ++value_a) {
-#ifdef USE_WRITE
- write(file_handle, &value_a, sizeof(value_a));
-#else
- ioctl(file_handle, ME8100_WRITE_DO_A, &value_a);
-#endif
- printf("Wrote %04x\n", value_a);
+ val = value + (dev << 8);;
+ write(file_handle, &val, sizeof(val));
+ printf("Wrote %04x\n", val);
sleep(1);
}
- err = close(file_handle);
- if(err){
- printf("Kann Pfad nicht schliessen\n");
- return 1;
+ if(-1 == close(file_handle)) {
+ perror("Can't close file");
+ exit(EXIT_FAILURE);
}
return 0;