blob: 18cc54c2ca884caba2083fed188d1d927c25bed7 [file] [log] [blame]
cliechti619e4562002-07-31 00:53:06 +00001#!/usr/bin/env python
cliechti7d2b78a2002-08-07 22:39:54 +00002# parallel port access using the ppdev driver
cliechti619e4562002-07-31 00:53:06 +00003
alexperry9c6d6f12004-10-04 18:13:39 +00004import sys
cliechti619e4562002-07-31 00:53:06 +00005import struct
6import fcntl
7import os
8
9#----
10# Generated by h2py 0.1.1 from <linux/ppdev.h>,
11# then cleaned up a bit by Michael P. Ashton and then a gain by chris ;-)
alexperry9c6d6f12004-10-04 18:13:39 +000012# Changes for Python2.2 support (c) September 2004 Alex.Perry@qm.com
13
cliechti619e4562002-07-31 00:53:06 +000014
15def sizeof(type): return struct.calcsize(type)
cliechti9cc93532005-01-15 21:16:33 +000016def _IOC(dir, type, nr, size): return int((dir << _IOC_DIRSHIFT ) | (type << _IOC_TYPESHIFT ) |\
17 (nr << _IOC_NRSHIFT ) | (size << _IOC_SIZESHIFT))
cliechti7d2b78a2002-08-07 22:39:54 +000018def _IO(type, nr): return _IOC(_IOC_NONE, type, nr, 0)
19def _IOR(type,nr,size): return _IOC(_IOC_READ, type, nr, sizeof(size))
20def _IOW(type,nr,size): return _IOC(_IOC_WRITE, type, nr, sizeof(size))
cliechti619e4562002-07-31 00:53:06 +000021
22_IOC_SIZEBITS = 14
alexperry54990222004-04-16 19:17:04 +000023_IOC_SIZEMASK = (1L << _IOC_SIZEBITS ) - 1
cliechti619e4562002-07-31 00:53:06 +000024_IOC_NRSHIFT = 0
25_IOC_NRBITS = 8
26_IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS
27_IOC_TYPEBITS = 8
28_IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS
29IOCSIZE_MASK = _IOC_SIZEMASK << _IOC_SIZESHIFT
30IOCSIZE_SHIFT = _IOC_SIZESHIFT
alexperry9c6d6f12004-10-04 18:13:39 +000031
32# Python 2.2 uses a signed int for the ioctl() call, so ...
33if ( sys.version_info[0] < 3 ) or ( sys.version_info[1] < 3 ):
34 _IOC_WRITE = 1L
35 _IOC_READ = -2L
36 _IOC_INOUT = -1L
37else:
38 _IOC_WRITE = 1L
39 _IOC_READ = 2L
40 _IOC_INOUT = 3L
41
cliechti619e4562002-07-31 00:53:06 +000042_IOC_DIRSHIFT = _IOC_SIZESHIFT + _IOC_SIZEBITS
alexperry9c6d6f12004-10-04 18:13:39 +000043IOC_INOUT = _IOC_INOUT << _IOC_DIRSHIFT
cliechti619e4562002-07-31 00:53:06 +000044IOC_IN = _IOC_WRITE << _IOC_DIRSHIFT
cliechti619e4562002-07-31 00:53:06 +000045IOC_OUT = _IOC_READ << _IOC_DIRSHIFT
46
47_IOC_NONE = 0
48PP_IOCTL = ord('p')
cliechti7d2b78a2002-08-07 22:39:54 +000049PPCLAIM = _IO(PP_IOCTL, 0x8b)
cliechti619e4562002-07-31 00:53:06 +000050PPCLRIRQ = _IOR(PP_IOCTL, 0x93, 'i')
51
52PPDATADIR = _IOW(PP_IOCTL, 0x90, 'i')
cliechti7d2b78a2002-08-07 22:39:54 +000053PPEXCL = _IO(PP_IOCTL, 0x8f)
cliechti619e4562002-07-31 00:53:06 +000054PPFCONTROL = _IOW(PP_IOCTL, 0x8e, 'BB')
55PPGETFLAGS = _IOR(PP_IOCTL, 0x9a, 'i')
56PPGETMODE = _IOR(PP_IOCTL, 0x98, 'i')
57PPGETMODES = _IOR(PP_IOCTL, 0x97, 'I')
58PPGETPHASE = _IOR(PP_IOCTL, 0x99, 'i')
59PPGETTIME = _IOR(PP_IOCTL, 0x95, 'll')
60PPNEGOT = _IOW(PP_IOCTL, 0x91, 'i')
61PPRCONTROL = _IOR(PP_IOCTL, 0x83, 'B')
62PPRDATA = _IOR(PP_IOCTL, 0x85, 'B')
63#'OBSOLETE__IOR' undefined in 'PPRECONTROL'
cliechti7d2b78a2002-08-07 22:39:54 +000064PPRELEASE = _IO(PP_IOCTL, 0x8c)
cliechti619e4562002-07-31 00:53:06 +000065#'OBSOLETE__IOR' undefined in 'PPRFIFO'
66PPRSTATUS = _IOR(PP_IOCTL, 0x81, 'B')
67PPSETFLAGS = _IOW(PP_IOCTL, 0x9b, 'i')
68PPSETMODE = _IOW(PP_IOCTL, 0x80, 'i')
69PPSETPHASE = _IOW(PP_IOCTL, 0x94, 'i')
70PPSETTIME = _IOW(PP_IOCTL, 0x96, 'll')
71PPWCONTROL = _IOW(PP_IOCTL, 0x84, 'B')
72PPWCTLONIRQ = _IOW(PP_IOCTL, 0x92, 'B')
73PPWDATA = _IOW(PP_IOCTL, 0x86, 'B')
74#'OBSOLETE__IOW' undefined in 'PPWECONTROL'
75#'OBSOLETE__IOW' undefined in 'PPWFIFO'
76#'OBSOLETE__IOW' undefined in 'PPWSTATUS'
77PPYIELD = _IO(PP_IOCTL, 0x8d)
78PP_FASTREAD = 1 << 3
79PP_FASTWRITE = 1 << 2
80PP_W91284PIC = 1 << 4
81PP_FLAGMASK = PP_FASTWRITE | PP_FASTREAD | PP_W91284PIC
82PP_MAJOR = 99
83_ASMI386_IOCTL_H= None
84_IOC_DIRBITS = 2
85_IOC_DIRMASK = (1 << _IOC_DIRBITS) - 1
86_IOC_NRMASK = (1 << _IOC_NRBITS) - 1
87_IOC_TYPEMASK = (1 << _IOC_TYPEBITS ) - 1
88
89def _IOC_DIR(nr): return (nr >> _IOC_DIRSHIFT) & _IOC_DIRMASK
90def _IOC_NR(nr): return (nr >> _IOC_NRSHIFT) & _IOC_NRMASK
91def _IOC_SIZE(nr): return (nr >> _IOC_SIZESHIFT) & _IOC_SIZEMASK
92def _IOC_TYPE(nr): return (nr >> _IOC_TYPESHIFT) & _IOC_TYPEMASK
93def _IOWR(type, nr, size): return _IOC(_IOC_READ | _IOC_WRITE, type, nr , sizeof(size))
94
95__ELF__ = 1
96__i386 = 1
97__i386__ = 1
98__linux = 1
99__linux__ = 1
100__unix = 1
101__unix__ = 1
102i386 = 1
103linux = 1
104unix = 1
105
106#-------- Constants from <linux/parport.h>
107
108PARPORT_CONTROL_STROBE = 0x1
109PARPORT_CONTROL_AUTOFD = 0x2
110PARPORT_CONTROL_INIT = 0x4
111PARPORT_CONTROL_SELECT = 0x8
112PARPORT_STATUS_ERROR = 8
113PARPORT_STATUS_SELECT = 0x10
114PARPORT_STATUS_PAPEROUT = 0x20
115PARPORT_STATUS_ACK = 0x40
116PARPORT_STATUS_BUSY = 0x80
117
118IEEE1284_MODE_NIBBLE = 0
119IEEE1284_MODE_BYTE = 1
120IEEE1284_MODE_COMPAT = 1<<8
121IEEE1284_MODE_BECP = 1<<9
122IEEE1284_MODE_ECP = 1<<4
123IEEE1284_MODE_ECPRLE = IEEE1284_MODE_ECP | (1<<5)
124IEEE1284_MODE_ECPSWE = 1<<10
125IEEE1284_MODE_EPP = 1<<6
126IEEE1284_MODE_EPPSL = 1<<11
127IEEE1284_MODE_EPPSWE = 1<<12
128IEEE1284_DEVICEID = 1<<2
129IEEE1284_EXT_LINK = 1<<14
130
131IEEE1284_ADDR = 1<<13
132IEEE1284_DATA = 0
133
134PARPORT_EPP_FAST = 1
135PARPORT_W91284PIC = 2
136#----
137
138class Parallel:
139 """Class for controlling the pins on a parallel port
140
141 This class provides bit-level access to the pins on a PC parallel
142 port. It is primarily designed for programs which must control
143 special circuitry - most often non-IEEE-1284-compliant devices
144 other than printers - using 'bit-banging' techniques.
145
146 The current implementation makes ioctl() calls to the Linux ppdev
147 driver, using the Python fcntl library. It might be rewritten in
148 C for extra speed. This particular implementation is written for
149 Linux; all of the upper-level calls can be ported to Windows as
150 well.
151
152 On Linux, the ppdev device driver, from the Linux 2.4 parallel
153 port subsystem, is used to control the parallel port hardware.
154 This driver must be made available from a kernel compile. The
155 option is called "Support user-space parallel-port drivers". When
156 using the module, be sure to unload the lp module first: usually
157 the lp module claims exclusive access to the parallel port, and if
158 it is loaded, this class will fail to open the parallel port file,
159 and throw an exception.
160
161 The primary source of information about the Linux 2.4 parallel
162 port subsystem is Tim Waugh's documentation, the source for which
163 is available in the kernel tree. This document (called,
164 appropriately enough, "The Linux 2.4 Parallel Port Subsystem"),
165 thoroughly describes the parallel port drivers and how to use
166 them.
167
168 This class provides a method for each of the ioctls supported by
169 the ppdev module. The ioctl methods are named, in uppercase, the
170 same as the ioctls they invoke. The documentation for these
171 methods was taken directly from the documentation for their
172 corresponding ioctl, and modified only where necessary.
173
174 Unless you have special reason to use the Linux ioctls, you should
175 use instead the upper-level functions, which are named in
176 lowerCase fashion and should be portable between Linux and
177 Windows. This way, any code you write for this class will (or
178 should) also work with the Windows version of this class.
179
180 """
181 def __init__(self, port = 0):
182 if type(port) == type(""):
183 self.device = port
184 else:
cliechti7d2b78a2002-08-07 22:39:54 +0000185 self.device = "/dev/parport%d" % port
cliechti619e4562002-07-31 00:53:06 +0000186 self._fd = os.open(self.device, os.O_RDWR)
187 self.PPEXCL()
188 self.PPCLAIM()
189 self.setDataDir(1)
190 self.setData(0)
191
192 def __del__(self):
193 self.PPRELEASE()
cliechti7d2b78a2002-08-07 22:39:54 +0000194 if self._fd is not None:
195 os.close(self._fd)
cliechti619e4562002-07-31 00:53:06 +0000196
197 def timevalToFloat(self, timeval):
198 t=struct.unpack('ll', timeval)
199 return t[0] + (t[1]/1000000.0)
200
201 def floatToTimeval(self, time):
202 sec = int(time)
203 usec = int(time*1000000.0)
204 return struct.pack('ll', sec, usec)
205
206 def PPCLAIM(self):
207 """
208 Claims access to the port. As a user-land device driver
209 writer, you will need to do this before you are able to
210 actually change the state of the parallel port in any
211 way. Note that some operations only affect the ppdev driver
212 and not the port, such as PPSETMODE; they can be performed
213 while access to the port is not claimed.
214 """
cliechti7d2b78a2002-08-07 22:39:54 +0000215 fcntl.ioctl(self._fd, PPCLAIM)
cliechti619e4562002-07-31 00:53:06 +0000216
217 def PPEXCL(self):
218 """
219 Instructs the kernel driver to forbid any sharing of the port
220 with other drivers, i.e. it requests exclusivity. The PPEXCL
221 command is only valid when the port is not already claimed for
222 use, and it may mean that the next PPCLAIM ioctl will fail:
223 some other driver may already have registered itself on that
224 port.
225
226 Most device drivers don't need exclusive access to the
227 port. It's only provided in case it is really needed, for
228 example for devices where access to the port is required for
229 extensive periods of time (many seconds).
230
231 Note that the PPEXCL ioctl doesn't actually claim the port
232 there and then---action is deferred until the PPCLAIM ioctl is
233 performed.
234 """
cliechti7d2b78a2002-08-07 22:39:54 +0000235 fcntl.ioctl(self._fd, PPEXCL)
cliechti619e4562002-07-31 00:53:06 +0000236
237 def PPRELEASE(self):
238 """
239 Releases the port. Releasing the port undoes the effect of
240 claiming the port. It allows other device drivers to talk to
241 their devices (assuming that there are any).
242 """
243 fcntl.ioctl(self._fd, PPRELEASE)
244
245 def PPYIELD(self):
246 """
247 Yields the port to another driver. This ioctl is a kind of
248 short-hand for releasing the port and immediately reclaiming
249 it. It gives other drivers a chance to talk to their devices,
250 but afterwards claims the port back. An example of using this
251 would be in a user-land printer driver: once a few characters
252 have been written we could give the port to another device
253 driver for a while, but if we still have characters to send to
254 the printer we would want the port back as soon as possible.
255
256 It is important not to claim the parallel port for too long,
257 as other device drivers will have no time to service their
258 devices. If your device does not allow for parallel port
259 sharing at all, it is better to claim the parallel port
260 exclusively (see PPEXCL).
261 """
262 fcntl.ioctl(self._fd, PPYIELD)
263
264 def PPNEGOT(self, mode):
265 """
266 Performs IEEE 1284 negotiation into a particular
267 mode. Briefly, negotiation is the method by which the host and
268 the peripheral decide on a protocol to use when transferring
269 data.
270
271 An IEEE 1284 compliant device will start out in compatibility
272 mode, and then the host can negotiate to another mode (such as
273 ECP).
274
275 The 'mode' parameter should be one of the following constants
276 from PPDEV:
277
278 - IEEE1284_MODE_COMPAT
279 - IEEE1284_MODE_NIBBLE
280 - IEEE1284_MODE_BYTE
281 - IEEE1284_MODE_EPP
282 - IEEE1284_MODE_ECP
283
284 The PPNEGOT ioctl actually does two things: it performs the
285 on-the-wire negotiation, and it sets the behaviour of
286 subsequent read/write calls so that they use that mode (but
287 see PPSETMODE).
288 """
289 fcntl.ioctl(self._fd, PPNEGOT, struct.pack('i', mode))
290
291 def PPSETMODE(self, mode):
292 """
293 Sets which IEEE 1284 protocol to use for the read and write
294 calls.
295
296 The 'mode' parameter should be one of the following constants
297 from PPDEV:
298
299 - IEEE1284_MODE_COMPAT
300 - IEEE1284_MODE_NIBBLE
301 - IEEE1284_MODE_BYTE
302 - IEEE1284_MODE_EPP
303 - IEEE1284_MODE_ECP
304 """
305 fcntl.ioctl(self._fd, PPSETMODE, struct.pack('i', mode))
306
307 def PPGETMODE(self):
308 """
309 Retrieves the IEEE 1284 mode being used for read and
310 write. The return value is one of the following constants
311 from PPDEV:
312
313 - IEEE1284_MODE_COMPAT
314 - IEEE1284_MODE_NIBBLE
315 - IEEE1284_MODE_BYTE
316 - IEEE1284_MODE_EPP
317 - IEEE1284_MODE_ECP
318 """
319 ret = struct.pack('i', 0)
320 ret = fcntl.ioctl(self._fd, PPGETMODE, ret)
321 return struct.unpack('i', ret)[0]
322
323 def PPGETTIME(self):
324 """
325 Retrieves the time-out value. The read and write calls will
326 time out if the peripheral doesn't respond quickly enough. The
327 PPGETTIME ioctl retrieves the length of time that the
328 peripheral is allowed to have before giving up.
329
330 Returns the timeout value in seconds as a floating-point value.
331 """
332 ret = struct.pack('ll', 0, 0)
333 ret = fcntl.ioctl(self._fd, PPGETTIME, ret)
334 return timevalToFloat(ret)
335
336 def PPSETTIME(self, time):
337 """
338 Sets the time-out (see PPGETTIME for more information).
339 'time' is the new time-out in seconds; floating-point values
340 are acceptable.
341 """
342 fcntl.ioctl(self._fd, PPSETTIME, floatToTimeval(time))
343
344 def PPGETMODES(self):
345 """
346 Retrieves the capabilities of the hardware (i.e. the modes
347 field of the parport structure).
348 """
349 raise NotImplementedError
350
351 def PPSETFLAGS(self):
352 """
353 Sets flags on the ppdev device which can affect future I/O
354 operations. Available flags are:
355
356 - PP_FASTWRITE
357 - PP_FASTREAD
358 - PP_W91284PIC
359 """
360 raise NotImplementedError
361
362 def PPWCONTROL(self, lines):
363 """
364 Sets the control lines. The 'lines' parameter is a bitwise OR
365 of the following constants from PPDEV:
366
367 - PARPORT_CONTROL_STROBE
368 - PARPORT_CONTROL_AUTOFD
369 - PARPORT_CONTROL_INIT
370 - PARPORT_CONTROL_SELECT
371 """
372 fcntl.ioctl(self._fd, PPWCONTROL, struct.pack('B', lines))
373
374 def PPRCONTROL(self):
375 """
376 Returns the last value written to the control register, in the
377 form of an integer, for which each bit corresponds to a control
378 line (although some are unused).
379
380 This doesn't actually touch the hardware; the last value
381 written is remembered in software. This is because some
382 parallel port hardware does not offer read access to the
383 control register.
384
385 The control lines bits are defined by the following constants
386 from PPDEV:
387
388 - PARPORT_CONTROL_STROBE
389 - PARPORT_CONTROL_AUTOFD
390 - PARPORT_CONTROL_SELECT
391 - PARPORT_CONTROL_INIT
392 """
393 ret = struct.pack('B',0)
394 ret = fcntl.ioctl(self._fd, PPRCONTROL, ret)
395 return struct.unpack('B', ret)[0]
396
397 def PPFCONTROL(self, mask, val):
398 """
399 Frobs the control lines. Since a common operation is to change
400 one of the control signals while leaving the others alone, it
401 would be quite inefficient for the user-land driver to have to
402 use PPRCONTROL, make the change, and then use PPWCONTROL. Of
403 course, each driver could remember what state the control
404 lines are supposed to be in (they are never changed by
405 anything else), but in order to provide PPRCONTROL, ppdev must
406 remember the state of the control lines anyway.
407
408 The PPFCONTROL ioctl is for "frobbing" control lines, and is
409 like PPWCONTROL but acts on a restricted set of control
410 lines. The ioctl parameter is a pointer to a struct
411 ppdev_frob_struct:
412
413 struct ppdev_frob_struct {
414 unsigned char mask;
415 unsigned char val;
416 };
417
418 The mask and val fields are bitwise ORs of control line names
419 (such as in PPWCONTROL). The operation performed by PPFCONTROL
420 is:
421
422 new_ctr = (old_ctr & ~mask) | val
423
424 In other words, the signals named in mask are set to the
425 values in val.
426 """
427 fcntl.ioctl(self._fd, PPFCONTROL, struct.pack('BB', mask, val))
428
429 def PPRSTATUS(self):
430 """
431 Returns an unsigned char containing bits set for each status
432 line that is set (for instance, PARPORT_STATUS_BUSY). The
433 ioctl parameter should be a pointer to an unsigned char.
434 """
435 ret = struct.pack('B',0)
436 ret = fcntl.ioctl(self._fd, PPRSTATUS, ret)
437 return struct.unpack('B', ret)[0]
438
439 def PPDATADIR(self, out):
440 """
441 Controls the data line drivers. Normally the computer's
442 parallel port will drive the data lines, but for byte-wide
443 transfers from the peripheral to the host it is useful to turn
444 off those drivers and let the peripheral drive the
445 signals. (If the drivers on the computer's parallel port are
446 left on when this happens, the port might be damaged.)
447 This is only needed in conjunction with PPWDATA or PPRDATA.
448
449 The 'out' parameter indicates the desired port direction. If
450 'out' is true or non-zero, the drivers are turned on (forward
451 direction); otherwise, the drivers are turned off (reverse
452 direction).
453 """
454 if out:
455 msg=struct.pack('i',0)
456 else:
457 msg=struct.pack('i',1)
458 fcntl.ioctl(self._fd, PPDATADIR, msg)
459
460 def PPWDATA(self, byte):
461 """
462 Sets the data lines (if in forward mode). The ioctl parameter
463 is a pointer to an unsigned char.
464 """
465 fcntl.ioctl(self._fd, PPWDATA,struct.pack('B',byte))
466
467 def PPRDATA(self):
468 """
469 Reads the data lines (if in reverse mode). The ioctl parameter
470 is a pointer to an unsigned char.
471 """
472 ret=struct.pack('B',0)
473 ret=fcntl.ioctl(self._fd, PPRDATA,ret)
474 return struct.unpack('B',ret)[0]
475
476 def PPCLRIRQ(self):
477 """
478 Returns the current interrupt count, and clears it. The ppdev
479 driver keeps a count of interrupts as they are triggered.
480 """
481 ret=struct.pack('i',0)
482 ret=fcntl.ioctl(self._fd, PPCLRIRQ,ret)
483 return struct.unpack('i',ret)[0]
484
485 def PPWCTLONIRQ(self, lines):
486 """
487 Set a trigger response. Afterwards when an interrupt is
488 triggered, the interrupt handler will set the control lines as
489 requested. The ioctl parameter is a pointer to an unsigned
490 char, which is interpreted in the same way as for PPWCONTROL.
491
492 The reason for this ioctl is simply speed. Without this ioctl,
493 responding to an interrupt would start in the interrupt
494 handler, switch context to the user-land driver via poll or
495 select, and then switch context back to the kernel in order to
496 handle PPWCONTROL. Doing the whole lot in the interrupt
497 handler is a lot faster.
498 """
499 fcntl.ioctl(self._fd, PPWCTLONIRQ,struct.pack('B',lines))
500
501 #data lines
502## def data(self):
503## """Returns the states of the data bus line drivers (pins 2-9)"""
504## return self._data
505
506 def setDataDir(self,out):
507 """Activates or deactivates the data bus line drivers (pins 2-9)"""
508 self._dataDir = out
509 self.PPDATADIR(out)
510
511 def dataDir(self):
512 """Returns true if the data bus line drivers are on (pins 2-9)"""
513 return self._dataDir
514
515 #control lines
516## def strobe(self):
517## """Returns the state of the nStrobe output (pin 1)"""
518## return (self.PPRCONTROL()&PARPORT_CONTROL_STROBE)==0
519
520 def setDataStrobe(self, level):
521 """Sets the state of the nStrobe output (pin 1)"""
522 if level:
523 self.PPFCONTROL(PARPORT_CONTROL_STROBE, 0)
524 else:
525 self.PPFCONTROL(PARPORT_CONTROL_STROBE, PARPORT_CONTROL_STROBE)
526
527## def autoFd(self):
528## """Returns the state of the nAutoFd output (pin 14)"""
529## return (self.PPRCONTROL()&PARPORT_CONTROL_AUTOFD)==0
530
531 def setAutoFeed(self, level):
532 """Sets the state of the nAutoFd output (pin 14)"""
533 if level:
534 self.PPFCONTROL(PARPORT_CONTROL_AUTOFD, 0)
535 else:
536 self.PPFCONTROL(PARPORT_CONTROL_AUTOFD, PARPORT_CONTROL_AUTOFD)
537
538## def init(self):
539## """Returns the state of the nInit output (pin 16)"""
540## return (self.PPRCONTROL()&PARPORT_CONTROL_INIT)!=0
541
542 def setInitOut(self, level):
543 """Sets the state of the nInit output (pin 16)"""
544 if level:
545 self.PPFCONTROL(PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT)
546 else:
547 self.PPFCONTROL(PARPORT_CONTROL_INIT, 0)
548
549## def selectIn(self):
550## """Returns the state of the nSelectIn output (pin 17)"""
551## return (self.PPRCONTROL()&PARPORT_CONTROL_SELECT)==0
552
553 def setSelect(self,level):
554 """Sets the state of the nSelectIn output (pin 17)"""
555 if level:
556 self.PPFCONTROL(PARPORT_CONTROL_SELECT, 0)
557 else:
558 self.PPFCONTROL(PARPORT_CONTROL_SELECT, PARPORT_CONTROL_SELECT)
559
560 def setData(self,d):
561 """Sets the states of the data bus line drivers (pins 2-9)"""
562 self._data=d
563 return self.PPWDATA(d)
564
565 #status lines
566 def getInError(self):
567 """Returns the level on the nFault pin (15)"""
568 return (self.PPRSTATUS() & PARPORT_STATUS_ERROR) != 0
569
cliechtie7d23fe2003-05-26 19:42:23 +0000570 def getInSelected(self):
cliechti619e4562002-07-31 00:53:06 +0000571 """Returns the level on the Select pin (13)"""
572 return (self.PPRSTATUS() & PARPORT_STATUS_SELECT) != 0
573
574 def getInPaperOut(self):
575 """Returns the level on the paperOut pin (12)"""
576 return (self.PPRSTATUS() & PARPORT_STATUS_PAPEROUT) != 0
577
578 def getInAcknowledge(self):
579 """Returns the level on the nAck pin (10)"""
580 return (self.PPRSTATUS() & PARPORT_STATUS_ACK) != 0
581
582 def getInBusy(self):
583 """Returns the level on the Busy pin (11)"""
584 return (self.PPRSTATUS() & PARPORT_STATUS_BUSY) == 0
585