pyparallel-0.2.2/0000775000175000017500000000000012642703645014737 5ustar hjacobshjacobs00000000000000pyparallel-0.2.2/setup.py0000664000175000017500000000274412642703644016457 0ustar hjacobshjacobs00000000000000#!/usr/bin/env python # setup.py try: from setuptools import setup except ImportError: from distutils.core import setup import sys # windows installer: # python setup.py bdist_wininst # patch distutils if it can't cope with the "classifiers" or # "download_url" keywords if sys.version < '2.2.3': from distutils.dist import DistributionMetadata DistributionMetadata.classifiers = None DistributionMetadata.download_url = None import os if os.name == 'nt': # set dependencies for windows version data_files = {'parallel': ['simpleio.dll']} else: # no dependencies data_files = {} def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( name='pyparallel', description='Python Parallel Port Extension', version='0.2.2', author='Chris Liechti', author_email='cliechti@gmx.net', url='https://github.com/pyserial/pyparallel', packages=['parallel'], license='BSD', long_description=read('README.rst'), classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Natural Language :: English', 'Operating System :: POSIX', 'Operating System :: Microsoft :: Windows', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Topic :: Communications', 'Topic :: Software Development :: Libraries', ], package_data=data_files ) pyparallel-0.2.2/pyparallel.egg-info/0000775000175000017500000000000012642703645020576 5ustar hjacobshjacobs00000000000000pyparallel-0.2.2/pyparallel.egg-info/top_level.txt0000664000175000017500000000001112642703645023320 0ustar hjacobshjacobs00000000000000parallel pyparallel-0.2.2/pyparallel.egg-info/dependency_links.txt0000664000175000017500000000000112642703645024644 0ustar hjacobshjacobs00000000000000 pyparallel-0.2.2/pyparallel.egg-info/SOURCES.txt0000664000175000017500000000037512642703645022467 0ustar hjacobshjacobs00000000000000README.rst setup.py parallel/__init__.py parallel/parallelppdev.py parallel/parallelutil.py parallel/parallelwin32.py pyparallel.egg-info/PKG-INFO pyparallel.egg-info/SOURCES.txt pyparallel.egg-info/dependency_links.txt pyparallel.egg-info/top_level.txtpyparallel-0.2.2/pyparallel.egg-info/PKG-INFO0000664000175000017500000000604312642703645021676 0ustar hjacobshjacobs00000000000000Metadata-Version: 1.1 Name: pyparallel Version: 0.2.2 Summary: Python Parallel Port Extension Home-page: https://github.com/pyserial/pyparallel Author: Chris Liechti Author-email: cliechti@gmx.net License: BSD Description: pyParallel [in development] ============================ Overview -------- This module encapsulates the access for the parallel port. It provides backends for Python running on Windows and Linux. Other platforms are possible too but not yet integrated. This module is still under development. But it may be useful for developers. The Windows version needs a compiled extension and the giveio.sys driver for Windows NT/2k/XP. It uses ctypes to access functions in a prebuilt DLL. It is released under a free software license, see LICENSE.txt for more details. Copyright (C) 2001-2016 Chris Liechti cliechti@gmx.net Homepage: https://github.com/pyserial/pyparallel Features -------- * same class based interface on all supported platforms * port numbering starts at zero, no need to know the port name in the user program * port string (device name) can be specified if access through numbering is inappropriate Requirements ------------ * Python 2.2 or newer * "Java Communications" (JavaComm) extension for Java/Jython Installation ------------ Extract files from the archive, open a shell/console in that directory and let Distutils do the rest: .. code-block:: bash $ python setup.py install Short introduction ------------------ .. code-block:: python >>> import parallel >>> p = parallel.Parallel() # open LPT1 or /dev/parport0 >>> p.setData(0x55) Examples -------- Please look in the GIT Repository. There is an example directory where you can find a simple terminal and more. https://github.com/pyserial/pyparallel/tree/master/examples References ---------- * Python: http://www.python.org * Jython: http://www.jython.org * Java@IBM http://www-106.ibm.com/developerworks/java/jdk/ (JavaComm links are on the download page for the respective platform jdk) * Java@SUN http://java.sun.com/products/ Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Natural Language :: English Classifier: Operating System :: POSIX Classifier: Operating System :: Microsoft :: Windows Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Communications Classifier: Topic :: Software Development :: Libraries pyparallel-0.2.2/PKG-INFO0000664000175000017500000000604312642703645016037 0ustar hjacobshjacobs00000000000000Metadata-Version: 1.1 Name: pyparallel Version: 0.2.2 Summary: Python Parallel Port Extension Home-page: https://github.com/pyserial/pyparallel Author: Chris Liechti Author-email: cliechti@gmx.net License: BSD Description: pyParallel [in development] ============================ Overview -------- This module encapsulates the access for the parallel port. It provides backends for Python running on Windows and Linux. Other platforms are possible too but not yet integrated. This module is still under development. But it may be useful for developers. The Windows version needs a compiled extension and the giveio.sys driver for Windows NT/2k/XP. It uses ctypes to access functions in a prebuilt DLL. It is released under a free software license, see LICENSE.txt for more details. Copyright (C) 2001-2016 Chris Liechti cliechti@gmx.net Homepage: https://github.com/pyserial/pyparallel Features -------- * same class based interface on all supported platforms * port numbering starts at zero, no need to know the port name in the user program * port string (device name) can be specified if access through numbering is inappropriate Requirements ------------ * Python 2.2 or newer * "Java Communications" (JavaComm) extension for Java/Jython Installation ------------ Extract files from the archive, open a shell/console in that directory and let Distutils do the rest: .. code-block:: bash $ python setup.py install Short introduction ------------------ .. code-block:: python >>> import parallel >>> p = parallel.Parallel() # open LPT1 or /dev/parport0 >>> p.setData(0x55) Examples -------- Please look in the GIT Repository. There is an example directory where you can find a simple terminal and more. https://github.com/pyserial/pyparallel/tree/master/examples References ---------- * Python: http://www.python.org * Jython: http://www.jython.org * Java@IBM http://www-106.ibm.com/developerworks/java/jdk/ (JavaComm links are on the download page for the respective platform jdk) * Java@SUN http://java.sun.com/products/ Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Natural Language :: English Classifier: Operating System :: POSIX Classifier: Operating System :: Microsoft :: Windows Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Communications Classifier: Topic :: Software Development :: Libraries pyparallel-0.2.2/parallel/0000775000175000017500000000000012642703645016533 5ustar hjacobshjacobs00000000000000pyparallel-0.2.2/parallel/parallelppdev.py0000664000175000017500000005204012641247776021750 0ustar hjacobshjacobs00000000000000#!/usr/bin/env python # parallel port access using the ppdev driver import sys import struct import fcntl import os #---- # Generated by h2py 0.1.1 from , # then cleaned up a bit by Michael P. Ashton and then a gain by chris ;-) # Changes for Python2.2 support (c) September 2004 Alex.Perry@qm.com def sizeof(type): return struct.calcsize(type) def _IOC(dir, type, nr, size): return int((dir << _IOC_DIRSHIFT ) | (type << _IOC_TYPESHIFT ) |\ (nr << _IOC_NRSHIFT ) | (size << _IOC_SIZESHIFT)) def _IO(type, nr): return _IOC(_IOC_NONE, type, nr, 0) def _IOR(type,nr,size): return _IOC(_IOC_READ, type, nr, sizeof(size)) def _IOW(type,nr,size): return _IOC(_IOC_WRITE, type, nr, sizeof(size)) _IOC_SIZEBITS = 14 _IOC_SIZEMASK = (1 << _IOC_SIZEBITS ) - 1 _IOC_NRSHIFT = 0 _IOC_NRBITS = 8 _IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS _IOC_TYPEBITS = 8 _IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS IOCSIZE_MASK = _IOC_SIZEMASK << _IOC_SIZESHIFT IOCSIZE_SHIFT = _IOC_SIZESHIFT # Python 2.2 uses a signed int for the ioctl() call, so ... if ( sys.version_info[0] < 3 ) or ( sys.version_info[1] < 3 ): _IOC_WRITE = 1 _IOC_READ = -2 _IOC_INOUT = -1 else: _IOC_WRITE = 1 _IOC_READ = 2 _IOC_INOUT = 3 _IOC_DIRSHIFT = _IOC_SIZESHIFT + _IOC_SIZEBITS IOC_INOUT = _IOC_INOUT << _IOC_DIRSHIFT IOC_IN = _IOC_WRITE << _IOC_DIRSHIFT IOC_OUT = _IOC_READ << _IOC_DIRSHIFT _IOC_NONE = 0 PP_IOCTL = ord('p') PPCLAIM = _IO(PP_IOCTL, 0x8b) PPCLRIRQ = _IOR(PP_IOCTL, 0x93, 'i') PPDATADIR = _IOW(PP_IOCTL, 0x90, 'i') PPEXCL = _IO(PP_IOCTL, 0x8f) PPFCONTROL = _IOW(PP_IOCTL, 0x8e, 'BB') PPGETFLAGS = _IOR(PP_IOCTL, 0x9a, 'i') PPGETMODE = _IOR(PP_IOCTL, 0x98, 'i') PPGETMODES = _IOR(PP_IOCTL, 0x97, 'I') PPGETPHASE = _IOR(PP_IOCTL, 0x99, 'i') PPGETTIME = _IOR(PP_IOCTL, 0x95, 'll') PPNEGOT = _IOW(PP_IOCTL, 0x91, 'i') PPRCONTROL = _IOR(PP_IOCTL, 0x83, 'B') PPRDATA = _IOR(PP_IOCTL, 0x85, 'B') #'OBSOLETE__IOR' undefined in 'PPRECONTROL' PPRELEASE = _IO(PP_IOCTL, 0x8c) #'OBSOLETE__IOR' undefined in 'PPRFIFO' PPRSTATUS = _IOR(PP_IOCTL, 0x81, 'B') PPSETFLAGS = _IOW(PP_IOCTL, 0x9b, 'i') PPSETMODE = _IOW(PP_IOCTL, 0x80, 'i') PPSETPHASE = _IOW(PP_IOCTL, 0x94, 'i') PPSETTIME = _IOW(PP_IOCTL, 0x96, 'll') PPWCONTROL = _IOW(PP_IOCTL, 0x84, 'B') PPWCTLONIRQ = _IOW(PP_IOCTL, 0x92, 'B') PPWDATA = _IOW(PP_IOCTL, 0x86, 'B') #'OBSOLETE__IOW' undefined in 'PPWECONTROL' #'OBSOLETE__IOW' undefined in 'PPWFIFO' #'OBSOLETE__IOW' undefined in 'PPWSTATUS' PPYIELD = _IO(PP_IOCTL, 0x8d) PP_FASTREAD = 1 << 3 PP_FASTWRITE = 1 << 2 PP_W91284PIC = 1 << 4 PP_FLAGMASK = PP_FASTWRITE | PP_FASTREAD | PP_W91284PIC PP_MAJOR = 99 _ASMI386_IOCTL_H= None _IOC_DIRBITS = 2 _IOC_DIRMASK = (1 << _IOC_DIRBITS) - 1 _IOC_NRMASK = (1 << _IOC_NRBITS) - 1 _IOC_TYPEMASK = (1 << _IOC_TYPEBITS ) - 1 def _IOC_DIR(nr): return (nr >> _IOC_DIRSHIFT) & _IOC_DIRMASK def _IOC_NR(nr): return (nr >> _IOC_NRSHIFT) & _IOC_NRMASK def _IOC_SIZE(nr): return (nr >> _IOC_SIZESHIFT) & _IOC_SIZEMASK def _IOC_TYPE(nr): return (nr >> _IOC_TYPESHIFT) & _IOC_TYPEMASK def _IOWR(type, nr, size): return _IOC(_IOC_READ | _IOC_WRITE, type, nr , sizeof(size)) __ELF__ = 1 __i386 = 1 __i386__ = 1 __linux = 1 __linux__ = 1 __unix = 1 __unix__ = 1 i386 = 1 linux = 1 unix = 1 #-------- Constants from PARPORT_CONTROL_STROBE = 0x1 PARPORT_CONTROL_AUTOFD = 0x2 PARPORT_CONTROL_INIT = 0x4 PARPORT_CONTROL_SELECT = 0x8 PARPORT_STATUS_ERROR = 8 PARPORT_STATUS_SELECT = 0x10 PARPORT_STATUS_PAPEROUT = 0x20 PARPORT_STATUS_ACK = 0x40 PARPORT_STATUS_BUSY = 0x80 IEEE1284_MODE_NIBBLE = 0 IEEE1284_MODE_BYTE = 1 IEEE1284_MODE_COMPAT = 1<<8 IEEE1284_MODE_BECP = 1<<9 IEEE1284_MODE_ECP = 1<<4 IEEE1284_MODE_ECPRLE = IEEE1284_MODE_ECP | (1<<5) IEEE1284_MODE_ECPSWE = 1<<10 IEEE1284_MODE_EPP = 1<<6 IEEE1284_MODE_EPPSL = 1<<11 IEEE1284_MODE_EPPSWE = 1<<12 IEEE1284_DEVICEID = 1<<2 IEEE1284_EXT_LINK = 1<<14 IEEE1284_ADDR = 1<<13 IEEE1284_DATA = 0 PARPORT_EPP_FAST = 1 PARPORT_W91284PIC = 2 #---- class Parallel: """Class for controlling the pins on a parallel port This class provides bit-level access to the pins on a PC parallel port. It is primarily designed for programs which must control special circuitry - most often non-IEEE-1284-compliant devices other than printers - using 'bit-banging' techniques. The current implementation makes ioctl() calls to the Linux ppdev driver, using the Python fcntl library. It might be rewritten in C for extra speed. This particular implementation is written for Linux; all of the upper-level calls can be ported to Windows as well. On Linux, the ppdev device driver, from the Linux 2.4 parallel port subsystem, is used to control the parallel port hardware. This driver must be made available from a kernel compile. The option is called "Support user-space parallel-port drivers". When using the module, be sure to unload the lp module first: usually the lp module claims exclusive access to the parallel port, and if it is loaded, this class will fail to open the parallel port file, and throw an exception. The primary source of information about the Linux 2.4 parallel port subsystem is Tim Waugh's documentation, the source for which is available in the kernel tree. This document (called, appropriately enough, "The Linux 2.4 Parallel Port Subsystem"), thoroughly describes the parallel port drivers and how to use them. This class provides a method for each of the ioctls supported by the ppdev module. The ioctl methods are named, in uppercase, the same as the ioctls they invoke. The documentation for these methods was taken directly from the documentation for their corresponding ioctl, and modified only where necessary. Unless you have special reason to use the Linux ioctls, you should use instead the upper-level functions, which are named in lowerCase fashion and should be portable between Linux and Windows. This way, any code you write for this class will (or should) also work with the Windows version of this class. """ def __init__(self, port = 0): if type(port) == type(""): self.device = port else: self.device = "/dev/parport%d" % port self._fd = None self._fd = os.open(self.device, os.O_RDWR) try: self.PPEXCL() self.PPCLAIM() self.setDataDir(1) self.setData(0) except IOError: os.close(self._fd) self._fd = None raise def __del__(self): if self._fd is not None: self.PPRELEASE() os.close(self._fd) def timevalToFloat(self, timeval): t=struct.unpack('ll', timeval) return t[0] + (t[1]/1000000.0) def floatToTimeval(self, time): sec = int(time) usec = int(time*1000000.0) return struct.pack('ll', sec, usec) def PPCLAIM(self): """ Claims access to the port. As a user-land device driver writer, you will need to do this before you are able to actually change the state of the parallel port in any way. Note that some operations only affect the ppdev driver and not the port, such as PPSETMODE; they can be performed while access to the port is not claimed. """ fcntl.ioctl(self._fd, PPCLAIM) def PPEXCL(self): """ Instructs the kernel driver to forbid any sharing of the port with other drivers, i.e. it requests exclusivity. The PPEXCL command is only valid when the port is not already claimed for use, and it may mean that the next PPCLAIM ioctl will fail: some other driver may already have registered itself on that port. Most device drivers don't need exclusive access to the port. It's only provided in case it is really needed, for example for devices where access to the port is required for extensive periods of time (many seconds). Note that the PPEXCL ioctl doesn't actually claim the port there and then---action is deferred until the PPCLAIM ioctl is performed. """ fcntl.ioctl(self._fd, PPEXCL) def PPRELEASE(self): """ Releases the port. Releasing the port undoes the effect of claiming the port. It allows other device drivers to talk to their devices (assuming that there are any). """ fcntl.ioctl(self._fd, PPRELEASE) def PPYIELD(self): """ Yields the port to another driver. This ioctl is a kind of short-hand for releasing the port and immediately reclaiming it. It gives other drivers a chance to talk to their devices, but afterwards claims the port back. An example of using this would be in a user-land printer driver: once a few characters have been written we could give the port to another device driver for a while, but if we still have characters to send to the printer we would want the port back as soon as possible. It is important not to claim the parallel port for too long, as other device drivers will have no time to service their devices. If your device does not allow for parallel port sharing at all, it is better to claim the parallel port exclusively (see PPEXCL). """ fcntl.ioctl(self._fd, PPYIELD) def PPNEGOT(self, mode): """ Performs IEEE 1284 negotiation into a particular mode. Briefly, negotiation is the method by which the host and the peripheral decide on a protocol to use when transferring data. An IEEE 1284 compliant device will start out in compatibility mode, and then the host can negotiate to another mode (such as ECP). The 'mode' parameter should be one of the following constants from PPDEV: - IEEE1284_MODE_COMPAT - IEEE1284_MODE_NIBBLE - IEEE1284_MODE_BYTE - IEEE1284_MODE_EPP - IEEE1284_MODE_ECP The PPNEGOT ioctl actually does two things: it performs the on-the-wire negotiation, and it sets the behaviour of subsequent read/write calls so that they use that mode (but see PPSETMODE). """ fcntl.ioctl(self._fd, PPNEGOT, struct.pack('i', mode)) def PPSETMODE(self, mode): """ Sets which IEEE 1284 protocol to use for the read and write calls. The 'mode' parameter should be one of the following constants from PPDEV: - IEEE1284_MODE_COMPAT - IEEE1284_MODE_NIBBLE - IEEE1284_MODE_BYTE - IEEE1284_MODE_EPP - IEEE1284_MODE_ECP """ fcntl.ioctl(self._fd, PPSETMODE, struct.pack('i', mode)) def PPGETMODE(self): """ Retrieves the IEEE 1284 mode being used for read and write. The return value is one of the following constants from PPDEV: - IEEE1284_MODE_COMPAT - IEEE1284_MODE_NIBBLE - IEEE1284_MODE_BYTE - IEEE1284_MODE_EPP - IEEE1284_MODE_ECP """ ret = struct.pack('i', 0) ret = fcntl.ioctl(self._fd, PPGETMODE, ret) return struct.unpack('i', ret)[0] def PPGETTIME(self): """ Retrieves the time-out value. The read and write calls will time out if the peripheral doesn't respond quickly enough. The PPGETTIME ioctl retrieves the length of time that the peripheral is allowed to have before giving up. Returns the timeout value in seconds as a floating-point value. """ ret = struct.pack('ll', 0, 0) ret = fcntl.ioctl(self._fd, PPGETTIME, ret) return timevalToFloat(ret) def PPSETTIME(self, time): """ Sets the time-out (see PPGETTIME for more information). 'time' is the new time-out in seconds; floating-point values are acceptable. """ fcntl.ioctl(self._fd, PPSETTIME, floatToTimeval(time)) def PPGETMODES(self): """ Retrieves the capabilities of the hardware (i.e. the modes field of the parport structure). """ raise NotImplementedError def PPSETFLAGS(self): """ Sets flags on the ppdev device which can affect future I/O operations. Available flags are: - PP_FASTWRITE - PP_FASTREAD - PP_W91284PIC """ raise NotImplementedError def PPWCONTROL(self, lines): """ Sets the control lines. The 'lines' parameter is a bitwise OR of the following constants from PPDEV: - PARPORT_CONTROL_STROBE - PARPORT_CONTROL_AUTOFD - PARPORT_CONTROL_INIT - PARPORT_CONTROL_SELECT """ fcntl.ioctl(self._fd, PPWCONTROL, struct.pack('B', lines)) def PPRCONTROL(self): """ Returns the last value written to the control register, in the form of an integer, for which each bit corresponds to a control line (although some are unused). This doesn't actually touch the hardware; the last value written is remembered in software. This is because some parallel port hardware does not offer read access to the control register. The control lines bits are defined by the following constants from PPDEV: - PARPORT_CONTROL_STROBE - PARPORT_CONTROL_AUTOFD - PARPORT_CONTROL_SELECT - PARPORT_CONTROL_INIT """ ret = struct.pack('B',0) ret = fcntl.ioctl(self._fd, PPRCONTROL, ret) return struct.unpack('B', ret)[0] def PPFCONTROL(self, mask, val): """ Frobs the control lines. Since a common operation is to change one of the control signals while leaving the others alone, it would be quite inefficient for the user-land driver to have to use PPRCONTROL, make the change, and then use PPWCONTROL. Of course, each driver could remember what state the control lines are supposed to be in (they are never changed by anything else), but in order to provide PPRCONTROL, ppdev must remember the state of the control lines anyway. The PPFCONTROL ioctl is for "frobbing" control lines, and is like PPWCONTROL but acts on a restricted set of control lines. The ioctl parameter is a pointer to a struct ppdev_frob_struct: struct ppdev_frob_struct { unsigned char mask; unsigned char val; }; The mask and val fields are bitwise ORs of control line names (such as in PPWCONTROL). The operation performed by PPFCONTROL is: new_ctr = (old_ctr & ~mask) | val In other words, the signals named in mask are set to the values in val. """ fcntl.ioctl(self._fd, PPFCONTROL, struct.pack('BB', mask, val)) def PPRSTATUS(self): """ Returns an unsigned char containing bits set for each status line that is set (for instance, PARPORT_STATUS_BUSY). The ioctl parameter should be a pointer to an unsigned char. """ ret = struct.pack('B',0) ret = fcntl.ioctl(self._fd, PPRSTATUS, ret) return struct.unpack('B', ret)[0] def PPDATADIR(self, out): """ Controls the data line drivers. Normally the computer's parallel port will drive the data lines, but for byte-wide transfers from the peripheral to the host it is useful to turn off those drivers and let the peripheral drive the signals. (If the drivers on the computer's parallel port are left on when this happens, the port might be damaged.) This is only needed in conjunction with PPWDATA or PPRDATA. The 'out' parameter indicates the desired port direction. If 'out' is true or non-zero, the drivers are turned on (forward direction); otherwise, the drivers are turned off (reverse direction). """ if out: msg=struct.pack('i',0) else: msg=struct.pack('i',1) fcntl.ioctl(self._fd, PPDATADIR, msg) def PPWDATA(self, byte): """ Sets the data lines (if in forward mode). The ioctl parameter is a pointer to an unsigned char. """ fcntl.ioctl(self._fd, PPWDATA,struct.pack('B',byte)) def PPRDATA(self): """ Reads the data lines (if in reverse mode). The ioctl parameter is a pointer to an unsigned char. """ ret=struct.pack('B',0) ret=fcntl.ioctl(self._fd, PPRDATA,ret) return struct.unpack('B',ret)[0] def PPCLRIRQ(self): """ Returns the current interrupt count, and clears it. The ppdev driver keeps a count of interrupts as they are triggered. """ ret=struct.pack('i',0) ret=fcntl.ioctl(self._fd, PPCLRIRQ,ret) return struct.unpack('i',ret)[0] def PPWCTLONIRQ(self, lines): """ Set a trigger response. Afterwards when an interrupt is triggered, the interrupt handler will set the control lines as requested. The ioctl parameter is a pointer to an unsigned char, which is interpreted in the same way as for PPWCONTROL. The reason for this ioctl is simply speed. Without this ioctl, responding to an interrupt would start in the interrupt handler, switch context to the user-land driver via poll or select, and then switch context back to the kernel in order to handle PPWCONTROL. Doing the whole lot in the interrupt handler is a lot faster. """ fcntl.ioctl(self._fd, PPWCTLONIRQ,struct.pack('B',lines)) #data lines ## def data(self): ## """Returns the states of the data bus line drivers (pins 2-9)""" ## return self._data def setDataDir(self,out): """Activates or deactivates the data bus line drivers (pins 2-9)""" self._dataDir = out self.PPDATADIR(out) def dataDir(self): """Returns true if the data bus line drivers are on (pins 2-9)""" return self._dataDir #control lines ## def strobe(self): ## """Returns the state of the nStrobe output (pin 1)""" ## return (self.PPRCONTROL()&PARPORT_CONTROL_STROBE)==0 def setDataStrobe(self, level): """Sets the state of the nStrobe output (pin 1)""" if level: self.PPFCONTROL(PARPORT_CONTROL_STROBE, 0) else: self.PPFCONTROL(PARPORT_CONTROL_STROBE, PARPORT_CONTROL_STROBE) ## def autoFd(self): ## """Returns the state of the nAutoFd output (pin 14)""" ## return (self.PPRCONTROL()&PARPORT_CONTROL_AUTOFD)==0 def setAutoFeed(self, level): """Sets the state of the nAutoFd output (pin 14)""" if level: self.PPFCONTROL(PARPORT_CONTROL_AUTOFD, 0) else: self.PPFCONTROL(PARPORT_CONTROL_AUTOFD, PARPORT_CONTROL_AUTOFD) ## def init(self): ## """Returns the state of the nInit output (pin 16)""" ## return (self.PPRCONTROL()&PARPORT_CONTROL_INIT)!=0 def setInitOut(self, level): """Sets the state of the nInit output (pin 16)""" if level: self.PPFCONTROL(PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT) else: self.PPFCONTROL(PARPORT_CONTROL_INIT, 0) ## def selectIn(self): ## """Returns the state of the nSelectIn output (pin 17)""" ## return (self.PPRCONTROL()&PARPORT_CONTROL_SELECT)==0 def setSelect(self,level): """Sets the state of the nSelectIn output (pin 17)""" if level: self.PPFCONTROL(PARPORT_CONTROL_SELECT, 0) else: self.PPFCONTROL(PARPORT_CONTROL_SELECT, PARPORT_CONTROL_SELECT) def setData(self,d): """Sets the states of the data bus line drivers (pins 2-9)""" self._data=d return self.PPWDATA(d) def getData(self): """Gets the states of the data bus line (pin 2-9)""" return self.PPRDATA() # status lines def getInError(self): """Returns the level on the nFault pin (15)""" return (self.PPRSTATUS() & PARPORT_STATUS_ERROR) != 0 def getInSelected(self): """Returns the level on the Select pin (13)""" return (self.PPRSTATUS() & PARPORT_STATUS_SELECT) != 0 def getInPaperOut(self): """Returns the level on the paperOut pin (12)""" return (self.PPRSTATUS() & PARPORT_STATUS_PAPEROUT) != 0 def getInAcknowledge(self): """Returns the level on the nAck pin (10)""" return (self.PPRSTATUS() & PARPORT_STATUS_ACK) != 0 def getInBusy(self): """Returns the level on the Busy pin (11)""" return (self.PPRSTATUS() & PARPORT_STATUS_BUSY) == 0 pyparallel-0.2.2/parallel/__init__.py0000664000175000017500000000102112642700604020626 0ustar hjacobshjacobs00000000000000# portable parallel port access with python # this is a wrapper module for different platform implementations # # (C)2001-2002 Chris Liechti # this is distributed under a free software license, see license.txt import os VERSION = "0.3" # choose an implementation, depending on os if os.name == 'nt': from parallel.parallelwin32 import Parallel # noqa elif os.name == 'posix': from parallel.parallelppdev import Parallel # noqa else: raise "Sorry no implementation for your platform available." pyparallel-0.2.2/parallel/parallelwin32.py0000664000175000017500000001131712641247776021576 0ustar hjacobshjacobs00000000000000#pyparallel driver for win32 #see __init__.py # #(C) 2002 Chris Liechti # this is distributed under a free software license, see license.txt # # thanks to Dincer Aydin dinceraydin@altavista.net for his work on the # winioport module: www.geocities.com/dinceraydin/ the graphic below is # borrowed form him ;-) # LPT1 = 0x0378 or 0x03BC # LPT2 = 0x0278 or 0x0378 # LPT3 = 0x0278 # # Data Register (base + 0) ........ outputs # # 7 6 5 4 3 2 1 0 # . . . . . . . * D0 ........... (pin 2), 1=High, 0=Low (true) # . . . . . . * . D1 ........... (pin 3), 1=High, 0=Low (true) # . . . . . * . . D2 ........... (pin 4), 1=High, 0=Low (true) # . . . . * . . . D3 ........... (pin 5), 1=High, 0=Low (true) # . . . * . . . . D4 ........... (pin 6), 1=High, 0=Low (true) # . . * . . . . . D5 ........... (pin 7), 1=High, 0=Low (true) # . * . . . . . . D6 ........... (pin 8), 1=High, 0=Low (true) # * . . . . . . . D7 ........... (pin 9), 1=High, 0=Low (true) # # Status Register (base + 1) ...... inputs # # 7 6 5 4 3 2 1 0 # . . . . . * * * Undefined # . . . . * . . . Error ........ (pin 15), high=1, low=0 (true) # . . . * . . . . Selected ..... (pin 13), high=1, low=0 (true) # . . * . . . . . No paper ..... (pin 12), high=1, low=0 (true) # . * . . . . . . Ack .......... (pin 10), high=1, low=0 (true) # * . . . . . . . Busy ......... (pin 11), high=0, low=1 (inverted) # # ctrl Register (base + 2) ..... outputs # # 7 6 5 4 3 2 1 0 # . . . . . . . * Strobe ....... (pin 1), 1=low, 0=high (inverted) # . . . . . . * . Auto Feed .... (pin 14), 1=low, 0=high (inverted) # . . . . . * . . Initialize ... (pin 16), 1=high,0=low (true) # . . . . * . . . Select ....... (pin 17), 1=low, 0=high (inverted) # * * * * . . . . Unused LPT1 = 0 LPT2 = 1 LPT1_base = 0x0378 LPT2_base = 0x0278 import ctypes import os #need to patch PATH so that the DLL can be found and loaded os.environ['PATH'] = os.environ['PATH'] + ';' + os.path.abspath(os.path.dirname(__file__)) #fake module, names of the functions are the same as in the old _pyparallel #python extension in earlier versions of this modules _pyparallel = ctypes.windll.simpleio #need to initialize giveio on WinNT based systems if _pyparallel.init(): raise IOError('Could not access the giveio driver which is required on NT based systems.') class Parallel: def __init__(self, port = LPT1): if port == LPT1: self.dataRegAdr = LPT1_base elif port == LPT2: self.dataRegAdr = LPT2_base else: raise ValueError("No such port available - expecting a number") self.statusRegAdr = self.dataRegAdr + 1 self.ctrlRegAdr = self.dataRegAdr + 2 self.ctrlReg = _pyparallel.inp(self.ctrlRegAdr) def setData(self, value): _pyparallel.outp(self.dataRegAdr, value) def setDataDir( self, level): """set for port as input, clear for output""" if level: self.ctrlReg |= 0x20 else: self.ctrlReg &= ~0x20 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg) # control register output functions def setDataStrobe(self, level): """data strobe bit""" if level: self.ctrlReg = self.ctrlReg & ~0x01 else: self.ctrlReg = self.ctrlReg | 0x01 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg) def setAutoFeed(self, level): """auto feed bit""" if level: self.ctrlReg = self.ctrlReg & ~0x02 else: self.ctrlReg = self.ctrlReg | 0x02 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg) def setInitOut(self, level): """initialize bit""" if level: self.ctrlReg = self.ctrlReg | 0x04 else: self.ctrlReg = self.ctrlReg & ~0x04 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg) def setSelect(self, level): """select bit""" if level: self.ctrlReg = self.ctrlReg & ~0x08 else: self.ctrlReg = self.ctrlReg | 0x08 _pyparallel.outp(self.ctrlRegAdr, self.ctrlReg) def getInError(self): """Error pin""" return _pyparallel.inp(self.statusRegAdr) & 0x08 and 1 def getInSelected(self): """select pin""" return _pyparallel.inp(self.statusRegAdr) & 0x10 and 1 def getInPaperOut(self): """paper out pin""" return _pyparallel.inp(self.statusRegAdr) & 0x20 and 1 def getInAcknowledge(self): """Acknowledge pin""" return _pyparallel.inp(self.statusRegAdr) & 0x40 and 1 def getInBusy(self): """input from busy pin""" return not (_pyparallel.inp(self.statusRegAdr) & 0x80) pyparallel-0.2.2/parallel/parallelutil.py0000664000175000017500000001052412641247776021610 0ustar hjacobshjacobs00000000000000class BitaccessMeta(type): """meta class that adds bit access properties to a parallel port implementation""" def __new__(self, classname, bases, classdict): klass = type.__new__(self, classname, bases, classdict) # status lines klass.paperOut = property(klass.getInPaperOut, None, "Read the PaperOut signal") # control lines klass.dataStrobe = property(None, klass.setDataStrobe, "Set the DataStrobe signal") # XXX ... other bits # data bits for bit in range(8): mask = (1<> shift) & mask def setter(self, b, shift=shift, mask=mask): self.setData((self.getData() & ~(mask<>4) & 0xf), (x & 0xf))) # test setting p._data = 0 (p.D4_D7, p.D0_D3) = (((x>>4) & 0xf), (x & 0xf)) self.failUnlessEqual(p._data, x) def testStatusbits(self): """bit by bit status lines""" # read the property: self.p._dummy = 0 self.failUnlessEqual(self.p.paperOut, 0) self.p._dummy = 1 self.failUnlessEqual(self.p.paperOut, 1) # read only, must not be writable: self.failUnlessRaises(AttributeError, setattr, self.p, 'paperOut', 1) def testControlbits(self): """bit by bit control lines""" self.p.dataStrobe = 0 self.failUnlessEqual(self.p._last, ('setDataStrobe', 0)) self.p.dataStrobe = 1 self.failUnlessEqual(self.p._last, ('setDataStrobe', 1)) # write only, must not be writable: self.failUnlessRaises(AttributeError, getattr, self.p, 'dataStrobe') sys.argv.append('-v') # When this module is executed from the command-line, it runs all its tests unittest.main() pyparallel-0.2.2/README.rst0000664000175000017500000000346612642702542016432 0ustar hjacobshjacobs00000000000000pyParallel [in development] ============================ Overview -------- This module encapsulates the access for the parallel port. It provides backends for Python running on Windows and Linux. Other platforms are possible too but not yet integrated. This module is still under development. But it may be useful for developers. The Windows version needs a compiled extension and the giveio.sys driver for Windows NT/2k/XP. It uses ctypes to access functions in a prebuilt DLL. It is released under a free software license, see LICENSE.txt for more details. Copyright (C) 2001-2016 Chris Liechti cliechti@gmx.net Homepage: https://github.com/pyserial/pyparallel Features -------- * same class based interface on all supported platforms * port numbering starts at zero, no need to know the port name in the user program * port string (device name) can be specified if access through numbering is inappropriate Requirements ------------ * Python 2.2 or newer * "Java Communications" (JavaComm) extension for Java/Jython Installation ------------ Extract files from the archive, open a shell/console in that directory and let Distutils do the rest: .. code-block:: bash $ python setup.py install Short introduction ------------------ .. code-block:: python >>> import parallel >>> p = parallel.Parallel() # open LPT1 or /dev/parport0 >>> p.setData(0x55) Examples -------- Please look in the GIT Repository. There is an example directory where you can find a simple terminal and more. https://github.com/pyserial/pyparallel/tree/master/examples References ---------- * Python: http://www.python.org * Jython: http://www.jython.org * Java@IBM http://www-106.ibm.com/developerworks/java/jdk/ (JavaComm links are on the download page for the respective platform jdk) * Java@SUN http://java.sun.com/products/ pyparallel-0.2.2/setup.cfg0000664000175000017500000000007312642703645016560 0ustar hjacobshjacobs00000000000000[egg_info] tag_date = 0 tag_build = tag_svn_revision = 0