aboutsummaryrefslogtreecommitdiff
path: root/panel.py
diff options
context:
space:
mode:
Diffstat (limited to 'panel.py')
-rw-r--r--panel.py95
1 files changed, 75 insertions, 20 deletions
diff --git a/panel.py b/panel.py
index 07a1362..d660af4 100644
--- a/panel.py
+++ b/panel.py
@@ -174,17 +174,22 @@ class Experiment:
def __init__(self, root):
self.root = root
self.tic = 0
+ self.channelsNames2plot={'dac0', 'dac1', 'adc1', 'adc2', 'adc3', 'adc4'}
+ self.xChannelName='dac0' # can be also 'tic' or any of above
+ self.xlabel='Frequency (Hz)'
+ self.lines2plot={}
self.clearData()
self.guiSetup(root)
self.guiSweeper = Sweeper(self.root, Npoints=2, SweepTime=1, onTicCallbacks=[self.updatePlot])
self.guiSweeper.cmdStart()
self.hardware = {}
- self.hardwareSetup()
+ # self.hardwareSetup()
self.sweeper = Sweeper(self.root, Npoints=100, SweepTime=1, onTicCallbacks=[self.onTic])
# self.funcGen = SinGen(2, 2, sweeper = self.sweeper)
# self.funcGen = RampGen(0, 5, sweeper = self.sweeper)
self.funcGen = TriangleGen(0, 5, sweeper = self.sweeper)
+
def hardwareSetup(self):
self.hardware['LabJack'] = ue9qol.UE9qol()
@@ -217,7 +222,7 @@ class Experiment:
# self.ax.set_xlim([0,20])
# self.ax.set_ylim([0,20])
# self.ax.plot([i for i in range(10)],[i for i in range(10)])
- self.line, = self.ax.plot(self.data['tic'], self.data['ch1'], '.')
+ self.line, = self.ax.plot(self.data['tic'], self.data['adc1'], '.')
self.canvas = FigureCanvasTkAgg(self.fig, master = self.dataDisplay)
self.canvas.draw()
@@ -235,7 +240,13 @@ class Experiment:
def clearData(self):
self.data = {}
self.data['tic'] = []
- self.data['ch1'] = []
+ self.data['x'] = []
+ self.data['dac0'] = []
+ self.data['dac1'] = []
+ self.data['adc1'] = []
+ self.data['adc2'] = []
+ self.data['adc3'] = []
+ self.data['adc4'] = []
def stop(self):
self.sweeper.cmdStop()
@@ -251,41 +262,85 @@ class Experiment:
start = datetime.now()
if swp is None:
swp = self.sweeper
- # self.root.after(1000, self.hello )
- # self.sweeper.incr()
- # tic = self.sweeper.getCnt()
- x = swp.getRelPos()
- y = self.funcGen.getValue(swp)
- # y = self.sweeper.getPos()
- # self.hardware['LabJack'].setOutputCh(0, x/2)
- self.hardware['LabJack'].setOutputCh(0, y)
- self.data['tic'].append(x)
- y= self.hardware['LabJack'].getInputCh(1)
- # self.data['ch1'].append( self.hardware['LabJack'].getInputCh(1) )
- self.data['ch1'].append( y )
+
+ # global tic counter
+ tic = self.sweeper.getCnt()
+ self.data['tic'].append(tic)
+
+ # DAQ
+ # daq0 = self.hardware['LabJack']
+
+ # dac0
+ dac0 = self.funcGen.getValue(swp)
+ # daq0.setOutputCh(0, out0)
+ self.data['dac0'].append(dac0)
+
+ # dac1
+ dac1 = PulseGen(ampl=5, sweeper=swp).getValue()
+ # daq0.setOutputCh(0, dac1)
+ self.data['dac1'].append(dac1)
+
+ # adc1
+ # adc1= daq0.getInputCh(1)
+ adc1 = SinGen(ampl=1, sweeper=swp).getValue()
+ self.data['adc1'].append( adc1 )
+
+ # adc2
+ # adc2= daq0.getInputCh(2)
+ adc2 = SinGen(ampl=2, sweeper=swp).getValue()
+ self.data['adc2'].append( adc2 )
+
+ # adc3
+ # adc3= daq0.getInputCh(3)
+ adc3 = SinGen(ampl=3, sweeper=swp).getValue()
+ self.data['adc3'].append( adc3 )
+
+ # adc4
+ # adc4= daq0.getInputCh(4)
+ adc4 = SinGen(ampl=4, sweeper=swp).getValue()
+ self.data['adc4'].append( adc4 )
+
+ # X-axis (i.e. independent variable)
+ # self.data['x'].append(tic)
+ self.data['x']=self.data[self.xChannelName]
+
stop = datetime.now()
runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000
# print("onTic DAQ took %s seconds." % (runTime) )
def autoZoom(self):
self.ax.cla()
- self.line, = self.ax.plot(self.data['tic'], self.data['ch1'], '.')
+ x = self.data['x']
+ for name in self.channelsNames2plot:
+ if name not in self.data:
+ continue
+ y = self.data[name]
+ self.lines2plot[name], = self.ax.plot(x, y, '.', label=name)
+ self.ax.legend()
+ plt.xlabel(self.xlabel)
self.canvas.draw()
def updatePlot(self,swp=None):
start = datetime.now()
# self.ax.cla()
- # self.line, = self.ax.plot(self.data['tic'], self.data['ch1'], '.')
+ # self.line, = self.ax.plot(self.data['tic'], self.data['adc1'], '.')
# t = Thread(target=self.canvas.draw)
# self.line.set_data([.1, .2, .3], [.1, .2, .3])
- self.line.set_data(self.data['tic'], self.data['ch1'])
- self.ax.draw_artist(self.line)
+ x = self.data['x']
+ for name in self.channelsNames2plot:
+ if name not in self.data:
+ continue
+ y = self.data[name]
+ if name in self.lines2plot:
+ ln = self.lines2plot[name]
+ ln.set_data(x, y)
+ self.ax.draw_artist(ln)
# self.canvas.update()
# self.canvas.draw()
self.fig.canvas.flush_events()
stop = datetime.now()
runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000
- print("Replot took %s seconds to plot %s points." % (runTime, len(self.data['ch1'])) )
+ print("Replot took %s seconds to plot %s points." % (runTime, len(self.data['adc1'])) )
if __name__ == '__main__':