|
Revision 1, 1.1 kB
(checked in by sven, 4 years ago)
|
|
Erstimport
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <stdlib.h> |
|---|
| 5 | #include <unistd.h> |
|---|
| 6 | #include <fcntl.h> |
|---|
| 7 | #include <errno.h> |
|---|
| 8 | |
|---|
| 9 | #include <sys/ioctl.h> |
|---|
| 10 | #include <linux/ppdev.h> |
|---|
| 11 | #include <linux/parport.h> |
|---|
| 12 | |
|---|
| 13 | #define DEBUG |
|---|
| 14 | #define PARPORT_DEVICE "/dev/parport0" |
|---|
| 15 | |
|---|
| 16 | int main(int argc, char **argv) { |
|---|
| 17 | int parport_fd; |
|---|
| 18 | int mode; |
|---|
| 19 | |
|---|
| 20 | parport_fd = open(PARPORT_DEVICE, O_RDWR); |
|---|
| 21 | if(parport_fd == -1) { |
|---|
| 22 | perror("open device failed"); |
|---|
| 23 | return 1; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | if(ioctl(parport_fd, PPCLAIM)) { |
|---|
| 27 | perror ("claiming port (PPCLAIM)"); |
|---|
| 28 | close (parport_fd); |
|---|
| 29 | return 1; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | mode = IEEE1284_MODE_COMPAT; |
|---|
| 33 | if(ioctl(parport_fd, PPNEGOT, &mode)) { |
|---|
| 34 | perror ("Setting compatibilty mode (PPNEGOT)"); |
|---|
| 35 | close (parport_fd); |
|---|
| 36 | return 1; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | { |
|---|
| 40 | static unsigned char mask = PARPORT_CONTROL_STROBE; |
|---|
| 41 | printf("Setting null mask to control pins (strobe,etc.)...\n"); |
|---|
| 42 | if(ioctl(parport_fd, PPWCONTROL, &mask)) { |
|---|
| 43 | perror("null mask"); |
|---|
| 44 | close(parport_fd); |
|---|
| 45 | return 1; |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | ioctl(parport_fd, PPRELEASE); |
|---|
| 50 | close(parport_fd); |
|---|
| 51 | return 0; |
|---|
| 52 | } |
|---|