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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#include <ieee1284.h>
#include <stdlib.h>
#include <stdio.h>
#define SHOW(st,bits) printf(#bits" %s\n", ( st & bits) ?"on":"off")
void dump_cap(int cap)
{
SHOW(cap,CAP1284_RAW);
SHOW(cap,CAP1284_NIBBLE);
SHOW(cap,CAP1284_BYTE);
SHOW(cap,CAP1284_COMPAT);
SHOW(cap,CAP1284_BECP);
SHOW(cap,CAP1284_ECP);
SHOW(cap,CAP1284_ECPRLE);
SHOW(cap,CAP1284_ECPSWE);
SHOW(cap,CAP1284_EPP);
SHOW(cap,CAP1284_EPPSL);
SHOW(cap,CAP1284_EPPSWE);
SHOW(cap,CAP1284_IRQ);
SHOW(cap,CAP1284_DMA) ;
}
void pperror(int ret)
{
switch(ret)
{
case E1284_NOMEM:
puts("There is not enough memory");
break;
case E1284_INVALIDPORT:
puts("The port is invalid");
break;
case E1284_SYS:
perror("E1284_SYS");
break;
default:
printf("unknown error %d",ret);
}
}
int main()
{
int ret;
int fd;
int flags,cap,i;
unsigned char dat;
struct parport_list *plist=calloc(1,sizeof(*plist));
struct parport *pport;
ret = ieee1284_find_ports( plist, 0);
if ( ( ret != E1284_OK ) || (plist->portc < 1) ) /* cannot find parports */
return -1;
pport = plist->portv[0];
//flags=F1284_EXCL; //causes CLAIM to fail is mod lp is loaded
flags=0;
printf("going to open %s\n",pport->filename);
ret=ieee1284_open(pport,flags,&cap);
if (ret != E1284_OK )
goto no_open;
//
dump_cap(cap);
ret = ieee1284_claim ( pport );
if ( ret != E1284_OK )
{
printf("could not claim port\n");
pperror( ret );
goto no_claim;
}
/* set data direction */
ieee1284_data_dir( pport,0);
for(i=0;i<8;i++)
{
dat=1<<i;
ieee1284_write_data(pport,dat);
printf("write and wait %x\n",dat);
usleep(100000);
}
ieee1284_write_data(pport,0);
ieee1284_release(pport);
no_claim:
ieee1284_close(pport);
no_open:
ieee1284_free_ports(plist);
return 0;
}
|