diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-02-18 17:39:44 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-02-18 17:39:44 +0100 |
commit | 9bfdbb1d569eea229fd9f10823891234c8676145 (patch) | |
tree | d12cc47a398d1c3684fc3a6709a55f959d085527 /pyk8055 | |
download | k8055-9bfdbb1d569eea229fd9f10823891234c8676145.zip k8055-9bfdbb1d569eea229fd9f10823891234c8676145.tar.gz |
initial commit, version 0.4.1 from http://sourceforge.net/projects/libk8055
Diffstat (limited to 'pyk8055')
-rw-r--r-- | pyk8055/Makefile | 37 | ||||
-rw-r--r-- | pyk8055/frmk8055qt.ui | 1422 | ||||
-rw-r--r-- | pyk8055/frmk8055qt.ui.h | 260 | ||||
-rwxr-xr-x | pyk8055/k8055.py | 117 | ||||
-rw-r--r-- | pyk8055/k8055qt.png | bin | 0 -> 33894 bytes | |||
-rw-r--r-- | pyk8055/k8055qt.py | 232 | ||||
-rwxr-xr-x | pyk8055/k8055test.py | 70 | ||||
-rw-r--r-- | pyk8055/k8055testm.py | 98 | ||||
-rw-r--r-- | pyk8055/libk8055.i | 352 | ||||
-rwxr-xr-x | pyk8055/pyplotA.py | 88 | ||||
-rw-r--r-- | pyk8055/pyplotA_1.png | bin | 0 -> 21901 bytes | |||
-rwxr-xr-x | pyk8055/pyplotD.py | 113 | ||||
-rw-r--r-- | pyk8055/pyplotD_2.png | bin | 0 -> 20543 bytes | |||
-rw-r--r-- | pyk8055/setup.py | 31 |
14 files changed, 2820 insertions, 0 deletions
diff --git a/pyk8055/Makefile b/pyk8055/Makefile new file mode 100644 index 0000000..a2069d3 --- /dev/null +++ b/pyk8055/Makefile @@ -0,0 +1,37 @@ +# $Id: Makefile,v 1.3 2007/04/08 10:54:49 pjetur Exp $ +# +#cc = gcc +#pylibdir = pyk8055 +#libs = -lusb -L/usr/lib -lm + +# We have to build extension "inplace" if We're to +# run samples locally without installing + +all: libk8055.i ../libk8055.c + python setup.py build_ext --inplace + python setup.py build + +# Or in plain language +# swig -python libk8055.i +# cc -fpic -O2 -c ../libk8055.c -o ./libk8055.o +# cc -fpic -O2 -c libk8055_wrap.c -I /usr/include/python2.4/ -o libk8055_wrap.o +# ld -shared libk8055.o libk8055_wrap.o -lusb -o _pyk8055.so +## mv -f pyk8055.py __init__.py + +.PHONY: kdemo + +kdemo: k8055qt.py frmk8055qt.ui frmk8055qt.ui.h + pyuic frmk8055qt.ui -o frmk8055qt.py + +# install will both make build and install +install: + python setup.py install + +# Remove all swig generated files +clean: + python setup.py clean --all + rm -f *.o _pyk8055.so libk8055_wrap.c pyk8055.py pyk8055.pyc + +uninstall: + python setup.py uninstall + #rm -f /usr/lib/python-2.4/site-packages/pyk8055.py /usr/lib/python-2.4/site-packages/_pyk8055.so diff --git a/pyk8055/frmk8055qt.ui b/pyk8055/frmk8055qt.ui new file mode 100644 index 0000000..2669c01 --- /dev/null +++ b/pyk8055/frmk8055qt.ui @@ -0,0 +1,1422 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>K8055QT</class> +<comment>Python:#from kdecore import * +Python:from kdeui import * +Python:from pyk8055 import * +</comment> +<widget class="QDialog"> + <property name="name"> + <cstring>K8055QT</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>314</height> + </rect> + </property> + <property name="caption"> + <string>K8055 Status</string> + </property> + <widget class="QButtonGroup"> + <property name="name"> + <cstring>OutputGroup</cstring> + </property> + <property name="geometry"> + <rect> + <x>320</x> + <y>70</y> + <width>270</width> + <height>51</height> + </rect> + </property> + <property name="title"> + <string>Digital Output</string> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>OutputBox5</cstring> + </property> + <property name="geometry"> + <rect> + <x>140</x> + <y>20</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>5</string> + </property> + <property name="toolTip" stdset="0"> + <string>Digital Output 5</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>OutputBox6</cstring> + </property> + <property name="geometry"> + <rect> + <x>169</x> + <y>20</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>6</string> + </property> + <property name="toolTip" stdset="0"> + <string>Digital Output 6</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>OutputBox7</cstring> + </property> + <property name="geometry"> + <rect> + <x>199</x> + <y>20</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>7</string> + </property> + <property name="toolTip" stdset="0"> + <string>Digital Output 7</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>OutputBox8</cstring> + </property> + <property name="geometry"> + <rect> + <x>229</x> + <y>20</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>8</string> + </property> + <property name="toolTip" stdset="0"> + <string>Digital Output 8</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>OutputBox1</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>20</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>1</string> + </property> + <property name="toolTip" stdset="0"> + <string>Digital Output 1</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>OutputBox2</cstring> + </property> + <property name="geometry"> + <rect> + <x>42</x> + <y>20</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>2</string> + </property> + <property name="toolTip" stdset="0"> + <string>Digital Output 2</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>OutputBox3</cstring> + </property> + <property name="geometry"> + <rect> + <x>76</x> + <y>20</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>3</string> + </property> + <property name="toolTip" stdset="0"> + <string>Digital Output 3</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>OutputBox4</cstring> + </property> + <property name="geometry"> + <rect> + <x>110</x> + <y>20</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>4</string> + </property> + <property name="toolTip" stdset="0"> + <string>Digital Output 4</string> + </property> + </widget> + </widget> + <widget class="QButtonGroup"> + <property name="name"> + <cstring>InputGroup</cstring> + </property> + <property name="geometry"> + <rect> + <x>320</x> + <y>130</y> + <width>270</width> + <height>70</height> + </rect> + </property> + <property name="title"> + <string>Digital Input</string> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>DigitaltextLabel1</cstring> + </property> + <property name="geometry"> + <rect> + <x>18</x> + <y>40</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>1</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>DigitaltextLabel4</cstring> + </property> + <property name="geometry"> + <rect> + <x>170</x> + <y>40</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>4</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>DigitaltextLabel5</cstring> + </property> + <property name="geometry"> + <rect> + <x>220</x> + <y>40</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>5</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>DigitaltextLabel2</cstring> + </property> + <property name="geometry"> + <rect> + <x>69</x> + <y>40</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>2</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>DigitaltextLabel3</cstring> + </property> + <property name="geometry"> + <rect> + <x>120</x> + <y>40</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>3</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="KLed"> + <property name="name"> + <cstring>DigitalLed1</cstring> + </property> + <property name="geometry"> + <rect> + <x>20</x> + <y>20</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="state"> + <enum>Off</enum> + </property> + <property name="color"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="toolTip" stdset="0"> + <string>Digital 1 input state</string> + </property> + </widget> + <widget class="KLed"> + <property name="name"> + <cstring>DigitalLed2</cstring> + </property> + <property name="geometry"> + <rect> + <x>70</x> + <y>20</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="state"> + <enum>Off</enum> + </property> + <property name="color"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="toolTip" stdset="0"> + <string>Digital 2 input state</string> + </property> + </widget> + <widget class="KLed"> + <property name="name"> + <cstring>DigitalLed3</cstring> + </property> + <property name="geometry"> + <rect> + <x>121</x> + <y>20</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="state"> + <enum>Off</enum> + </property> + <property name="color"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="toolTip" stdset="0"> + <string>Digital 3 input state</string> + </property> + </widget> + <widget class="KLed"> + <property name="name"> + <cstring>DigitalLed4</cstring> + </property> + <property name="geometry"> + <rect> + <x>173</x> + <y>20</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="state"> + <enum>Off</enum> + </property> + <property name="color"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="toolTip" stdset="0"> + <string>Digital 4 input state</string> + </property> + </widget> + <widget class="KLed"> + <property name="name"> + <cstring>DigitalLed5</cstring> + </property> + <property name="geometry"> + <rect> + <x>221</x> + <y>20</y> + <width>20</width> + <height>20</height> + </rect> + </property> + <property name="state"> + <enum>Off</enum> + </property> + <property name="color"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="toolTip" stdset="0"> + <string>Digital 5 input state</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupCounter1</cstring> + </property> + <property name="geometry"> + <rect> + <x>320</x> + <y>200</y> + <width>271</width> + <height>51</height> + </rect> + </property> + <property name="title"> + <string>Counter 1</string> + </property> + <widget class="QComboBox"> + <item> + <property name="text"> + <string>1 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>2 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>5 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>10 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>50 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>100 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>500 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>1000 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>2000 ms</string> + </property> + </item> + <property name="name"> + <cstring>comboCounter1</cstring> + </property> + <property name="geometry"> + <rect> + <x>171</x> + <y>20</y> + <width>90</width> + <height>21</height> + </rect> + </property> + <property name="toolTip" stdset="0"> + <string>Debounce value counter #1</string> + </property> + </widget> + <widget class="QLCDNumber"> + <property name="name"> + <cstring>Counter1Value</cstring> + </property> + <property name="geometry"> + <rect> + <x>20</x> + <y>20</y> + <width>71</width> + <height>21</height> + </rect> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="segmentStyle"> + <enum>Flat</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Counter #1</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>ClearCounter1</cstring> + </property> + <property name="geometry"> + <rect> + <x>100</x> + <y>20</y> + <width>60</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>Reset</string> + </property> + <property name="toolTip" stdset="0"> + <string>Reset Counter #1</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupCounter2</cstring> + </property> + <property name="geometry"> + <rect> + <x>320</x> + <y>250</y> + <width>271</width> + <height>51</height> + </rect> + </property> + <property name="title"> + <string>Counter 2</string> + </property> + <widget class="QComboBox"> + <item> + <property name="text"> + <string>1 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>2 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>5 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>10 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>50 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>100 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>500 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>1000 ms</string> + </property> + </item> + <item> + <property name="text"> + <string>2000 ms</string> + </property> + </item> + <property name="name"> + <cstring>comboCounter2</cstring> + </property> + <property name="geometry"> + <rect> + <x>171</x> + <y>20</y> + <width>90</width> + <height>21</height> + </rect> + </property> + <property name="toolTip" stdset="0"> + <string>Debounce value counter #2</string> + </property> + </widget> + <widget class="QLCDNumber"> + <property name="name"> + <cstring>Counter2Value</cstring> + </property> + <property name="geometry"> + <rect> + <x>20</x> + <y>20</y> + <width>71</width> + <height>21</height> + </rect> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="segmentStyle"> + <enum>Flat</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Counter #2</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>ClearCounter2</cstring> + </property> + <property name="geometry"> + <rect> + <x>100</x> + <y>20</y> + <width>60</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>Reset</string> + </property> + <property name="toolTip" stdset="0"> + <string>Reset Counter #2</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupDigitalButtonBox</cstring> + </property> + <property name="geometry"> + <rect> + <x>200</x> + <y>10</y> + <width>110</width> + <height>90</height> + </rect> + </property> + <property name="title"> + <string>Digital</string> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>ClearAllDigitalButton</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>50</y> + <width>90</width> + <height>30</height> + </rect> + </property> + <property name="text"> + <string>Clear All</string> + </property> + <property name="toolTip" stdset="0"> + <string>Clear all digital outputs</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>SetAllDigitalButton</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>20</y> + <width>90</width> + <height>30</height> + </rect> + </property> + <property name="text"> + <string>Set All</string> + </property> + <property name="toolTip" stdset="0"> + <string>Set all digital outputs</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupAnalogButtonBox</cstring> + </property> + <property name="geometry"> + <rect> + <x>200</x> + <y>110</y> + <width>110</width> + <height>90</height> + </rect> + </property> + <property name="title"> + <string>Analog</string> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>ClearAllAnalogButton</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>50</y> + <width>90</width> + <height>30</height> + </rect> + </property> + <property name="text"> + <string>Clear All</string> + </property> + <property name="toolTip" stdset="0"> + <string>Set all analog outputs low</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>SetAllAnalogButton</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>20</y> + <width>90</width> + <height>30</height> + </rect> + </property> + <property name="text"> + <string>Set All</string> + </property> + <property name="toolTip" stdset="0"> + <string>Set all analog outputs high</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupTestButtonBox</cstring> + </property> + <property name="geometry"> + <rect> + <x>200</x> + <y>210</y> + <width>110</width> + <height>90</height> + </rect> + </property> + <property name="title"> + <string>Test</string> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>TestAnalogButton</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>50</y> + <width>90</width> + <height>30</height> + </rect> + </property> + <property name="text"> + <string>Analog</string> + </property> + <property name="toolTip" stdset="0"> + <string>Run analog tests</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>TestDigitalButton</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>20</y> + <width>90</width> + <height>30</height> + </rect> + </property> + <property name="text"> + <string>Digital</string> + </property> + <property name="toolTip" stdset="0"> + <string>Run digital output tests</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBoxAD2</cstring> + </property> + <property name="geometry"> + <rect> + <x>140</x> + <y>10</y> + <width>45</width> + <height>290</height> + </rect> + </property> + <property name="title"> + <string>AD2</string> + </property> + <widget class="QScrollBar"> + <property name="name"> + <cstring>BarAD2</cstring> + </property> + <property name="geometry"> + <rect> + <x>16</x> + <y>20</y> + <width>20</width> + <height>230</height> + </rect> + </property> + <property name="maxValue"> + <number>255</number> + </property> + <property name="pageStep"> + <number>1</number> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Analog input value - AD2</string> + </property> + </widget> + <widget class="QLCDNumber"> + <property name="name"> + <cstring>AD2Value</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>260</y> + <width>30</width> + <height>20</height> + </rect> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="numDigits"> + <number>3</number> + </property> + <property name="segmentStyle"> + <enum>Flat</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Analog value AD2</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBoxAD1</cstring> + </property> + <property name="geometry"> + <rect> + <x>100</x> + <y>10</y> + <width>45</width> + <height>290</height> + </rect> + </property> + <property name="title"> + <string>AD1</string> + </property> + <widget class="QLCDNumber"> + <property name="name"> + <cstring>AD1Value</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>260</y> + <width>30</width> + <height>20</height> + </rect> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="numDigits"> + <number>3</number> + </property> + <property name="segmentStyle"> + <enum>Flat</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Analog value AD1</string> + </property> + </widget> + <widget class="QScrollBar"> + <property name="name"> + <cstring>BarAD1</cstring> + </property> + <property name="geometry"> + <rect> + <x>15</x> + <y>20</y> + <width>20</width> + <height>230</height> + </rect> + </property> + <property name="maxValue"> + <number>255</number> + </property> + <property name="pageStep"> + <number>1</number> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Analog input value - AD1</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBoxDA2</cstring> + </property> + <property name="geometry"> + <rect> + <x>55</x> + <y>10</y> + <width>45</width> + <height>290</height> + </rect> + </property> + <property name="title"> + <string>DA2</string> + </property> + <widget class="QLCDNumber"> + <property name="name"> + <cstring>DA2Value</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>260</y> + <width>30</width> + <height>20</height> + </rect> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="numDigits"> + <number>3</number> + </property> + <property name="segmentStyle"> + <enum>Flat</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Analog value DA2</string> + </property> + </widget> + <widget class="QScrollBar"> + <property name="name"> + <cstring>BarDA2</cstring> + </property> + <property name="geometry"> + <rect> + <x>15</x> + <y>20</y> + <width>20</width> + <height>230</height> + </rect> + </property> + <property name="maxValue"> + <number>255</number> + </property> + <property name="pageStep"> + <number>1</number> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Analog output value - DA2</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBoxDA1</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>45</width> + <height>290</height> + </rect> + </property> + <property name="title"> + <string>DA1</string> + </property> + <widget class="QLCDNumber"> + <property name="name"> + <cstring>DA1Value</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>260</y> + <width>30</width> + <height>20</height> + </rect> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="numDigits"> + <number>3</number> + </property> + <property name="segmentStyle"> + <enum>Flat</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Analog value DA1</string> + </property> + </widget> + <widget class="QScrollBar"> + <property name="name"> + <cstring>BarDA1</cstring> + </property> + <property name="geometry"> + <rect> + <x>15</x> + <y>20</y> + <width>20</width> + <height>230</height> + </rect> + </property> + <property name="maxValue"> + <number>255</number> + </property> + <property name="pageStep"> + <number>1</number> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Analog output value - DA1</string> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupCard</cstring> + </property> + <property name="geometry"> + <rect> + <x>320</x> + <y>10</y> + <width>271</width> + <height>51</height> + </rect> + </property> + <property name="title"> + <string>Card</string> + </property> + <widget class="QButtonGroup"> + <property name="name"> + <cstring>CardRadioGroup</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>19</y> + <width>151</width> + <height>20</height> + </rect> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="title"> + <string></string> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>CardButton1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>1</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="toolTip" stdset="0"> + <string>Select Card #1</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>CardButton3</cstring> + </property> + <property name="geometry"> + <rect> + <x>80</x> + <y>0</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>3</string> + </property> + <property name="toolTip" stdset="0"> + <string>Select Card #3</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>CardButton2</cstring> + </property> + <property name="geometry"> + <rect> + <x>40</x> + <y>0</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>2</string> + </property> + <property name="toolTip" stdset="0"> + <string>Select Card #2</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>CardButton4</cstring> + </property> + <property name="geometry"> + <rect> + <x>120</x> + <y>0</y> + <width>30</width> + <height>21</height> + </rect> + </property> + <property name="text"> + <string>4</string> + </property> + <property name="toolTip" stdset="0"> + <string>Select Card #4</string> + </property> + </widget> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>ConnectButton</cstring> + </property> + <property name="geometry"> + <rect> + <x>179</x> + <y>15</y> + <width>80</width> + <height>30</height> + </rect> + </property> + <property name="text"> + <string>Connect</string> + </property> + <property name="toolTip" stdset="0"> + <string>Connect to selected card</string> + </property> + </widget> + </widget> +</widget> +<connections> + <connection> + <sender>ConnectButton</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>ConnectButton_clicked()</slot> + </connection> + <connection> + <sender>CardButton1</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>CardButton1_clicked()</slot> + </connection> + <connection> + <sender>CardButton2</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>CardButton2_clicked()</slot> + </connection> + <connection> + <sender>ClearCounter2</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>ClearCounter2_clicked()</slot> + </connection> + <connection> + <sender>OutputBox1</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>OutputBox1_clicked()</slot> + </connection> + <connection> + <sender>ClearCounter1</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>ClearCounter1_clicked()</slot> + </connection> + <connection> + <sender>OutputBox8</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>OutputBox8_clicked()</slot> + </connection> + <connection> + <sender>OutputBox7</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>OutputBox7_clicked()</slot> + </connection> + <connection> + <sender>OutputBox2</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>OutputBox2_clicked()</slot> + </connection> + <connection> + <sender>OutputBox3</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>OutputBox3_clicked()</slot> + </connection> + <connection> + <sender>OutputBox4</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>OutputBox4_clicked()</slot> + </connection> + <connection> + <sender>OutputBox5</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>OutputBox5_clicked()</slot> + </connection> + <connection> + <sender>OutputBox6</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>OutputBox6_clicked()</slot> + </connection> + <connection> + <sender>SetAllAnalogButton</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>SetAllAnalogButton_clicked()</slot> + </connection> + <connection> + <sender>ClearAllAnalogButton</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>ClearAllAnalogButton_clicked()</slot> + </connection> + <connection> + <sender>SetAllDigitalButton</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>SetAllDigitalButton_clicked()</slot> + </connection> + <connection> + <sender>ClearAllDigitalButton</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>ClearAllDigitalButton_clicked()</slot> + </connection> + <connection> + <sender>BarAD2</sender> + <signal>valueChanged(int)</signal> + <receiver>K8055QT</receiver> + <slot>BarAD2_valueChanged(int)</slot> + </connection> + <connection> + <sender>BarAD1</sender> + <signal>valueChanged(int)</signal> + <receiver>K8055QT</receiver> + <slot>BarAD1_valueChanged(int)</slot> + </connection> + <connection> + <sender>comboCounter2</sender> + <signal>activated(int)</signal> + <receiver>K8055QT</receiver> + <slot>comboCounter2_activated(int)</slot> + </connection> + <connection> + <sender>comboCounter1</sender> + <signal>activated(int)</signal> + <receiver>K8055QT</receiver> + <slot>comboCounter1_activated(int)</slot> + </connection> + <connection> + <sender>TestDigitalButton</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>TestDigitalButton_clicked()</slot> + </connection> + <connection> + <sender>TestAnalogButton</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>TestAnalogButton_clicked()</slot> + </connection> + <connection> + <sender>CardButton3</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>CardButton3_clicked()</slot> + </connection> + <connection> + <sender>CardButton4</sender> + <signal>clicked()</signal> + <receiver>K8055QT</receiver> + <slot>CardButton4_clicked()</slot> + </connection> +</connections> +<includes> + <include location="local" impldecl="in implementation">frmk8055qt.ui.h</include> +</includes> +<variables> + <variable access="private">Kpriv;</variable> + <variable access="public">Kp = False;</variable> +</variables> +<slots> + <slot>ConnectButton_clicked()</slot> + <slot>CardButton1_clicked()</slot> + <slot>CardButton2_clicked()</slot> + <slot>CardButton3_clicked()</slot> + <slot>CardButton4_clicked()</slot> + <slot>init()</slot> + <slot>ClearCounter1_clicked()</slot> + <slot>ClearCounter2_clicked()</slot> + <slot>OutputBox1_clicked()</slot> + <slot>OutputBox2_clicked()</slot> + <slot>OutputBox3_clicked()</slot> + <slot>OutputBox4_clicked()</slot> + <slot>OutputBox5_clicked()</slot> + <slot>OutputBox6_clicked()</slot> + <slot>OutputBox7_clicked()</slot> + <slot>OutputBox8_clicked()</slot> + <slot>SetAllAnalogButton_clicked()</slot> + <slot>ClearAllAnalogButton_clicked()</slot> + <slot>SetAllDigitalButton_clicked()</slot> + <slot>ClearAllDigitalButton_clicked()</slot> + <slot>BarAD1_valueChanged( int )</slot> + <slot>BarAD2_valueChanged( int )</slot> + <slot>comboCounter2_activated( int )</slot> + <slot>comboCounter1_activated( int )</slot> + <slot>TestDigitalButton_clicked()</slot> + <slot>TestAnalogButton_clicked()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kled.h</includehint> + <includehint>kled.h</includehint> + <includehint>kled.h</includehint> + <includehint>kled.h</includehint> + <includehint>kled.h</includehint> +</includehints> +</UI> diff --git a/pyk8055/frmk8055qt.ui.h b/pyk8055/frmk8055qt.ui.h new file mode 100644 index 0000000..1e986e6 --- /dev/null +++ b/pyk8055/frmk8055qt.ui.h @@ -0,0 +1,260 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you want to add, delete, or rename functions or slots, use +** Qt Designer to update this file, preserving your code. +** +** You should not define a constructor or destructor in this file. +** Instead, write your code in functions called init() and destroy(). +** These will automatically be called by the form's constructor and +** destructor. +*****************************************************************************/ + + +void K8055QT::ConnectButton_clicked() +{ + if (self.card != None) and (self.k == None): + try: + #print "Connect to card #",self.card + self.k = k8055(self.card) + self.EnableAll() + self.ClearAllDigitalButton_clicked() + self.ClearAllAnalogButton_clicked() + self.comboCounter1.setCurrentItem(0) + self.comboCounter2.setCurrentItem(0) + + self.ConnectButton.setText(self.__tr("Disconnect")) + except: + print "No such Card" + elif (self.k != None): + try: + #print "Disconnect from card #",self.card + self.k.CloseDevice() + self.k = None + self.DisableAll() + self.OutputBox1.setChecked(0) + self.OutputBox2.setChecked(0) + self.OutputBox3.setChecked(0) + self.OutputBox4.setChecked(0) + self.OutputBox5.setChecked(0) + self.OutputBox6.setChecked(0) + self.OutputBox7.setChecked(0) + self.OutputBox8.setChecked(0) + self.BarDA1.setValue(0) + self.BarDA2.setValue(0) + self.BarAD1.setValue(0) + self.BarAD2.setValue(0) + self.DA1Value.setProperty("intValue",QVariant(0)) + self.DA2Value.setProperty("intValue",QVariant(0)) + self.AD1Value.setProperty("intValue",QVariant(0)) + self.AD2Value.setProperty("intValue",QVariant(0)) + self.comboCounter1.setCurrentItem(0) + self.comboCounter2.setCurrentItem(0) + self.Counter1Value.setProperty("intValue",QVariant(0)) + self.Counter2Value.setProperty("intValue",QVariant(0)) + self.ConnectButton.setText(self.__tr("Connect")) + except: + pass + +} + + +void K8055QT::CardButton1_clicked() +{ + self.card = 0 +} + +void K8055QT::CardButton2_clicked() +{ + self.card = 1 +} + +void K8055QT::CardButton3_clicked() +{ + self.card = 2 +} + +void K8055QT::CardButton4_clicked() +{ + self.card = 3 +} + + +void K8055QT::init() +{ + self.k = None + self.DisableAll() +} + +void K8055QT::ClearCounter1_clicked() +{ + if self.k: + self.k.ResetCounter(1) +} + +void K8055QT::ClearCounter2_clicked() +{ + if self.k: + self.k.ResetCounter(2) +} + + +void K8055QT::OutputBox1_clicked() +{ + if self.k: + if self.OutputBox1.isChecked(): + self.k.SetDigitalChannel(1) + else: + self.k.ClearDigitalChannel(1) +} + +void K8055QT::OutputBox2_clicked() +{ + if self.k: + if self.OutputBox2.isChecked(): + self.k.SetDigitalChannel(2) + else: + self.k.ClearDigitalChannel(2) + +void K8055QT::OutputBox3_clicked() +{ + if self.k: + if self.OutputBox3.isChecked(): + self.k.SetDigitalChannel(3) + else: + self.k.ClearDigitalChannel(3) +} +void K8055QT::OutputBox4_clicked() +{ + if self.k: + if self.OutputBox4.isChecked(): + self.k.SetDigitalChannel(4) + else: + self.k.ClearDigitalChannel(4) +} +void K8055QT::OutputBox5_clicked() +{ + if self.k: + if self.OutputBox5.isChecked(): + self.k.SetDigitalChannel(5) + else: + self.k.ClearDigitalChannel(5) +} +void K8055QT::OutputBox6_clicked() +{ + if self.k: + if self.OutputBox6.isChecked(): + self.k.SetDigitalChannel(6) + else: + self.k.ClearDigitalChannel(6) +} +void K8055QT::OutputBox7_clicked() +{ + if self.k: + if self.OutputBox7.isChecked(): + self.k.SetDigitalChannel(7) + else: + self.k.ClearDigitalChannel(7) +} +void K8055QT::OutputBox8_clicked() +{ + if self.k: + if self.OutputBox8.isChecked(): + self.k.SetDigitalChannel(8) + else: + self.k.ClearDigitalChannel(8) +} + + +void K8055QT::SetAllAnalogButton_clicked() +{ + if self.k: + self.k.SetAllAnalog() + self.BarAD1.setValue(0) + self.BarAD2.setValue(0) + self.AD1Value.setProperty("intValue",QVariant(255)) + self.AD2Value.setProperty("intValue",QVariant(255)) +} + + +void K8055QT::ClearAllAnalogButton_clicked() +{ + if self.k: + self.k.ClearAllAnalog() + self.BarAD1.setValue(255) + self.BarAD2.setValue(255) + self.AD1Value.setProperty("intValue",QVariant(0)) + self.AD2Value.setProperty("intValue",QVariant(0)) +} + + +void K8055QT::SetAllDigitalButton_clicked() +{ + if self.k: + self.k.SetAllDigital() + self.OutputBox1.setChecked(1) + self.OutputBox2.setChecked(1) + self.OutputBox3.setChecked(1) + self.OutputBox4.setChecked(1) + self.OutputBox5.setChecked(1) + self.OutputBox6.setChecked(1) + self.OutputBox7.setChecked(1) + self.OutputBox8.setChecked(1) +} + +void K8055QT::ClearAllDigitalButton_clicked() +{ + if self.k: + self.k.ClearAllDigital() + self.OutputBox1.setChecked(0) + self.OutputBox2.setChecked(0) + self.OutputBox3.setChecked(0) + self.OutputBox4.setChecked(0) + self.OutputBox5.setChecked(0) + self.OutputBox6.setChecked(0) + self.OutputBox7.setChecked(0) + self.OutputBox8.setChecked(0) +} + + +void K8055QT::BarAD1_valueChanged( int ) +{ + if self.k: + self.k.OutputAnalogChannel(1,255-a0) + self.AD1Value.setProperty("intValue",QVariant(255-a0)) +} + +void K8055QT::BarAD2_valueChanged( int ) +{ + if self.k: + self.k.OutputAnalogChannel(2,255-a0) + self.AD2Value.setProperty("intValue",QVariant(255-a0)) +} + + +void K8055QT::comboCounter2_activated( int ) +{ + if self.k: + v = str(self.comboCounter2.currentText()).split() + self.k.SetCounterDebounceTime(2,int(v[0])) +} + + +void K8055QT::comboCounter1_activated( int ) +{ + if self.k: + v = str(self.comboCounter1.currentText()).split() + self.k.SetCounterDebounceTime(1,int(v[0])) +} + + +void K8055QT::TestDigitalButton_clicked() +{ + self.DigitalTest() +} + + +void K8055QT::TestAnalogButton_clicked() +{ + self.AnalogTest() +} diff --git a/pyk8055/k8055.py b/pyk8055/k8055.py new file mode 100755 index 0000000..3c03a10 --- /dev/null +++ b/pyk8055/k8055.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +# $Id: k8055.py,v 1.2 2007/03/15 14:50:55 pjetur Exp $ +""" +Python version of K8055 command line program + +Copyright (C) 2007 by Pjetur G. Hjaltason + +Syntax : python k8055.py [-p:(number)] [-d:(value)] [-a1:(value)] [-a2:(value)] + [-num:(number) [-delay:(number)] [-dbt1:(value)] + [-dbt2:(value)] [-reset1] [-reset2] [-debug] [-h|--help] + -p:(number) Set board number (0/1/2/3) + -d:(value) Set digital output value (bitmask, 8 bits in decimal) + -a1:(value) Set analog output 1 value (0-255) + -a2:(value) Set analog output 2 value (0-255) + -num:(number) Set number of measures (-1 for no read) + -delay:(number) Set delay between two measures (in msec) + -dbt1:(value) Set debounce time for counter 1 (in msec) + -dbt2:(value) Set debounce time for counter 2 (in msec) + -reset1 Reset counter 1 + -reset2 Reset counter 2 + -debug Activate debug mode + -h or --help Print this text + +Example : python k8055.py -p:1 -d:147 -a1:25 -a2:203 + +NOTE: + Because of the nature of commands sent to the K8055 board, this + program has no way of knowing previous state of the analog or + digial outputs, thus each run of this command will clear the previous + state - and set a new state - of the analog and digital outputs + + See header of libk8055.c for more details of K8055 commands +""" +import sys +from time import sleep, time +from pyk8055 import * + +def main(argv): + # preset values + p , db = 0,0 # Port, debug + r1, r2 = 0,0 # reset1, reset2 + dl = -1 # delay + db1,db2 = -1,-1 # debounce1, debounce2 + a1,a2,d = -1,-1,-1 # analog1, analog2, digital + nm = 1 # number of times to read, default once + + # not the standard getopts way, but... + for arg in argv: + if arg in ("-h", "--help"): + print __doc__ + sys.exit(0) + elif arg[:4] == "-a1:" : a1 = int(arg[4:]) + elif arg[:4] == "-a2:" : a2 = int(arg[4:]) + elif arg[:5] == "-num:" : nm = int(arg[5:]) + elif arg[:3] == "-d:" : d = int(arg[3:]) + elif arg[:3] == "-p:" : p = int(arg[3:]) + elif arg[:7] == "-delay:" : dl = int(arg[7:]) + elif arg[:6] == "-dbt1:" : db1 = int(arg[6:]) + elif arg[:6] == "-dbt2:" : db2 = int(arg[6:]) + elif arg == "-reset1" : r1 = 1 + elif arg == "-reset2" : r2 = 1 + elif arg == "-debug" : db = 1 + else: + print __doc__ + sys.exit(0) + + try: + # Open device + if db == 1: k = k8055(p,True) # Debug mode + else: k = k8055(p) + + # set requested + if r1 != 0: k.ResetCounter(1) + if r2 != 0: k.ResetCounter(2) + if db1 != -1: k.SetCounterDebounceTime(1, db1) + if db2 != -1: k.SetCounterDebounceTime(2, db2) + + # Try to set all digital/analog values at the same time + if (d != -1 and a1 != -1 and a2 != -1) : SetAllValues(d,a1,a2) + elif (d != -1 and a1 != -1 ) : SetAllValues(d,a1,0) + elif (d != -1 and a2 != -1 ) : SetAllValues(d,0,a2) + elif (a1 != -1 and a2 != -1 ) : SetAllValues(0,a1,a2) + # Else only one specified + else: + if d != -1: k.WriteAllDigital(d) + if a1 != -1: k.OutputAnalogChannel(1,a1) + if a2 != -1: k.OutputAnalogChannel(2,a2) + + # Now we loop (or not) for the specified number of times + # reading all the input values + + # Each read of all values will take about 2-8ms, at least + # on my setup - so no sense in using delay less than 10 + if (dl > 0) & (dl < 10): dl = 10 + + if (nm > 0) & (dl > 0): + tst = tstart = time() + i = 0 + while nm > 0: + ds = str(k) + tnow = time() + tms = (tnow - tstart) * 1000.0 + delta= dl - (tms - dl*i) + #tst = tnow + print str(int(tms+0.4999))+";"+ds + sleep((delta)/1000.0) # compensate for read time + nm -= 1 + i += 1 + elif nm > 0: + print "0;"+ str(k) + + k.CloseDevice() + + except IOError: + print "Could not open the k8055 (port:%s)" % str(p) + +main(sys.argv[1:]) diff --git a/pyk8055/k8055qt.png b/pyk8055/k8055qt.png Binary files differnew file mode 100644 index 0000000..85647db --- /dev/null +++ b/pyk8055/k8055qt.png diff --git a/pyk8055/k8055qt.py b/pyk8055/k8055qt.py new file mode 100644 index 0000000..49288f6 --- /dev/null +++ b/pyk8055/k8055qt.py @@ -0,0 +1,232 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Python version of libK8055 demo program +# +# Copyright (C) 2007 by Pjetur G. Hjaltason +# + +import sys +from qt import * +#from qwt import * + +import time, string +from pyk8055 import * +from frmk8055qt import * + +class QTK8055(K8055QT): + def __init__(self): + K8055QT.__init__(self) + + # Not much sense in making a fancy menu yet + # + #puProg = QPopupMenu(self) + #puProg.insertItem("Quit", Kapp.quit) + + #puHelp = QPopupMenu(self) + #puHelp.insertItem("About", self.about) + + #self.menu = QMenuBar(self) + #self.menu.insertItem("Program", puProg) + #self.menu.insertItem("Help", puHelp) + + # enumerate devices + BMask = SearchDevices() + if not BMask: + print "No K8055 devices found" + exit + + # Enable those present + self.CardButton1.setEnabled((BMask & 0x01) > 0) + self.CardButton2.setEnabled((BMask & 0x02) > 0) + self.CardButton3.setEnabled((BMask & 0x04) > 0) + self.CardButton4.setEnabled((BMask & 0x08) > 0) + + # set the first one found as suggestion + if (BMask & 0x01) > 0: + self.card = 0 + self.CardButton1.setChecked(1) + elif (BMask & 0x02) > 0: + self.card = 1 + self.CardButton2.setChecked(1) + elif (BMask & 0x04) > 0: + self.card = 2 + self.CardButton3.setChecked(1) + elif (BMask & 0x08) > 0: + self.card = 3 + self.CardButton4.setChecked(1) + + self.time = QTime.currentTime() # get current time + internalTimer = QTimer( self ) # create internal timer + self.connect( internalTimer, SIGNAL("timeout()"), self.timeout ) + internalTimer.start( 100 ) # emit signal every 1/10 second + + self.timeout() + + def AnalogTest(self): + try: + for step in range(0,255,10): + self.BarAD1.setValue(step) + self.BarAD2.setValue(step) + time.sleep(0.1) + # set analog output channel 1 to 200/255*5v = 3.9V + for step in range(255,0,10): + self.BarAD1.setValue(step) + self.BarAD2.setValue(step) + time.sleep(0.1) + + # read both analog inputs + # note: this returns a list + #res = self.k.ReadAllAnalog() + #sres = res[1:] + + # There should be more interesting information in the messagebox ;-/ + + QMessageBox.information( self,'Information', "AllOK","Ok") + except: + pass + + def DigitalTest(self): + try: + # Create a rotating display of digital outputs + # while waiting for keypress on digital input 1 + # (longer than .2sec :) Loop at most 3 times + Input1High = False + for i in range(1,3): + d = 1 + self.k.WriteAllDigital(1) + while Input1High == False and d < 128: + Input1High = (self.k.ReadDigitalChannel(1) > 0) + if Input1High: break + time.sleep(0.2) # wait .2 sec + d *=2 # and continue rotating digital outputs + #if d > 128: d=1; + self.k.WriteAllDigital(d) + if Input1High: break + + res = "Digital input 1=" + str(self.k.ReadDigitalChannel(1)) + "<br>" + # read the counter on input 1 + res+= "Counter(1)=" + str(self.k.ReadCounter(1)) + "<br>" + # read the counter on input 2 + res+= "Counter(2)=" + str(self.k.ReadCounter(2)) + + # set even bits on digital outputs + self.k.WriteAllDigital(170) + time.sleep(1) + # set odd bits on digital outputs + self.k.WriteAllDigital(85) + time.sleep(1) + # Clear all digital outputs + self.k.WriteAllDigital(0) + + # There should be more interesting information in the messagebox ;-/ + + QMessageBox.information( self,'DigitalTest', res,"Ok") + except: + QMessageBox.warning( self,'DigitalTest', "Not OK","Ok") + pass + + def EnableAll(self): + self.OutputBox1.setEnabled(1) + self.OutputBox2.setEnabled(1) + self.OutputBox3.setEnabled(1) + self.OutputBox4.setEnabled(1) + self.OutputBox5.setEnabled(1) + self.OutputBox6.setEnabled(1) + self.OutputBox7.setEnabled(1) + self.OutputBox8.setEnabled(1) + self.SetAllDigitalButton.setEnabled(1) + self.ClearAllDigitalButton.setEnabled(1) + self.SetAllAnalogButton.setEnabled(1) + self.ClearAllAnalogButton.setEnabled(1) + self.comboCounter1.setEnabled(1) + self.comboCounter2.setEnabled(1) + self.ClearCounter1.setEnabled(1) + self.ClearCounter2.setEnabled(1) + self.TestDigitalButton.setEnabled(1) + self.TestAnalogButton.setEnabled(1) + self.BarAD1.setEnabled(1) + self.BarAD2.setEnabled(1) + self.BarDA1.setEnabled(1) + self.BarDA2.setEnabled(1) + + def DisableAll(self): + self.OutputBox1.setEnabled(0) + self.OutputBox2.setEnabled(0) + self.OutputBox3.setEnabled(0) + self.OutputBox4.setEnabled(0) + self.OutputBox5.setEnabled(0) + self.OutputBox6.setEnabled(0) + self.OutputBox7.setEnabled(0) + self.OutputBox8.setEnabled(0) + self.SetAllDigitalButton.setEnabled(0) + self.ClearAllDigitalButton.setEnabled(0) + self.SetAllAnalogButton.setEnabled(0) + self.ClearAllAnalogButton.setEnabled(0) + self.comboCounter1.setEnabled(0) + self.comboCounter2.setEnabled(0) + self.ClearCounter1.setEnabled(0) + self.ClearCounter2.setEnabled(0) + self.TestDigitalButton.setEnabled(0) + self.TestAnalogButton.setEnabled(0) + self.BarAD1.setEnabled(0) + self.BarAD2.setEnabled(0) + self.BarDA1.setEnabled(0) + self.BarDA2.setEnabled(0) +# +## The QTimer::timeout() signal is received by this slot. +# + + def timeout( self ): + #new_time = QTime.currentTime() # get the current time + if self.k != None: + try: + AllVal = self.k.ReadAllValues() + #print AllVal,AllVal[2] + self.BarDA1.setValue(255 - AllVal[2]) + self.BarDA2.setValue(255 - AllVal[3]) + self.DA1Value.setProperty("intValue",QVariant(AllVal[2])) + self.DA2Value.setProperty("intValue",QVariant(AllVal[3])) + self.Counter1Value.setProperty("intValue",QVariant(AllVal[4])) + self.Counter2Value.setProperty("intValue",QVariant(AllVal[5])) + + if (AllVal[1] & 0x01) > 0: + self.DigitalLed1.setState(KLed.On) + else: + self.DigitalLed1.setState(KLed.Off) + if (AllVal[1] & 0x02) > 0: + self.DigitalLed2.setState(KLed.On) + else: + self.DigitalLed2.setState(KLed.Off) + if (AllVal[1] & 0x04) > 0: + self.DigitalLed3.setState(KLed.On) + else: + self.DigitalLed3.setState(KLed.Off) + if (AllVal[1] & 0x08) > 0: + self.DigitalLed4.setState(KLed.On) + else: + self.DigitalLed4.setState(KLed.Off) + if (AllVal[1] & 0x10) > 0: + self.DigitalLed5.setState(KLed.On) + else: + self.DigitalLed5.setState(KLed.Off) + except: + print "K8055 Read failed" + + def about(self): + QMessageBox.about( self, "About k8055qt", + "k8055qt is a small GUI program using libk8055\n\n" + "Copyright 2007 Pjetur G. Hjaltason. " + "Distributed under GPL license\n\n" + "For technical support, study the source code or surf\n" + "http://sourceforge.net/projects/libk8055/\n" ) + +if __name__ == "__main__": + Kapp = QApplication(sys.argv) + QObject.connect(Kapp,SIGNAL("lastWindowClosed()"),Kapp,SLOT("quit()")) + w = QTK8055() + Kapp.setMainWidget(w) + w.show() + Kapp.exec_loop() + + diff --git a/pyk8055/k8055test.py b/pyk8055/k8055test.py new file mode 100755 index 0000000..db5ee54 --- /dev/null +++ b/pyk8055/k8055test.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# $Id: k8055test.py,v 1.3 2007/03/28 10:09:34 pjetur Exp $ +# +# Sample pyton test program for pyk8055 wrapper +# Testing single board +# +from time import sleep +from pyk8055 import * + +try: + # CHANGE PORT HERE IF NEEDED + # Open device port 0 + k = k8055(0) + + # set analog output channel 1 to 200/255*5v = 3.9V + k.OutputAnalogChannel(1,200) + sleep(1) + # set analog output channel low again = 0V + k.OutputAnalogChannel(1,0) + + # read both analog inputs + # note: this returns a list + res = k.ReadAllAnalog() + print res[1:] + + # Test class string function + print str(k) + + # Set debounce time on counter 1 + k.SetCounterDebounceTime(1, 100) + + # reset counter 1 + k.ResetCounter(1) + + # create a rotating display of digital outputs + # while waiting for keypress on digital input 1 + # (longer than .2sec :) + Loop,dInput1,d = 0,0,1 + k.WriteAllDigital(1) + while Loop < 3 or dInput1 == 0: # is key 1 down (input 1 high) + dInput1 = k.ReadDigitalChannel(1) + Loop += 1 + sleep(0.2) # wait .2 sec + d *=2 # and continue rotating digital outputs + if d > 128: d=1; + k.WriteAllDigital(d) + + print "Digital input 1=",dInput1 + + # read the counter on input 1 + print "Counter(1)=",k.ReadCounter(1) + # read the counter on input 2 + print "Counter(2)=",k.ReadCounter(2) + + # set even bits on digital outputs + k.WriteAllDigital(170) + sleep(1) + # set odd bits on digital outputs + k.WriteAllDigital(85) + sleep(1) + # Clear all digital outputs + k.WriteAllDigital(0) + + # and close + k.CloseDevice() + +except IOError: + print "Could not open Device" + + diff --git a/pyk8055/k8055testm.py b/pyk8055/k8055testm.py new file mode 100644 index 0000000..a20dc30 --- /dev/null +++ b/pyk8055/k8055testm.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# $Id: k8055testm.py,v 1.1 2007/03/28 10:10:32 pjetur Exp $ +# +# Sample pyton test program for pyk8055 wrapper +# Scanning and testing multiple boards +# +from time import sleep +from pyk8055 import * + +try: + K8055_devices =[] + BMask = SearchDevices() + if not BMask: + print "No K8055 devices found" + exit + + if BMask & 0x01 : K8055_devices.append(k8055(0)) + if BMask & 0x02 : K8055_devices.append(k8055(1)) + if BMask & 0x04 : K8055_devices.append(k8055(2)) + if BMask & 0x08 : K8055_devices.append(k8055(3)) + + for k in K8055_devices: + k.SetCurrentDevice() + # set analog output channel 1 to 200/255*5v = 3.9V + k.OutputAnalogChannel(1,200) + sleep(1) + # set analog output channel low again = 0V + k.OutputAnalogChannel(1,0) + + # read both analog inputs + # note: this returns a list + res = k.ReadAllAnalog() + print "Analog status, board #",k.DeviceAddress(),res[1:] + + # Test class string function + print "Status, board #",k.DeviceAddress(),str(k) + + # Set debounce time on counter 1 + k.SetCounterDebounceTime(1, 100) + + # reset counter 1 + k.ResetCounter(1) + + # Loop creating a rotating display of digital outputs + # Loop 3 times + for i in range(1,3): + for k in K8055_devices: + k.SetCurrentDevice() + d = 1 + k.WriteAllDigital(1) + while d <= 128: # While this running + if k.ReadDigitalChannel(1): + print "Hello world (from board #%d)" %(k.DeviceAddress(),) + sleep(0.2) # wait .2 sec + d *=2 # and continue rotating digital outputs + k.WriteAllDigital(d) + + for k in K8055_devices: + k.SetCurrentDevice() + # read/print the counter on input 1 + print "Board # %d Counter #1=%d" % (k.DeviceAddress(),k.ReadCounter(1)) + # read/print the counter on input 2 + print "Board # %d Counter #2=%d" % (k.DeviceAddress(),k.ReadCounter(2)) + + for k in K8055_devices: + k.SetCurrentDevice() + # set even bits on digital outputs + k.WriteAllDigital(170) + + sleep(1) + + for k in K8055_devices: + k.SetCurrentDevice() + # set odd bits on digital outputs + k.WriteAllDigital(85) + + sleep(1) + + for k in K8055_devices: + k.SetCurrentDevice() + # Clear all digital outputs + k.WriteAllDigital(0) + + # and close + for k in K8055_devices: + k.SetCurrentDevice() + k.CloseDevice() + +except KeyboardInterrupt: + for k in K8055_devices: + k.SetCurrentDevice() + k.WriteAllDigital(0) + k.CloseDevice() + exit + +except IOError: + print "Could not open Device" + diff --git a/pyk8055/libk8055.i b/pyk8055/libk8055.i new file mode 100644 index 0000000..b0d31e9 --- /dev/null +++ b/pyk8055/libk8055.i @@ -0,0 +1,352 @@ +/* $Id: libk8055.i,v 1.3 2007/03/28 10:08:13 pjetur Exp $ + + Copyright (C) 2007 by Pjetur G. Hjaltason + + + Python wrapper for the libk8055 library using "swig" + This file is part of the libk8055 Library. + + The libk8055 Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The libk8055 Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the + Free Software Foundation, Inc., + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + http://opensource.org/licenses/ + +*/ +%module pyk8055 +%include "typemaps.i" + +/* for the ReadAllAnalog and ReadAllValues function */ +%apply long *OUTPUT { long int *data1, long int *data2, long int *data3, long int *data4, long int *data5 }; + +%inline %{ + +/* For direct access to the DEBUG variable and global IO strings */ +extern int DEBUG; +extern unsigned char data_in[9]; +extern unsigned char data_out[9]; +/* + Extended functions for debugging the IO +*/ + +char strval[30]; + +/* returns 16byte hex string - 8 bytes */ +char * RawInput() + { + int i; + for(i=0; i< 8; i++) { + sprintf((char *)&strval[i*2],"%02X",data_in[i]); + } + return (char *)strval; + } + +/* More print friendly format */ +char * DumpInput() + { + int i; + for(i=0; i< 8; i++) { + sprintf((char *)&strval[i*3],"%02X:",data_in[i]); + } + strval[23] = '\0'; + return (char *)strval; + } + +char * DumpOutput() + { + int i; + for(i=0; i< 8; i++) { + sprintf((char *)&strval[i*3],"%02X:",data_out[i]); + } + strval[23] = '\0'; + return (char *)strval; + } +%} + +%{ +extern int OpenDevice (long int BoardAddress); +extern int CloseDevice (void); +extern long int ReadAnalogChannel (long int Channelno); +extern int ReadAllAnalog (long int *data1, long int *data2); +extern int OutputAnalogChannel (long int Channel, long int data); +extern int OutputAllAnalog (long int data1, long int data2); +extern int ClearAllAnalog (void); +extern int ClearAnalogChannel (long int Channel); +extern int SetAnalogChannel (long int Channel); +extern int SetAllAnalog (void); +extern int WriteAllDigital (long int data); +extern int ClearDigitalChannel (long int Channel); +extern int ClearAllDigital (void); +extern int SetDigitalChannel (long int Channel); +extern int SetAllDigital (void); +extern int ReadDigitalChannel (long int Channel); +extern long int ReadAllDigital (void); +extern int ResetCounter (long int counternr); +extern long int ReadCounter (long int CounterNo); +extern int SetCounterDebounceTime (long int CounterNo, long int DebounceTime); +extern int ReadAllValues (long int *data1, long int *data2, long int *data3, long int *data4, long int *data5); +extern int SetAllValues(int digitaldata, int addata1, int addata2); +extern int SetCounterDebounceTime(long CounterNo, long DebounceTime); +extern long SetCurrentDevice(long deviceno); +extern long SearchDevices(void); +extern char *Version(void); + +%} +/* + +And here we create the class interface to the library + +*/ +%pythoncode %{ +K8055_ERROR = -1 +_K8055_CLOSED = -1 + +class k8055: + "Class interface to the libk8055 library" + def __init__(self,BoardAddress=None,debug=False): + """Constructor, optional board open + + k=k8055() # Does not connect to board + k=k8055(1) # Init class and connect to board 1 + k=k8055(1,True) # connect to board 0 and enable debugging + + """ + self.Buttons = 0 + self.dev = _K8055_CLOSED + self.Address = BoardAddress + if debug == False: + self.DebugOff() + else: + self.DebugOn() + if BoardAddress != None: + try: + self.dev = self.OpenDevice(BoardAddress) + # print "Open OK " + str(self.dev) + except: + self.dev = _K8055_CLOSED + raise IOError, "Could not open device" + # print "Open error" + + def __str__(self): + """String format (almost) as from K8055 program""" + if self.__opentest() == True: # Device open + all = self.ReadAllValues() + return str(all[1])+";"+str(all[2])+";"+str(all[3])+";"+str(all[4])+";"+str(all[5]) + else: + return "" + + def __opentest(self): + if self.dev == _K8055_CLOSED: + return False + else: + return True + + def OpenDevice(self,BoardAddress): + """Open the connection to K8055 + + k=k8055() + try; + k.OpenDevice(0) # possible (address 0/1/2/3) + except IOError: + ... + returns 0 if OK, + Throws IOError if invalid board or not accessible + """ + if self.__opentest() == False: # Not open yet + self.dev = _pyk8055.OpenDevice(BoardAddress) + if self.dev == K8055_ERROR: + raise IOError, "Could not open device" + # print "Open OK " + str(self.dev) + return self.dev + + def CloseDevice(self): + """Close the connection to K8055 + + k.CloseDevice() + + retuns 0 if OK else -1 + """ + if self.dev != _K8055_CLOSED: + ret = _pyk8055.CloseDevice() + self.dev = _K8055_CLOSED + return ret + + def OutputAnalogChannel(self,Channel,value=0): + """Set analog output channel value, default 0 (0-255)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.OutputAnalogChannel(Channel,value) + + def ReadAnalogChannel(self,Channel): + """Read data from analog input channel (1/2)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ReadAnalogChannel(Channel) + + def ReadAllAnalog(self): + """Read data from both analog input channels at once + + Returns list, [return-value,channel_data1, channel_data2] + + """ + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ReadAllAnalog() + + def OutputAllAnalog(self,data1,data2): + """Set both analog output channels at once (0-255,0-255)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.OutputAllAnalog(data1,data2) + + def ClearAllAnalog(self): + """Set all (both) analog output channels to 0 (low)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ClearAllAnalog() + + def ClearAnalogChannel(self,Channel): + """Set analog output channel (1/2)to 0 (low)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ClearAnalogChannel(Channel) + + def SetAnalogChannel(self,Channel): + """Set analog output channel (1/2) to 0xFF (high)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.SetAnalogChannel(Channel) + + def SetAllAnalog(self): + """Set all (both) analog output channels to 0xFF (high)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.SetAllAnalog() + + def WriteAllDigital(self,data): + """Write digital output channel bitmask (0-255)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.WriteAllDigital(data) + + def ClearDigitalChannel(self,Channel): + """Clear digital output channel (1-8)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ClearDigitalChannel(Channel) + + def ClearAllDigital(self): + """Set all digital output channels low (0)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ClearAllDigital() + + def SetDigitalChannel(self,Channel): + """Set digital output channel (1-8)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.SetDigitalChannel(Channel) + + def SetAllDigital(self): + """Set all digital output channels high (1)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.SetAllDigital() + + def ReadDigitalChannel(self,Channel): + """Read digital input channel (1-5), returns 0/1 (-1 on error)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ReadDigitalChannel(Channel) + + def ReadAllDigital(self): + """Read all digital input channels - bitmask + + returns mask 0x00 - 0x1f, 0x01 as channel 1, 0x02 as channel 2... + retuns -1 on error + + """ + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ReadAllDigital() + + def ResetCounter(self,CounterNo): + """Reset input counter (1/2), input channel 1/2""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ResetCounter(CounterNo) + + def ReadCounter(self,CounterNo): + """Read input counter (1/2), input channel 1/2""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ReadCounter(CounterNo) + + def SetCounterDebounceTime(self,CounterNo, DebounceTime): + """Set counter debounce time on counter 1/2 (1-7450 ms)""" + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.SetCounterDebounceTime(CounterNo,DebounceTime) + + # Makes no sense to switch to another class here + def SetCurrentDevice(self): + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.SetCurrentDevice(self.Address) + + # This function makes no sense in this context as + # the device is already open + #def SearchDevices(self): + #return _pyk8055.SearchDevices() + + def DeviceAddress(self): + return self.Address + + def IsOpen(self): + return self.__opentest() + + def ReadAllValues(self): + """Read data from all input channels at once + + Returns list, [return-value,digital input data, analog channel_data1, analog channel_data2, counter1, counter2] + + """ + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.ReadAllValues() + def SetAllValues(self,digitaldata, addata1, addata2): + if self.__opentest() == False : return K8055_ERROR + return _pyk8055.SetAllValues(digitaldata, addata1, addata2) + + def Version(self): + return _pyk8055.Version(); + + def DebugOn(self): + _pyk8055.cvar.DEBUG = 1 + def DebugOff(self): + _pyk8055.cvar.DEBUG = 0 + + def RawInput(self): + return _pyk8055.RawInput() + def DumpInput(self): + return "In <-"+_pyk8055.DumpInput() + def DumpOutput(self): + return "Out->"+_pyk8055.DumpOutput() + +%} +extern int OpenDevice (long int BoardAddress); +extern int CloseDevice (void); +extern long int ReadAnalogChannel (long int Channelno); +extern int ReadAllAnalog (long int *data1, long int *data2); +extern int OutputAnalogChannel (long int Channel, long int data); +extern int OutputAllAnalog (long int data1, long int data2); +extern int ClearAllAnalog (void); +extern int ClearAnalogChannel (long int Channel); +extern int SetAnalogChannel (long int Channel); +extern int SetAllAnalog (void); +extern int WriteAllDigital (long int data); +extern int ClearDigitalChannel (long int Channel); +extern int ClearAllDigital (void); +extern int SetDigitalChannel (long int Channel); +extern int SetAllDigital (void); +extern int ReadDigitalChannel (long int Channel); +extern long int ReadAllDigital (void); +extern int ResetCounter (long int counternr); +extern long int ReadCounter (long int CounterNo); +extern int SetCounterDebounceTime (long int CounterNo, long int DebounceTime); +extern int ReadAllValues (long int *data1, long int *data2, long int *data3, long int *data4, long int *data5); +extern int SetAllValues(int digitaldata, int addata1, int addata2); +extern long SetCurrentDevice(long deviceno); +extern long SearchDevices(void); +extern char *Version(void); diff --git a/pyk8055/pyplotA.py b/pyk8055/pyplotA.py new file mode 100755 index 0000000..6d19e29 --- /dev/null +++ b/pyk8055/pyplotA.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# $Id: pyplotA.py,v 1.2 2007/03/15 14:55:38 pjetur Exp $ +# +# Simple plotting of analog input data from the K8055 board +# +# based on the running plot sample from pyQwt +# The Python version of qwt-*/examples/data_plot/data_plot.cpp + +import random, sys +from qt import * +from qwt import * +from Numeric import * +from pyk8055 import * + + +class DataPlot(QwtPlot): + + def __init__(self, *args): + QwtPlot.__init__(self, *args) + + # Initialize data + self.x = arrayrange(0.0, 100.1, 0.5) + self.a1 = zeros(len(self.x), Float) + self.a2 = zeros(len(self.x), Float) + + self.setTitle("Simple K8055 datascope") + self.setAutoLegend(True) + + self.curve1 = self.insertCurve("Input 1") + self.curve2 = self.insertCurve("Input 2") + + self.setCurvePen(self.curve1, QPen(Qt.red)) + self.setCurvePen(self.curve2, QPen(Qt.blue)) + + # No automatic scaling, set y-scale 0-255 + self.setAxisScale(QwtPlot.yLeft,0,255,50) + + # set marker line in the middle - value 128 + mY = self.insertLineMarker("", QwtPlot.yLeft) + self.setMarkerYPos(mY, 128.0) + + self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") + self.setAxisTitle(QwtPlot.yLeft, "Values") + + self.startTimer(50) + + self.k = k8055(0) + # __init__() + + def timerEvent(self, e): + + # data moves from left to right: + # shift data array right and assign new value data[0] + + self.a1 = concatenate((self.a1[:1], self.a1[:-1]), 1) + self.a1[0] = self.k.ReadAnalogChannel(1) + + self.a2 = concatenate((self.a2[:1], self.a2[:-1]), 1) + self.a2[0] = self.k.ReadAnalogChannel(2) + + self.setCurveData(self.curve1, self.x, self.a1) + self.setCurveData(self.curve2, self.x, self.a2) + + self.replot() + + # timerEvent() + +# class DataPlot + +def main(args): + app = QApplication(args) + demo = make() + app.setMainWidget(demo) + app.exec_loop() + +# main() + +def make(): + demo = DataPlot() + demo.resize(500, 300) + demo.show() + return demo + +# make() + +# Admire +if __name__ == '__main__': + main(sys.argv) diff --git a/pyk8055/pyplotA_1.png b/pyk8055/pyplotA_1.png Binary files differnew file mode 100644 index 0000000..56ed71d --- /dev/null +++ b/pyk8055/pyplotA_1.png diff --git a/pyk8055/pyplotD.py b/pyk8055/pyplotD.py new file mode 100755 index 0000000..9145b37 --- /dev/null +++ b/pyk8055/pyplotD.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +# $Id: pyplotD.py,v 1.2 2007/03/15 14:55:38 pjetur Exp $ +# +# Simple plotting of digital input data from the K8055 board +# +# based on the running plot sample from pyQwt +# The Python version of qwt-*/examples/data_plot/data_plot.cpp + +import random, sys +from qt import * +from qwt import * +from Numeric import * +from pyk8055 import * + +class DataPlot(QwtPlot): + + def __init__(self, *args): + QwtPlot.__init__(self, *args) + + # Initialize data + self.x = arrayrange(0.0, 100.1, 0.5) + self.d1 = 0.0 + zeros(len(self.x), Float) + self.d2 = 1.0 + zeros(len(self.x), Float) # shift data up 1 + self.d3 = 2.0 + zeros(len(self.x), Float) # Shift data up 2... + self.d4 = 3.0 + zeros(len(self.x), Float) + self.d5 = 4.0 + zeros(len(self.x), Float) + + self.setTitle("Simple K8055 datascope") + self.setAutoLegend(True) + + self.curve1 = self.insertCurve("Input 1") + self.curve2 = self.insertCurve("Input 2") + self.curve3 = self.insertCurve("Input 3") + self.curve4 = self.insertCurve("Input 4") + self.curve5 = self.insertCurve("Input 5") + + self.setCurvePen(self.curve1, QPen(Qt.red)) + self.setCurvePen(self.curve2, QPen(Qt.blue)) + self.setCurvePen(self.curve3, QPen(Qt.green)) + self.setCurvePen(self.curve4, QPen(Qt.black)) + self.setCurvePen(self.curve5, QPen(Qt.cyan)) + + # Make data plot shape square + self.setCurveStyle(self.curve1, QwtCurve.Steps) + self.setCurveStyle(self.curve2, QwtCurve.Steps) + self.setCurveStyle(self.curve3, QwtCurve.Steps) + self.setCurveStyle(self.curve4, QwtCurve.Steps) + self.setCurveStyle(self.curve5, QwtCurve.Steps) + + # Fixed axis here from 0 to 5 + self.setAxisScale(QwtPlot.yLeft,0,5,1) + + self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") + self.setAxisTitle(QwtPlot.yLeft, "Values") + + self.startTimer(50) + + # init the K8055 board + self.k = k8055(0) + # __init__() + + def timerEvent(self, e): + + # data moves from left to right: + # shift data array right and assign new value data[0] + + self.d1 = concatenate((self.d1[:1], self.d1[:-1]), 1) + self.d1[0] = self.k.ReadDigitalChannel(1) * 0.95 + + self.d2 = concatenate((self.d2[:1], self.d2[:-1]), 1) + self.d2[0] = self.k.ReadDigitalChannel(2) * 0.95 + 1 # Shift data up 1 + + self.d3 = concatenate((self.d3[:1], self.d3[:-1]), 1) + self.d3[0] = self.k.ReadDigitalChannel(3) * 0.95 + 2 # Shift data up 2... + + self.d4 = concatenate((self.d4[:1], self.d4[:-1]), 1) + self.d4[0] = self.k.ReadDigitalChannel(4) * 0.95 + 3 + + self.d5 = concatenate((self.d5[:1], self.d5[:-1]), 1) + self.d5[0] = self.k.ReadDigitalChannel(5) * 0.95 + 4 + + self.setCurveData(self.curve1, self.x, self.d1) + self.setCurveData(self.curve2, self.x, self.d2) + self.setCurveData(self.curve3, self.x, self.d3) + self.setCurveData(self.curve4, self.x, self.d4) + self.setCurveData(self.curve5, self.x, self.d5) + + self.replot() + + # timerEvent() + +# class DataPlot + +def main(args): + app = QApplication(args) + demo = make() + app.setMainWidget(demo) + app.exec_loop() + +# main() + +def make(): + demo = DataPlot() + demo.resize(500, 300) + demo.show() + return demo + +# make() + +# Admire +if __name__ == '__main__': + main(sys.argv) + diff --git a/pyk8055/pyplotD_2.png b/pyk8055/pyplotD_2.png Binary files differnew file mode 100644 index 0000000..1603cf4 --- /dev/null +++ b/pyk8055/pyplotD_2.png diff --git a/pyk8055/setup.py b/pyk8055/setup.py new file mode 100644 index 0000000..b1a1c85 --- /dev/null +++ b/pyk8055/setup.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import os,sys,string +from distutils.core import setup, Extension + +__revision__ = "$Id: setup.py,v 1.3 2007/03/28 10:17:57 pjetur Exp $" + +if os.environ.has_key('VERSION'): + version=os.environ['VERSION'] +else: + from subprocess import * + try: + version = Popen(["grep ^VERSION ../Makefile | cut -d '=' -f 2 | tr -d '\n'"], stdout=PIPE, shell=True).communicate()[0] + except: + version='?.?' + +build_modules = [Extension('_pyk8055', + define_macros = [('VERSION', "\"%s\"" % str(version))], + libraries=["usb"], + sources=['libk8055.i',"../libk8055.c"])] + +setup( + name='pyk8055', + version=version, + author='Pjetur G. Hjaltason', + author_email='pjetur@pjetur.net', + description='K8055 library wrapper', + url='http://libk8055.sourceforge.net/', + ext_modules =build_modules, + py_modules=['pyk8055'] +) |