blob: 7c10c3fea5ef461843c9ce4dc8218acfcaf3a9bc [file] [log] [blame]
cliechti88641262002-07-29 02:09:04 +00001#pyparallel driver for win32
2#see __init__.py
3#
4#(C) 2002 Chris Liechti <cliechti@gmx.net>
5# this is distributed under a free software license, see license.txt
6#
7# thanks to Dincer Aydin dinceraydin@altavista.net for his work on the
8# winioport module: www.geocities.com/dinceraydin/ the graphic below is
9# borrowed form him ;-)
10
11
12# LPT1 = 0x0378 or 0x03BC
13# LPT2 = 0x0278 or 0x0378
14# LPT3 = 0x0278
15#
16# Data Register (base + 0) ........ outputs
17#
18# 7 6 5 4 3 2 1 0
19# . . . . . . . * D0 ........... (pin 2), 1=High, 0=Low (true)
20# . . . . . . * . D1 ........... (pin 3), 1=High, 0=Low (true)
21# . . . . . * . . D2 ........... (pin 4), 1=High, 0=Low (true)
22# . . . . * . . . D3 ........... (pin 5), 1=High, 0=Low (true)
23# . . . * . . . . D4 ........... (pin 6), 1=High, 0=Low (true)
24# . . * . . . . . D5 ........... (pin 7), 1=High, 0=Low (true)
25# . * . . . . . . D6 ........... (pin 8), 1=High, 0=Low (true)
26# * . . . . . . . D7 ........... (pin 9), 1=High, 0=Low (true)
27#
28# Status Register (base + 1) ...... inputs
29#
30# 7 6 5 4 3 2 1 0
31# . . . . . * * * Undefined
32# . . . . * . . . Error ........ (pin 15), high=1, low=0 (true)
33# . . . * . . . . Selected ..... (pin 13), high=1, low=0 (true)
34# . . * . . . . . No paper ..... (pin 12), high=1, low=0 (true)
35# . * . . . . . . Ack .......... (pin 10), high=1, low=0 (true)
36# * . . . . . . . Busy ......... (pin 11), high=0, low=1 (inverted)
37#
38# ctrl Register (base + 2) ..... outputs
39#
40# 7 6 5 4 3 2 1 0
41# . . . . . . . * Strobe ....... (pin 1), 1=low, 0=high (inverted)
42# . . . . . . * . Auto Feed .... (pin 14), 1=low, 0=high (inverted)
43# . . . . . * . . Initialize ... (pin 16), 1=high, 0=low (true)
44# . . . . * . . . Select ....... (pin 17), 1=low, 0=high (inverted)
45# * * * * . . . . Unused
46
47LPT1 = 0
48LPT2 = 1
49
50LPT1_base = 0x0378
51LPT2_base = 0x0278
52
53import _pyparallel
54
55class Parallel:
56 def __init__(self, port = LPT1):
57 if port == LPT1:
58 self.dataRegAdr = LPT1_base
59 elif port == LPT1:
60 self.dataRegAdr = LPT2_base
61 else:
62 raise ValueError("No such port available - expecting a number")
63 self.statusRegAdr = self.dataRegAdr + 1
64 self.ctrlRegAdr = self.dataRegAdr + 2
65
66 def setData(self, value):
67 _pyparallel.outp(self.dataRegAdr, value)
68
69 # control register output functions
70 def setDataStrobe(self, state):
71 """data strobe bit"""
72 if state == 0:
73 self.ctrlReg = self.ctrlReg | 0x01
74 else:
75 self.ctrlReg = self.ctrlReg & ~0x01
76 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg)
77
78 def setAutoFeed(self, state):
79 """auto feed bit"""
80 if state == 0:
81 self.ctrlReg = self.ctrlReg | 0x02
82 else:
83 self.ctrlReg = self.ctrlReg & ~0x02
84 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg)
85
86 def setInitOut(self, state):
87 """initialize bit"""
88 if state == 0:
89 self.ctrlReg = self.ctrlReg & ~0x04
90 else:
91 self.ctrlReg = self.ctrlReg | 0x04
92 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg)
93
94 def setSelect(self, state):
95 """select bit"""
96 if state == 0:
97 self.ctrlReg = self.ctrlReg | 0x08
98 else:
99 self.ctrlReg = self.ctrlReg & ~0x08
100 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg)
101
102 def getInError(self):
103 """Error pin"""
104 return _pyparallel.inp(self.statusRegAdr) & 0x08 and 1
105
106 def gettInSelected(self):
107 """select pin"""
108 return _pyparallel.inp(self.statusRegAdr) & 0x10 and 1
109
110 def getInPaperOut(self):
111 """paper out pin"""
112 return _pyparallel.inp(self.statusRegAdr) & 0x20 and 1
113
114 def getInAcknowledge(self):
115 """Acknowledge pin"""
116 return _pyparallel.inp(self.statusRegAdr) & 0x40 and 1
117
118 def getInBusy(self):
119 """input from busy pin"""
120 return _pyparallel.inp(self.statusRegAdr)& 0x80 and 1
121
122