Richard Siderits wrote:
Greetings. I am trying to write a small application for controlling CRYDOM
AC and DC switches from the parallel port using pyparallel. The project is
described in the latest issue of MAKE magazine Vol.3 pg 86. All of the
examples are in C, VB, Linux, Unix but not a thing in Python. Seems like a
perfect application for a Python program or even a simple windowed app.
Problem is I'm stuck. How, for example, would I format the setData() to
turn off data PIN 3? If I knew that then.. Life, the Universe and
Everything would be better.
Progress so far:
import parallel, time, ctypes
p=parallel.Parallel(1)
p.setData(0)
p.setDataStrobe(0)
print "Boy are you stuck!"
THANKS for any help!!
Here is some code that may do what you want:
from parallel import *
class P:
def __init__(self, port):
self.dataReg = 0
self.p = Parallel(port)
def setData(self, value):
self.dataReg = value
self.p.setData(value)
def setDataBit(self, bit, value):
assert 0 <= bit <= 7
assert 0 <= value <= 1
mask = 1 << bit
self.dataReg = (self.dataReg & ~mask)
if value:
self.dataReg += mask
self.p.setData(self.dataReg)
if __name__ == '__main__':
import msvcrt, time
bit = 1
pyp = P(LPT1)
pyp.setData(0xff) # set all bits high
print 'all bits high'
while not msvcrt.kbhit():
time.sleep(0.1)
ch = msvcrt.getch()
while 1:
pyp.setDataBit(bit, 0) # set bit <bit> low
print 'bit %d low' % (bit, )
while not msvcrt.kbhit():
time.sleep(0.1)
ch = msvcrt.getch()
if ord(ch) == 27: # esc
break
pyp.setDataBit(bit, 1) # now high
print 'bit %d high' % (bit, )
while not msvcrt.kbhit():
time.sleep(0.1)
ch = msvcrt.getch()
if ord(ch) == 27: # esc
break