blob: 21e8887222052b1f507b226a7fd18d0f0f83b609 [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)
cliechti619e4562002-07-31 00:53:06 +000043# . . . . . * . . Initialize ... (pin 16), 1=high,0=low (true)
cliechti88641262002-07-29 02:09:04 +000044# . . . . * . . . 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
cliechti619e4562002-07-31 00:53:06 +000059 elif port == LPT2:
cliechti88641262002-07-29 02:09:04 +000060 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
cliechti619e4562002-07-31 00:53:06 +000070 def setDataStrobe(self, level):
cliechti88641262002-07-29 02:09:04 +000071 """data strobe bit"""
cliechti619e4562002-07-31 00:53:06 +000072 if level:
cliechti88641262002-07-29 02:09:04 +000073 self.ctrlReg = self.ctrlReg & ~0x01
cliechti619e4562002-07-31 00:53:06 +000074 else:
75 self.ctrlReg = self.ctrlReg | 0x01
cliechti88641262002-07-29 02:09:04 +000076 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg)
77
cliechti619e4562002-07-31 00:53:06 +000078 def setAutoFeed(self, level):
cliechti88641262002-07-29 02:09:04 +000079 """auto feed bit"""
cliechti619e4562002-07-31 00:53:06 +000080 if level:
cliechti88641262002-07-29 02:09:04 +000081 self.ctrlReg = self.ctrlReg & ~0x02
cliechti619e4562002-07-31 00:53:06 +000082 else:
83 self.ctrlReg = self.ctrlReg | 0x02
cliechti88641262002-07-29 02:09:04 +000084 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg)
85
cliechti619e4562002-07-31 00:53:06 +000086 def setInitOut(self, level):
cliechti88641262002-07-29 02:09:04 +000087 """initialize bit"""
cliechti619e4562002-07-31 00:53:06 +000088 if level:
cliechti88641262002-07-29 02:09:04 +000089 self.ctrlReg = self.ctrlReg | 0x04
cliechti619e4562002-07-31 00:53:06 +000090 else:
91 self.ctrlReg = self.ctrlReg & ~0x04
cliechti88641262002-07-29 02:09:04 +000092 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg)
93
cliechti619e4562002-07-31 00:53:06 +000094 def setSelect(self, level):
cliechti88641262002-07-29 02:09:04 +000095 """select bit"""
cliechti619e4562002-07-31 00:53:06 +000096 if level:
cliechti88641262002-07-29 02:09:04 +000097 self.ctrlReg = self.ctrlReg & ~0x08
cliechti619e4562002-07-31 00:53:06 +000098 else:
99 self.ctrlReg = self.ctrlReg | 0x08
cliechti88641262002-07-29 02:09:04 +0000100 _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"""
cliechti619e4562002-07-31 00:53:06 +0000120 return not (_pyparallel.inp(self.statusRegAdr) & 0x80)
cliechti88641262002-07-29 02:09:04 +0000121
122