pyparallel-0.2.orig/0000755000175000017500000000000010177656601014402 5ustar dokodoko00000000000000pyparallel-0.2.orig/README.txt0000644000175000017500000000367510040342630016072 0ustar dokodoko00000000000000pyParallel [in developement] ============================ 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 developement. But it may be useful for developers. The windows version needs a compiled extension and the giveio.sys driver for Windows NT/2k/XP. The extension module can be compiled with distutils with either MSVC or GCC/mingw32. It is released under a free software license, see LICENSE.txt for more details. (C) 2001-2003 Chris Liechti cliechti@gmx.net Homepage: http://pyserial.sf.net 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 Disutils do the rest: python setup.py install The files get installed in the "Lib/site-packages" directory in newer Python versions. Short introduction ------------------ >>> import parallel >>> p = parallel.Parallel() #open LPT1 >>> p.setData(0x55) Examples -------- Please look in the CVS Repository. There is an example directory where you can find a simple terminal and more. http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pyserial/pyparallel/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 respecive platform jdk) * Java@SUN http://java.sun.com/products/ pyparallel-0.2.orig/LICENSE.txt0000644000175000017500000000553207521105612016220 0ustar dokodoko00000000000000Copyright (c) 2002 Chris Liechti ; All Rights Reserved. This is the Python license. In short, you can use this product in commercial and non-commercial applications, modify it, redistribute it. A notification to the author when you use and/or modify it is welcome. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING THIS SOFTWARE =================================================================== LICENSE AGREEMENT ----------------- 1. This LICENSE AGREEMENT is between the copyright holder of this product, and the Individual or Organization ("Licensee") accessing and otherwise using this product in source or binary form and its associated documentation. 2. Subject to the terms and conditions of this License Agreement, the copyright holder hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use this product alone or in any derivative version, provided, however, that copyright holders License Agreement and copyright holders notice of copyright are retained in this product alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or incorporates this product or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to this product. 4. The copyright holder is making this product available to Licensee on an "AS IS" basis. THE COPYRIGHT HOLDER MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, THE COPYRIGHT HOLDER MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS PRODUCT WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 5. THE COPYRIGHT HOLDER SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THIS PRODUCT FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING THIS PRODUCT, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 6. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 7. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between the copyright holder and Licensee. This License Agreement does not grant permission to use trademarks or trade names from the copyright holder in a trademark sense to endorse or promote products or services of Licensee, or any third party. 8. By copying, installing or otherwise using this product, Licensee agrees to be bound by the terms and conditions of this License Agreement. pyparallel-0.2.orig/CHANGES.txt0000644000175000017500000000005707521105652016207 0ustar dokodoko00000000000000Version 0.1 29 Jul 2002 added to CVS pyparallel-0.2.orig/setup.py0000644000175000017500000000104310176025340016077 0ustar dokodoko00000000000000#!/usr/bin/env python from distutils.core import setup import os if os.name == 'nt': data_files = {'parallel': ['simpleio.dll']} else: data_files = None setup (name = "pyparallel", description="Python Parallel Port Extension", version="0.2", author="Chris Liechti", author_email="cliechti@gmx.net", url="http://pyserial.sourceforge.net/", packages=['parallel'], license="Python", long_description="Python Parallel Port Extension for Win32, Linux, BSD", package_data = data_files ) pyparallel-0.2.orig/PKG-INFO0000644000175000017500000000045310176025434015472 0ustar dokodoko00000000000000Metadata-Version: 1.0 Name: pyparallel Version: 0.2 Summary: Python Parallel Port Extension Home-page: http://pyserial.sourceforge.net/ Author: Chris Liechti Author-email: cliechti@gmx.net License: Python Description: Python Parallel Port Extension for Win32, Linux, BSD Platform: UNKNOWN pyparallel-0.2.orig/parallel/0000755000175000017500000000000010177656601016176 5ustar dokodoko00000000000000pyparallel-0.2.orig/parallel/__init__.py0000644000175000017500000000137307711265336020314 0ustar dokodoko00000000000000#!/usr/bin/env python #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 sys, os, string VERSION = string.split("$Revision: 1.4 $")[1] #extract CVS version #chose an implementation, depending on os if os.name == 'nt': from parallelwin32 import * elif os.name == 'posix': if sys.platform == 'linux2': from parallelppdev import * #linux, kernel 2.4 else: from parallelioctl import * #IOCTLs elif os.name == 'java': from paralleljava import * else: raise "Sorry no implementation for your platform available." pyparallel-0.2.orig/parallel/parallelwin32.py0000644000175000017500000001077610176022016021224 0ustar dokodoko00000000000000#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 _pyparallel.init() 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) # 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.orig/parallel/parallelppdev.py0000644000175000017500000005253210172304036021375 0ustar dokodoko00000000000000#!/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 = (1L << _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 = 1L _IOC_READ = -2L _IOC_INOUT = -1L else: _IOC_WRITE = 1L _IOC_READ = 2L _IOC_INOUT = 3L _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 = os.open(self.device, os.O_RDWR) self.PPEXCL() self.PPCLAIM() self.setDataDir(1) self.setData(0) def __del__(self): self.PPRELEASE() if self._fd is not None: 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) #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.orig/src/0000755000175000017500000000000010177656601015171 5ustar dokodoko00000000000000pyparallel-0.2.orig/src/win32/0000755000175000017500000000000010177656601016133 5ustar dokodoko00000000000000pyparallel-0.2.orig/src/win32/_pyparallel.c0000644000175000017500000000373507537172076020620 0ustar dokodoko00000000000000// Parallel port extension for Win32 // "inp" and "outp" are used to access the parallelport hardware // needs giveio.sys driver on NT/2k/XP // // (C) 2002 Chris Liechti // this is distributed under a free software license, see license.txt #include #include #include #define DRIVERNAME "\\\\.\\giveio" /* module-functions */ static PyObject* py_outp(PyObject *self, PyObject *args) { int port, value; if(!PyArg_ParseTuple(args, "ii", &port, &value)) return 0; _outp(port, value); Py_INCREF(Py_None); return Py_None; } static PyObject* py_inp(PyObject *self, PyObject *args) { int port, value; if(!PyArg_ParseTuple(args, "i", &port)) return 0; value = _inp(port); return Py_BuildValue("i", value); } static PyMethodDef pypar_methods[] = { {"outp", py_outp, METH_VARARGS}, {"inp", py_inp, METH_VARARGS}, {0, 0} }; /* module entry-point (module-initialization) function */ void init_pyparallel(void) { OSVERSIONINFO vi; /* Create the module and add the functions */ Py_InitModule("_pyparallel", pypar_methods); //detect OS, on NT,2k,XP the driver needs to be loaded vi.dwOSVersionInfoSize = sizeof(vi); GetVersionEx(&vi); if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) { HANDLE h; //try to open driver h = CreateFile(DRIVERNAME, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (h == INVALID_HANDLE_VALUE) { //if it fails again, then we have a problem... -> exception PyErr_Format(PyExc_ImportError, "Couldn't access giveio device"); } //close again immediately. //the process is now tagged to have the rights it needs, //the giveio driver remembers that if (h != NULL) CloseHandle(h); //close the driver's file } } pyparallel-0.2.orig/src/win32/simpleio.c0000644000175000017500000000256510176020252020112 0ustar dokodoko00000000000000// Parallel port extension for Win32 // "inp" and "outp" are used to access the parallelport hardware // needs giveio.sys driver on NT/2k/XP // // (C) 2005 Chris Liechti // this is distributed under a free software license, see license.txt #include #include #define DRIVERNAME "\\\\.\\giveio" /* module-functions */ WINAPI void outp(int port, int value) { _outp(port, value); } WINAPI int inp(int port) { int value; value = _inp(port); return value; } WINAPI int init(void) { OSVERSIONINFO vi; //detect OS, on NT,2k,XP the driver needs to be loaded vi.dwOSVersionInfoSize = sizeof(vi); GetVersionEx(&vi); if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) { HANDLE h; //try to open driver h = CreateFile(DRIVERNAME, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (h == INVALID_HANDLE_VALUE) { //if it fails again, then we have a problem... -> exception //"Couldn't access giveio device"; return 1; } //close again immediately. //the process is now tagged to have the rights it needs, //the giveio driver remembers that if (h != NULL) CloseHandle(h); //close the driver's file } return 0; } pyparallel-0.2.orig/src/win32/simpleio.dll0000644000175000017500000001300010176024352020432 0ustar dokodoko00000000000000MZ@ !L!This program cannot be run in DOS mode. $PEL(A# 8 _ Pa`p.text``.data  @.rdata,0@@.bss@.edataaP@@.idata`@.relocp@BUWVS } |$]M\$ $uƃ 1t[@tE@ 9rtЋ@9st&$x1҉@$Tu@uF1t&e[^_] t&$T@tl@f&@v'9rtЋ@9st&$1=@$o 1_'U@@ET$L$$]ɃÍU@@EL$T$$-ÐU]UE D$E$X]UE$1]UDžXX$`hu\D$D$D$D$ D$D$$0`¸tt $`]ÐU] U t&  QA uÍ&USt)t'Ku$:[[]Ë 1 @u뽍US @u6 @t%tt&Ku$[[]Ë 1 @uU,0Q,0r]ÐUp@P]Í&'U1$]|$8@@ CPC SC,CP@CC$C(  C0S4$|$]Ðt&UX]p@ut ]u]ÐEAAAA 0uEAAAAEAAAAEء0EAAAAEAAAAEܡ0EAAAAEAAAAE0EAAAA4$E0E 0E$0E(0E]fub$8t\$$`ftp@C`@C@%$x4$v'$ UVSPut&'AuaLHy 0Eء0Eܡ0E0E0E 0E$0E(0EE$d؃fu 1ҍe[^]É$9u獴&'U@ST1ET$UT$$ t0v'|AtHy;8u ؋] %`%`%`%`%`%`%`%`%`%`%`%`%`%`U]\\.\giveio-LIBGCCW32-EH-SJLJ-GTHR-MINGW32(AFP(P4P@PSPXP\Psimpleio.dllinitinpoutp@`a`h`a``````a aa a,a pyparallel-0.2.orig/src/win32/install_giveio.bat0000644000175000017500000000055007540477552021641 0ustar dokodoko00000000000000@set DIRVERNAME=giveio @echo Installing Windows NT/2k/XP driver: %DIRVERNAME% @loaddrv install %DIRVERNAME% @if errorlevel 3 goto error @loaddrv start %DIRVERNAME% @if errorlevel 1 goto error @loaddrv starttype %DIRVERNAME% auto @if errorlevel 1 goto error @goto exit :error @echo ERROR: Installation of %DIRVERNAME% failed :exit @pause pyparallel-0.2.orig/src/win32/remove_giveio.bat0000644000175000017500000000035107536444674021473 0ustar dokodoko00000000000000@set DIRVERNAME=giveio @loaddrv stop %DIRVERNAME% @if errorlevel 2 goto error @loaddrv remove %DIRVERNAME% @if errorlevel 1 goto error @goto exit :error @echo ERROR: Deinstallation of %DIRVERNAME% failed :exit @pause pyparallel-0.2.orig/src/win32/giveio.sys0000644000175000017500000001220006130551206020135 0ustar dokodoko00000000000000MZ@ !L!This program cannot be run in DOS mode. $PEL4c1z 2@ @U3 4T.texth@@ `.rdataT`@@.dataJ ` @.idata@.relocH ` @BU 0VW$}f= th PEЍMPQMQMq_^]t$P5 jjL$33҉AA3U\VWL}f$} h f ui= 3E̍MP5Q֍MEQP֍MUQujjj"RjV|"EMPQ|F8F4@3_^]%%4c1 4c104c10@\DosDevices\giveio\Device\giveio2Jbx2JbxIoDeleteDeviceIoDeleteSymbolicLinkRtlInitUnicodeStringrMmFreeNonCachedMemoryKe386SetIoAccessMapKe386IoSetAccessProcessIoGetCurrentProcessIofCompleteRequestIoCreateSymbolicLinkIoCreateDeviceiMmAllocateNonCachedMemoryntoskrnl.exe4N2[2h2o2}2222222233,3B3i3{33333z @.filegC:\dale\ddj\distrib\giveio\giveio.c.data .text@_.data$&.text .debug$F.text.debug$F.text.debug$F.text .dataL.idata$6.idata$5X.idata$4X.idata$6X.idata$5X.idata$4X.idata$6X.idata$5X.idata$4X.idata$6X.idata$5X.idata$4X.idata$6X.idata$5X.idata$4X.idata$6X.textX.idata$5X.idata$4X.idata$6xX.textX.idata$5X.idata$4X.idata$6bX.idata$5X.idata$4X.idata$6JX.idata$5X.idata$4X.idata$62X.idata$5X.idata$4X.idata$6X.idata$5X.idata$4X.idata$6Xheader@     ^ #$L5j,Hfend_DriverEntry@8_GiveioUnload@4??_C@_1CG@GPLM@?$AA?2?$AAD?$AAo?$AAs?$AAD?$AAe?$AAv?$AAi?$AAc?$AAe?$AAs?$AA?2?$AAg?$AAi?$AAv?$AAe?$AAi?$AAo?$AA?$AA?$AA?$AA@_SetIOPermissionMap@4_GiveIO@0_GiveioCreateDispatch@8??_C@_1BO@MPDE@?$AA?2?$AAD?$AAe?$AAv?$AAi?$AAc?$AAe?$AA?2?$AAg?$AAi?$AAv?$AAe?$AAi?$AAo?$AA?$AA?$AA?$AA?$AA?$AA?$AAo?$AA?$AA?$AA?$AA@_IOPM_local__imp__IoDeleteDevice@4__imp__IoDeleteSymbolicLink@4__imp__RtlInitUnicodeString@8__imp__MmFreeNonCachedMemory@8_Ke386SetIoAccessMap@8_Ke386IoSetAccessProcess@8__imp__IoGetCurrentProcess@0__imp_@IofCompleteRequest@8__imp__IoCreateSymbolicLink@8__imp__IoCreateDevice@28__imp__MmAllocateNonCachedMemory@4_IoDeleteDevice@4ntoskrnl_IMPORT_DESCRIPTOR_IoDeleteSymbolicLink@4_RtlInitUnicodeString@8_MmFreeNonCachedMemory@8__imp__Ke386SetIoAccessMap@8__imp__Ke386IoSetAccessProcess@8_IoGetCurrentProcess@0@IofCompleteRequest@8_IoCreateSymbolicLink@8_IoCreateDevice@28_MmAllocateNonCachedMemory@4NULL_IMPORT_DESCRIPTORntoskrnl_NULL_THUNK_DATA܈.\i386\free\giveio.sys pyparallel-0.2.orig/src/win32/giveio/0000755000175000017500000000000010177656601017415 5ustar dokodoko00000000000000pyparallel-0.2.orig/src/win32/giveio/GIVEIO.C0000644000175000017500000001317206130550762020502 0ustar dokodoko00000000000000/********************************************************************* Author: Dale Roberts Date: 8/30/95 Program: GIVEIO.SYS Compile: Use DDK BUILD facility Purpose: Give direct port I/O access to a user mode process. *********************************************************************/ #include /* * The name of our device driver. */ #define DEVICE_NAME_STRING L"giveio" /* * This is the "structure" of the IOPM. It is just a simple * character array of length 0x2000. * * This holds 8K * 8 bits -> 64K bits of the IOPM, which maps the * entire 64K I/O space of the x86 processor. Any 0 bits will give * access to the corresponding port for user mode processes. Any 1 * bits will disallow I/O access to the corresponding port. */ #define IOPM_SIZE 0x2000 typedef UCHAR IOPM[IOPM_SIZE]; /* * This will hold simply an array of 0's which will be copied * into our actual IOPM in the TSS by Ke386SetIoAccessMap(). * The memory is allocated at driver load time. */ IOPM *IOPM_local = 0; /* * These are the two undocumented calls that we will use to give * the calling process I/O access. * * Ke386IoSetAccessMap() copies the passed map to the TSS. * * Ke386IoSetAccessProcess() adjusts the IOPM offset pointer so that * the newly copied map is actually used. Otherwise, the IOPM offset * points beyond the end of the TSS segment limit, causing any I/O * access by the user mode process to generate an exception. */ void Ke386SetIoAccessMap(int, IOPM *); void Ke386QueryIoAccessMap(int, IOPM *); void Ke386IoSetAccessProcess(PEPROCESS, int); /********************************************************************* Release any allocated objects. *********************************************************************/ VOID GiveioUnload(IN PDRIVER_OBJECT DriverObject) { WCHAR DOSNameBuffer[] = L"\\DosDevices\\" DEVICE_NAME_STRING; UNICODE_STRING uniDOSString; if(IOPM_local) MmFreeNonCachedMemory(IOPM_local, sizeof(IOPM)); RtlInitUnicodeString(&uniDOSString, DOSNameBuffer); IoDeleteSymbolicLink (&uniDOSString); IoDeleteDevice(DriverObject->DeviceObject); } /********************************************************************* Set the IOPM (I/O permission map) of the calling process so that it is given full I/O access. Our IOPM_local[] array is all zeros, so the IOPM will be all zeros. If OnFlag is 1, the process is given I/O access. If it is 0, access is removed. *********************************************************************/ VOID SetIOPermissionMap(int OnFlag) { Ke386IoSetAccessProcess(PsGetCurrentProcess(), OnFlag); Ke386SetIoAccessMap(1, IOPM_local); } void GiveIO(void) { SetIOPermissionMap(1); } /********************************************************************* Service handler for a CreateFile() user mode call. This routine is entered in the driver object function call table by the DriverEntry() routine. When the user mode application calls CreateFile(), this routine gets called while still in the context of the user mode application, but with the CPL (the processor's Current Privelege Level) set to 0. This allows us to do kernel mode operations. GiveIO() is called to give the calling process I/O access. All the user mode application needs do to obtain I/O access is open this device with CreateFile(). No other operations are required. *********************************************************************/ NTSTATUS GiveioCreateDispatch( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { GiveIO(); // give the calling process I/O access Irp->IoStatus.Information = 0; Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT); return STATUS_SUCCESS; } /********************************************************************* Driver Entry routine. This routine is called only once after the driver is initially loaded into memory. It allocates everything necessary for the driver's operation. In our case, it allocates memory for our IOPM array, and creates a device which user mode applications can open. It also creates a symbolic link to the device driver. This allows a user mode application to access our driver using the \\.\giveio notation. *********************************************************************/ NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { PDEVICE_OBJECT deviceObject; NTSTATUS status; WCHAR NameBuffer[] = L"\\Device\\" DEVICE_NAME_STRING; WCHAR DOSNameBuffer[] = L"\\DosDevices\\" DEVICE_NAME_STRING; UNICODE_STRING uniNameString, uniDOSString; // // Allocate a buffer for the local IOPM and zero it. // IOPM_local = MmAllocateNonCachedMemory(sizeof(IOPM)); if(IOPM_local == 0) return STATUS_INSUFFICIENT_RESOURCES; RtlZeroMemory(IOPM_local, sizeof(IOPM)); // // Set up device driver name and device object. // RtlInitUnicodeString(&uniNameString, NameBuffer); RtlInitUnicodeString(&uniDOSString, DOSNameBuffer); status = IoCreateDevice(DriverObject, 0, &uniNameString, FILE_DEVICE_UNKNOWN, 0, FALSE, &deviceObject); if(!NT_SUCCESS(status)) return status; status = IoCreateSymbolicLink (&uniDOSString, &uniNameString); if (!NT_SUCCESS(status)) return status; // // Initialize the Driver Object with driver's entry points. // All we require are the Create and Unload operations. // DriverObject->MajorFunction[IRP_MJ_CREATE] = GiveioCreateDispatch; DriverObject->DriverUnload = GiveioUnload; return STATUS_SUCCESS; } pyparallel-0.2.orig/src/win32/giveio/MAKEFILE0000644000175000017500000000041305632262006020503 0ustar dokodoko00000000000000# # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source # file to this component. This file merely indirects to the real make file # that is shared by all the driver components of the Windows NT DDK # !INCLUDE $(NTMAKEENV)\makefile.def pyparallel-0.2.orig/src/win32/giveio/README.TXT0000644000175000017500000001157407521617472020765 0ustar dokodoko00000000000000The entire archive was pulled from here: Dr. Dobb's Journal, http://www.ddj.com/ftp/1996/1996.05/directio.zip It contained some other snippets too, but as they are not useful here I don't include them here. chris Following is the original readme of the archive: ----------------------------------------------------------------------------- Author: Dale Roberts, Direct I/O and Windows NT Here are two helpful hints to get you going with GIVEIO. The first section below mentions the INSTDRV utility that is provided with the Microsoft DDK. If you do not have access to the DDK, you can use Paula Tomlinson's program LOADDRV instead. She describes it in her May 1995 article in Windows/DOS Developer's Journal (now Windows Developer's Journal). You can get the program from their FTP site at: ftp://ftp.mfi.com/pub/windev/1995/may95.zip. ------------------------------------------------------------------ Device Driver Installation Made Easy The Microsoft NT Device Driver Kit documentation implies in several places that there are several steps involved in installing a device driver and making it accessible to a Win32 application. It explains that you should edit the registry manually and then reboot the system. But device drivers are dynamically loadable and unloadable in NT, and the DDK comes with a very handy utility called INSTDRV that demonstrates this facility in a very practical manner. INSTDRV is a console application that will register, load, and start a kernel mode device driver. It does not require you to edit the registry manually or reboot the computer. On the command line you simply give the name of your device driver and the complete path to the .SYS file (which does not need to be in the system's DRIVERS directory). After this command is executed, you will find that the driver has been registered with the system and appears in the Devices applet in the control panel. If you give the word remove instead of the path, the driver is removed from the system and taken out of the driver database. Once the driver is loaded and started, you can use the control panel's Devices applet to start and stop it, or you can use the net start and net stop commands (these are much faster) from a console window. When a kernel mode device is stopped, it is in also unloaded from memory. The next time you start the device, a fresh copy of the driver is read from the hard drive, if it has been modified. This makes it very convenient to develop device drivers, since you can go through the modify, stop, start cycle repeatedly without ever needing to reboot. If you need your driver to load at boot time, you can go into the Devices applet and change its startup mode to boot. The other component that is needed to make the driver visible to user mode applications, so they can use CreateFile() calls to access the driver, is registering the name in the DOS Devices name space. This can be done, as documented in the DDK, by editing the registry manually and rebooting. Or, much more simply, the kernel mode driver can call the IoCreateSymbolicLink() function to register the name itself. The GIVEIO driver shown in Listing Four uses the later technique. Once the name is registered, user mode applications can get a file handle to the device driver by calling CreateFile() with the driver name as the file parameter, but preceding the driver name with the special cookie \\.\. The TESTIO application in Listing Five uses this technique. ------------------------------------------------------------------ Quick Trick: Using DEBUG With Port I/O Sometimes you just need to do a quick I/O operation to a port. In DOS, you could use the DEBUG program to accomplish this. In NT, once you have the GIVEIO device driver up and running, you can once again use DEBUG for port I/O. If you look at the source code for the test application, you'll see that all it does is open and close the GIVEIO device driver. It uses the special cookie \\.\ before the driver name in order to access it. Without modifying DEBUG, you can have it open this device driver by simply typing debug \\.\giveio in an NT console window. You will get an error message complaining that the file \\.\giveio is not found, but it will give DEBUG I/O access anyway. Subsequent DOS applications that are run from this console window will also have I/O access. WIN32 applications executed from this console window will still cause exceptions. This is because DEBUG (and any other DOS application) runs in the context of the VDM (Virtual DOS Machine) process of the console box, whereas each WIN32 application gets its own process. The VDM process stays active as long as the console window is open, but each WIN32 application creates a brand new process with the IOPM offset initialized to point beyond the end of the TSS. pyparallel-0.2.orig/src/win32/giveio/SOURCES0000644000175000017500000000013706130551072020452 0ustar dokodoko00000000000000TARGETNAME=giveio TARGETPATH=. TARGETTYPE=DRIVER INCLUDES=c:\ddk\inc SOURCES=giveio.c pyparallel-0.2.orig/src/win32/loaddrv_console/0000755000175000017500000000000010177656601021310 5ustar dokodoko00000000000000pyparallel-0.2.orig/src/win32/loaddrv_console/loaddrv.c0000644000175000017500000004122107610756474023116 0ustar dokodoko00000000000000// loaddrv.c - Dynamic driver install/start/stop/remove // based on Paula Tomlinson's LOADDRV program. // She describes it in her May 1995 article in Windows/DOS Developer's // Journal (now Windows Developer's Journal). // i removed the old/ugly dialog, it now accepts command line options and // prints error messages with textual description from the OS. #include #include #include #include #include "loaddrv.h" // globals SC_HANDLE hSCMan = NULL; //get ext messages for windows error codes: void DisplayErrorText(DWORD dwLastError) { LPSTR MessageBuffer; DWORD dwBufferLength; DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM; dwBufferLength = FormatMessageA( dwFormatFlags, NULL, // module to get message from (NULL == system) dwLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language (LPSTR) &MessageBuffer, 0, NULL ); if (dwBufferLength) { // Output message puts(MessageBuffer); // Free the buffer allocated by the system. LocalFree(MessageBuffer); } } int exists(char *filename) { FILE * pFile; pFile = fopen(filename, "r"); return pFile != NULL; } void usage(void) { printf("USGAE: loaddrv command drivername [args...]\n\n" "NT/2k/XP Driver and Service modification tool.\n" "(C)2002 Chris Liechti \n\n" "Suported commands:\n\n" " install [fullpathforinstall]\n" " Install new service. Loaded from given path. If path is not present,\n" " the local directory is searched for a .sys file. If the service\n" " already exists, it must be removed first.\n" " start\n" " Start service. It must be installed in advance.\n" " stop\n" " Stop service.\n" " remove\n" " Remove service. It must be stopped in advance.\n" " status\n" " Show status information about service.\n" " starttype auto|manual|system|disable\n" " Change startup type to the given type.\n" ); } int main(int argc, char *argv[]) { DWORD status = 0; int level = 0; if (argc < 3) { usage(); exit(1); } LoadDriverInit(); if (strcmp(argv[1], "start") == 0) { printf("starting %s... ", argv[2]); status = DriverStart(argv[2]); if ( status != OKAY) { printf("start failed (status %ld):\n", status); level = 1; } else { printf("ok.\n"); } } else if (strcmp(argv[1], "stop") == 0) { printf("stoping %s... ", argv[2]); status = DriverStop(argv[2]); if ( status != OKAY) { printf("stop failed (status %ld):\n", status); level = 1; } else { printf("ok.\n"); } } else if (strcmp(argv[1], "install") == 0) { char path[MAX_PATH*2]; if (argc<4) { char cwd[MAX_PATH]; getcwd(cwd, sizeof cwd); sprintf(path, "%s\\%s.sys", cwd, argv[2]); } else { strncpy(path, argv[3], MAX_PATH); } if (exists(path)) { printf("installing %s from %s... ", argv[2], path); status = DriverInstall(path, argv[2]); if ( status != OKAY) { printf("install failed (status %ld):\n", status); level = 2; } else { printf("ok.\n"); } } else { printf("install failed, file not found: %s\n", path); level = 1; } } else if (strcmp(argv[1], "remove") == 0) { printf("removing %s... ", argv[2]); status = DriverRemove(argv[2]); if ( status != OKAY) { printf("remove failed (status %ld):\n", status); level = 1; } else { printf("ok.\n"); } } else if (strcmp(argv[1], "status") == 0) { printf("status of %s:\n", argv[2]); status = DriverStatus(argv[2]); if ( status != OKAY) { printf("stat failed (status %ld):\n", status); level = 1; } else { printf("ok.\n"); } } else if (strcmp(argv[1], "starttype") == 0) { if (argc < 4) { printf("Error: need start type (string) as argument.\n"); level = 2; } else { DWORD type = 0; printf("set start type of %s to %s... ", argv[2], argv[3]); if (strcmp(argv[1], "boot") == 0) { type = SERVICE_BOOT_START; } else if (strcmp(argv[3], "system") == 0) { type = SERVICE_SYSTEM_START; } else if (strcmp(argv[3], "auto") == 0) { type = SERVICE_AUTO_START; } else if (strcmp(argv[3], "manual") == 0) { type = SERVICE_DEMAND_START; } else if (strcmp(argv[3], "disabled") == 0) { type = SERVICE_DISABLED; } else { printf("unknown type\n"); level = 1; } if (level == 0) { status = DriverStartType(argv[2], type); if ( status != OKAY) { printf("set start type failed (status %ld):\n", status); level = 1; } else { printf("ok.\n"); } } } } else { usage(); level = 1; } if (status) DisplayErrorText(status); LoadDriverCleanup(); exit(level); return 0; } DWORD LoadDriverInit(void) { // connect to local service control manager if ((hSCMan = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL) { return -1; } return OKAY; } void LoadDriverCleanup(void) { if (hSCMan != NULL) CloseServiceHandle(hSCMan); } /**-----------------------------------------------------**/ DWORD DriverInstall(LPSTR lpPath, LPSTR lpDriver) { BOOL dwStatus = OKAY; SC_HANDLE hService = NULL; // add to service control manager's database if ((hService = CreateService(hSCMan, lpDriver, lpDriver, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, lpPath, NULL, NULL, NULL, NULL, NULL)) == NULL) dwStatus = GetLastError(); else CloseServiceHandle(hService); return dwStatus; } // DriverInstall /**-----------------------------------------------------**/ DWORD DriverStart(LPSTR lpDriver) { BOOL dwStatus = OKAY; SC_HANDLE hService = NULL; // get a handle to the service if ((hService = OpenService(hSCMan, lpDriver, SERVICE_ALL_ACCESS)) != NULL) { // start the driver if (!StartService(hService, 0, NULL)) dwStatus = GetLastError(); } else dwStatus = GetLastError(); if (hService != NULL) CloseServiceHandle(hService); return dwStatus; } // DriverStart /**-----------------------------------------------------**/ DWORD DriverStop(LPSTR lpDriver) { BOOL dwStatus = OKAY; SC_HANDLE hService = NULL; SERVICE_STATUS serviceStatus; // get a handle to the service if ((hService = OpenService(hSCMan, lpDriver, SERVICE_ALL_ACCESS)) != NULL) { // stop the driver if (!ControlService(hService, SERVICE_CONTROL_STOP, &serviceStatus)) dwStatus = GetLastError(); } else dwStatus = GetLastError(); if (hService != NULL) CloseServiceHandle(hService); return dwStatus; } // DriverStop /**-----------------------------------------------------**/ DWORD DriverRemove(LPSTR lpDriver) { BOOL dwStatus = OKAY; SC_HANDLE hService = NULL; // get a handle to the service if ((hService = OpenService(hSCMan, lpDriver, SERVICE_ALL_ACCESS)) != NULL) { // remove the driver if (!DeleteService(hService)) dwStatus = GetLastError(); } else dwStatus = GetLastError(); if (hService != NULL) CloseServiceHandle(hService); return dwStatus; } // DriverRemove /**-----------------------------------------------------**/ ////extensions by Lch /**-----------------------------------------------------**/ DWORD DriverStatus(LPSTR lpDriver) { BOOL dwStatus = OKAY; SC_HANDLE hService = NULL; DWORD dwBytesNeeded; // get a handle to the service if ((hService = OpenService(hSCMan, lpDriver, SERVICE_ALL_ACCESS)) != NULL) { LPQUERY_SERVICE_CONFIG lpqscBuf; //~ LPSERVICE_DESCRIPTION lpqscBuf2; // Allocate a buffer for the configuration information. if ((lpqscBuf = (LPQUERY_SERVICE_CONFIG) LocalAlloc( LPTR, 4096)) != NULL) { //~ if ((lpqscBuf2 = (LPSERVICE_DESCRIPTION) LocalAlloc( //~ LPTR, 4096)) != NULL) { // Get the configuration information. if (QueryServiceConfig( hService, lpqscBuf, 4096, &dwBytesNeeded) //&& //~ QueryServiceConfig2( //~ hService, //~ SERVICE_CONFIG_DESCRIPTION, //~ lpqscBuf2, //~ 4096, //~ &dwBytesNeeded ) { // Print the configuration information. printf("Type: [0x%02lx] ", lpqscBuf->dwServiceType); switch (lpqscBuf->dwServiceType) { case SERVICE_WIN32_OWN_PROCESS: printf("The service runs in its own process."); break; case SERVICE_WIN32_SHARE_PROCESS: printf("The service shares a process with other services."); break; case SERVICE_KERNEL_DRIVER: printf("Kernel driver."); break; case SERVICE_FILE_SYSTEM_DRIVER: printf("File system driver."); break; case SERVICE_INTERACTIVE_PROCESS: printf("The service can interact with the desktop."); break; default: printf("Unknown type."); } printf("\nStart Type: [0x%02lx] ", lpqscBuf->dwStartType); switch (lpqscBuf->dwStartType) { case SERVICE_BOOT_START: printf("Boot"); break; case SERVICE_SYSTEM_START: printf("System"); break; case SERVICE_AUTO_START: printf("Automatic"); break; case SERVICE_DEMAND_START: printf("Manual"); break; case SERVICE_DISABLED: printf("Disabled"); break; default: printf("Unknown."); } printf("\nError Control: [0x%02lx] ", lpqscBuf->dwErrorControl); switch (lpqscBuf->dwErrorControl) { case SERVICE_ERROR_IGNORE: printf("IGNORE: Ignore."); break; case SERVICE_ERROR_NORMAL: printf("NORMAL: Display a message box."); break; case SERVICE_ERROR_SEVERE: printf("SEVERE: Restart with last-known-good config."); break; case SERVICE_ERROR_CRITICAL: printf("CRITICAL: Restart w/ last-known-good config."); break; default: printf("Unknown."); } printf("\nBinary path: %s\n", lpqscBuf->lpBinaryPathName); if (lpqscBuf->lpLoadOrderGroup != NULL) printf("Load order grp: %s\n", lpqscBuf->lpLoadOrderGroup); if (lpqscBuf->dwTagId != 0) printf("Tag ID: %ld\n", lpqscBuf->dwTagId); if (lpqscBuf->lpDependencies != NULL) printf("Dependencies: %s\n", lpqscBuf->lpDependencies); if (lpqscBuf->lpServiceStartName != NULL) printf("Start Name: %s\n", lpqscBuf->lpServiceStartName); //~ if (lpqscBuf2->lpDescription != NULL) //~ printf("Description: %s\n", lpqscBuf2->lpDescription); } //~ LocalFree(lpqscBuf2); } LocalFree(lpqscBuf); } else { dwStatus = GetLastError(); } } else { dwStatus = GetLastError(); } if (hService != NULL) CloseServiceHandle(hService); return dwStatus; } // DriverStatus /**-----------------------------------------------------**/ DWORD DriverStartType(LPSTR lpDriver, DWORD dwStartType) { BOOL dwStatus = OKAY; SC_HANDLE hService = NULL; SC_LOCK sclLock; LPQUERY_SERVICE_LOCK_STATUS lpqslsBuf; DWORD dwBytesNeeded; // Need to acquire database lock before reconfiguring. sclLock = LockServiceDatabase(hSCMan); // If the database cannot be locked, report the details. if (sclLock == NULL) { // Exit if the database is not locked by another process. if (GetLastError() == ERROR_SERVICE_DATABASE_LOCKED) { // Allocate a buffer to get details about the lock. lpqslsBuf = (LPQUERY_SERVICE_LOCK_STATUS) LocalAlloc( LPTR, sizeof(QUERY_SERVICE_LOCK_STATUS)+256); if (lpqslsBuf != NULL) { // Get and print the lock status information. if (QueryServiceLockStatus( hSCMan, lpqslsBuf, sizeof(QUERY_SERVICE_LOCK_STATUS)+256, &dwBytesNeeded) ) { if (lpqslsBuf->fIsLocked) { printf("Locked by: %s, duration: %ld seconds\n", lpqslsBuf->lpLockOwner, lpqslsBuf->dwLockDuration ); } else { printf("No longer locked\n"); } } LocalFree(lpqslsBuf); } } dwStatus = GetLastError(); } else { // The database is locked, so it is safe to make changes. // Open a handle to the service. hService = OpenService( hSCMan, // SCManager database lpDriver, // name of service SERVICE_CHANGE_CONFIG ); // need CHANGE access if (hService != NULL) { // Make the changes. if (!ChangeServiceConfig( hService, // handle of service SERVICE_NO_CHANGE, // service type: no change dwStartType, // change service start type SERVICE_NO_CHANGE, // error control: no change NULL, // binary path: no change NULL, // load order group: no change NULL, // tag ID: no change NULL, // dependencies: no change NULL, // account name: no change NULL, // password: no change NULL) ) // display name: no change { dwStatus = GetLastError(); } } // Release the database lock. UnlockServiceDatabase(sclLock); } if (hService != NULL) CloseServiceHandle(hService); return dwStatus; } // DriverStartType pyparallel-0.2.orig/src/win32/loaddrv_console/loaddrv.h0000644000175000017500000000063407540475676023132 0ustar dokodoko00000000000000#ifndef LOADDRV_H #define LOADDRV_H #include #define OKAY 0 #define UNEXPECTED_ERROR 9999 //prototypes DWORD LoadDriverInit(void); void LoadDriverCleanup(void); DWORD DriverInstall(LPSTR, LPSTR); DWORD DriverStart(LPSTR); DWORD DriverStop(LPSTR); DWORD DriverRemove(LPSTR); DWORD DriverStatus(LPSTR); DWORD DriverStartType(LPSTR, DWORD); #endif //LOADDRV_Hpyparallel-0.2.orig/src/win32/loaddrv_console/makefile0000644000175000017500000000015207526277150023010 0ustar dokodoko00000000000000COPT = -O2 -Wall -g -mno-cygwin loaddrv.exe: loaddrv.c loaddrv.h gcc ${COPT} $< -o $@ strip $@