diff options
Diffstat (limited to 'content/demo-programme/ppraider.c')
| -rw-r--r-- | content/demo-programme/ppraider.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/content/demo-programme/ppraider.c b/content/demo-programme/ppraider.c new file mode 100644 index 0000000..20288c7 --- /dev/null +++ b/content/demo-programme/ppraider.c @@ -0,0 +1,108 @@ +/* + alle datenpins der reihe nach setzen via parport +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> +#include <sys/ioctl.h> + +#include <linux/parport.h> +#include <linux/ppdev.h> + + +#define DEVICE "/dev/parport0" + +static char *RCSID __attribute__ ((unused)) = + "$Id: ppraider.c,v 1.1 2006/03/19 15:33:54 walter Exp walter $"; + + +#define SHOW(st,bits) printf(#bits" %s\n", ( st & bits) ?"on":"off") + + +int xopenport(char *name, int fdmode) +{ + static int fd; + int mode; + + + mode = O_WRONLY | O_NOCTTY; + fd = open(name, mode); + + if (fd == -1) { + perror("open"); + exit(EXIT_FAILURE); + } + + + + if (ioctl(fd, PPCLAIM)) { + perror("PPCLAIM"); + close(fd); + exit(EXIT_FAILURE); + } + mode = IEEE1284_MODE_COMPAT; + + if (ioctl(fd, PPNEGOT, &mode)) { + perror("PPNEGOT"); + close(fd); + exit(EXIT_FAILURE); + } + return fd; +} + + /* release port close(fd), ignore errors */ +void xcloseport(int fd) +{ + ioctl(fd, PPRELEASE); + close(fd); +} + + +void xset_data(int fd, int data) +{ + int ret; + ret = ioctl(fd, PPWDATA, &data); + if (!ret) + return; + fprintf(stderr, "%s failed:%s\n", __func__, strerror(errno)); + exit(EXIT_FAILURE); +} + + + /* get status info */ + /* clean up later */ +void xget_status(int fd, unsigned char *foo) +{ + int ret; + unsigned char status; + ret = ioctl(fd, PPRSTATUS, &status); + if (!ret) { + *foo = status; + return; + + } + fprintf(stderr, "%s failed:%s\n", __func__, strerror(errno)); + exit(EXIT_FAILURE); +} + + +int main() +{ + int i,fd; + fd = xopenport(DEVICE, 0); + + + for (i = 0; i < 8; i++) { + xset_data(fd, 1 << i); + usleep(500000); + } + + xset_data(fd, 0); + xcloseport(fd); + + return 0; +} |
