DB25 connector pinouts.

Additional Commands Python Py-Parallel Programming

by Lewis Loflin

Documentation lists only 8 commands (below) that are limited. I went into the file parallelppdev.py and found several additional commands to read the status of the four output pins and commands to turn the data port on/off, and read the data port latches. They were commented out, I commented them back in and are now available.

The documentation talks about some additional software I can't find to allow one to access the individual data port bits instead of writing just a byte at a time. The extra commands made it easy to add that feature in my programs. Being able to read the state of the data port made this easy to control individual devices attached to it.

The bit operations in pportbits.py can be imported or simply copy-paste to a new program.

Note: "Level" is "1" or "0".

setData(value)
"""Apply the given byte to the data pins of the parallel port. Pins 2-9"""

# write the 4 output (control) pins

setDataStrobe(level) # Set the "data strobe" line to the given state. Pin 1

setAutoFeed(level) # Set "auto feed" line to given state. Pin 14

setInitOut(level) # Set "initialize" line to given state. Pin (16) reset

setSelect(level) # Sets the state of the SelectIn output (pin 17)

# read the 5 input (status) pins

getInError() # Returns the level on the nFault pin (15)

getInSelected() # Read level of "select" line. pin (13)

getInPaperOut() # Read level of "paper out" line. Pin (12)

getInBusy() # Returns the level on the Busy pin (11)

getInAcknowledge() # Read level of "Acknowledge" line. Pin (10)

#################################################################

# below was commented back in on the parallelppdev.py file:

# read the level on 4 output (control) pins and return the state of the pin:

strobe()
"""Returns the state of the nStrobe output (pin 1)"""

autoFd()
"""Returns the state of the nAutoFd output (pin 14)"""

init() """Returns the state of the nInit output (pin 16)"""

selectIn()
"""Returns the state of the nSelectIn output (pin 17)"""

# use with data port

data()
"""Returns value of the data bus line drivers (pins 2-9)"""

setDataDir(level)
"""1 Activates or 0 deactivates the data bus line drivers (pins 2-9)"""

dataDir()
"""Returns true if the data bus line drivers are on (pins 2-9)"""

For working examples of below see Controlling Data Bits on the PC Parallel Port

The program is written in Python and runs under Linux. To use this one must setup a module pyparallel. How to set this up is on my webpage Programming the PC Printer Port in Python


#!/usr/bin/env python
# File pportbits.py
# http://www.bristolwatch.com/pport/index.htm
# By Lewis Loflin - lewis@bvu.net
# Example code to turn ON-OFF individual bits on PC 
# printer port Db25 pins 2-9.
# Must use my version of pyparallel on website for p.data().
# Bitwise AND is used to clear a bit while bitwise OR used to set bit.

import parallel
p = parallel.Parallel()

def writeD0(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 1) # set bit 0
    else: # clear bit 0
        p.setData(p.data() & (255 - 1))
    return

def writeD1(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 2) #set bit 1
    else: # clear bit 1
        p.setData(p.data() & (255 - 2))
    return

def writeD2(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 4) #set bit 2
    else: # clear bit 2
        p.setData(p.data() & (255 - 4))
    return

def writeD3(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 8) #set bit 3
    else: # clear bit 3
        p.setData(p.data() & (255 - 8))
    return

def writeD4(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 16) #set bit 4
    else: # clear bit 4
        p.setData(p.data() & (255 - 16))
    return

def writeD5(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 32) #set bit 5
    else: # clear bit 5
        p.setData(p.data() & (255 - 32))
    return

def writeD6(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 64) #set bit 6
    else: # clear bit 6
        p.setData(p.data() & (255 - 64))
    return

def writeD7(bit_val):
    if bit_val == 1:
        p.setData(p.data() | 128) #set bit 7
    else: # clear bit 7
        p.setData(p.data() & (255 - 128))
    return

exit 


Download pport-1.0.iso from Sourceforge.com then burn to DVD (file size 920 meg.), insert into DVD drive and reboot. Make sure PC is set to boot from DVD ROM.

This is pre-configured by myself to use Python to control the printer port. Python can be run from IDLE or Geany.

All of my PPORT electronics projects will work without installation to a PC.

Programs can be saved to thumb drive in LIVE mode.

Projects

Below are listed a series of projects using pyparallel and electronics. Starting with routines I wrote to aid students I'd advise walking through this in sequence. Have fun and send comments and/or corrections to lewis@bvu.net.

Linux Videos

Printer Port in C


Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.