By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

pyparallel and MAKE controller board for CRYDOM AC/DC switches

P: n/a
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!!
Oct 11 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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-----

Oct 11 '05 #2

P: n/a

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

Oct 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.