pyparallel and MAKE controller board for CRYDOM AC/DC switches

R

Richard Siderits

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!!
 
J

jepler

Recalling the parallel pinout, pin 3 is data bit 2. Have you tried
def BIT(x): return 1<<x
p.setData(BIT(2))
?


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDSxgTJd01MZaTXX0RArpjAJ44vuU/eHMH24514JMWg5iDsAxeXwCcC3qf
N2s6xRrC5SUmnvyaqF0t9U8=
=a5SZ
-----END PGP SIGNATURE-----
 
G

garyr

Richard said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top