Summary:
Here you can find a python module for easier access of the Velleman relay card k8056. The class should work under any OS with a working PySerial package. It was tested under SuSE 9.3, SuSE 10.2, Debian Etch and WindowsXP (32bit). It depends on the PySerial package, for Windows you also need the win32all package.
Licence: GNU GPL
Installation: Just place the file relaycard.py in your python search path.
Usage example:
>>> import relaycard >>> card = relaycard.RelayCard(0) # initialize card on serial port 0 >>> card.set(1) # set relay number 1 >>> card.clear(1) # clear relay number 1 >>> card.close() # close connection to the card
Methods:
>>> from relaycard import RelayCard
>>> print RelayCard.__doc__
RelayCard - Class for controlling the velleman K8056
8 channel relay card via serial port
RelayCard(port, instr_repeat, wait)
: constructor, give serial port as number
or device file (default 0); for better
reliability repeat instructions n-times
(default 0) and wait between execution
(default 0)
Methods are:
close() : important for detaching serial port
set(relay, address) : set <relay> 1..8 (9 for all relays) on the
card with <address> (default 1)
clear(relay, address) : clear <relay> on card <address>
toggle(relay, address) : toggle <relay> on card <address>
setAddress(old, new) : 1..255 (default 1)
forceAddress() : reset all cards to address 1
getAddress() : displays all card addresses on the LEDs
in binary fashion
sendByte(0..255, address) : set relays direct in binary mode
eStop() : clear all relays on all cards, emergency
purpose
Download: relaycard.zip
The zip file comes with a more advanced example you can find in example_qt. The GUI design was inspired by the windows example picture I found in the manual with some additional features. It uses PyQT 3.x, since there is no opensource version of PyQT 3.x for windows, it won't be usable there. Just run "python run.py" in the example_qt directory to execute it.
Qt 4 example:
A more recent version of the example is written with Qt 4 and also available for Windows. The executables (standalone and installer) are built with PyInstaller under WindowsXP (32bit) and do not need Python/Qt/PyQt installed.
Autor: Joerg Breitbart - brejoe at web.de