-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
51 lines (46 loc) · 1006 Bytes
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/ppdev.h>
int main(int argc, char* argv[])
{
unsigned char data;
int pfd;
pfd = open("/dev/parportsnif0", O_RDWR);
if (pfd < 0) {
perror("Failed to open port");
exit(0);
}
if ((ioctl(pfd, PPEXCL) < 0) || (ioctl(pfd, PPCLAIM) < 0)) {
perror("Failed to lock port");
close(pfd);
exit(0);
}
// turn all bits off
data=0x00;
ioctl(pfd, PPWDATA, &data);
usleep(100000);
// turn some bits on and other off
data=0x55;
ioctl(pfd, PPWDATA, &data);
usleep(100000);
// turn some bits off and other on
data=0xAA;
ioctl(pfd, PPWDATA, &data);
usleep(100000);
// turn some bits on and other off
data=0x55;
ioctl(pfd, PPWDATA, &data);
usleep(100000);
// turn some bits off and other on
data=0xAA;
ioctl(pfd, PPWDATA, &data);
usleep(100000);
// turn all bits off
data=0x00;
ioctl(pfd, PPWDATA, &data);
usleep(100000);
close(pfd);
return 0;
}