summaryrefslogtreecommitdiffstats
path: root/pyk8055/pyplotA.py
blob: e520c403cee6738b50d657d6fec6e826d29319e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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 sys
from Numeric import *
from PyQt4.Qt import *
from PyQt4.Qwt5 import *
from pyk8055 import k8055

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 = QwtPlotCurve("Input 1")
        self.curve2 = QwtPlotCurve("Input 2")

        self.curve1.setPen(QPen(Qt.red))
        self.curve2.setPen(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)
        mY = QwtPlotMarker()
        #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.curve1.setData(self.x, self.a1)
        self.curve1.setData(self.x, self.a2)

        self.replot()
    # timerEvent()

# class DataPlot

def make():
    demo = DataPlot()
    demo.resize(500, 300)
    demo.show()
    return demo
# make()


def main(args):
    app = QApplication(args)
    demo = make()
    sys.exit(app.exec_())
# main()

if __name__ == '__main__':
    main(sys.argv)