aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-04-03 13:41:11 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-04-03 13:41:11 -0400
commite1ef103a8bda50cc26348cbbb672467f5dfb6964 (patch)
tree20fbb246225b87243f5d17059a76983d8a904878
parent579109775d37888fe17196208c2f3271399af6eb (diff)
downloadpyExpControl-e1ef103a8bda50cc26348cbbb672467f5dfb6964.tar.gz
pyExpControl-e1ef103a8bda50cc26348cbbb672467f5dfb6964.zip
added start, stop, restart for sweeper
-rw-r--r--panel.py85
1 files changed, 73 insertions, 12 deletions
diff --git a/panel.py b/panel.py
index c1b707a..19c150c 100644
--- a/panel.py
+++ b/panel.py
@@ -12,25 +12,71 @@ from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationTool
import ue9qol
class Sweeper:
- def __init__(self, start, stop, Npoints, SweepTime):
+ def __init__(self, widget, start, stop, Npoints, SweepTime, onTicCallbacks=[]):
# walk from start to stop with Npoints
# cnt = 1 corresponds to start
# cnt = Npoints corresponds to stop
# variables like relVar are relative to the start of the period
+ self.cnt = 0 # onTic will increase it right away
+ self.widget = widget
self.start = start
self.stop = stop
self.Npoints = Npoints
self.SweepTime = SweepTime
+ self.onTicCallbacks = onTicCallbacks
+ self.isOn = False
+ self.isRestart = True
+ self.isTicRunning = False
self.span = self.stop - self.start
self.center = (self.stop + self.start)/2
self.dPos = self.span/(self.Npoints-1)
- self.restart()
+ self.dT = self.SweepTime/(self.Npoints-1)
+ self.dTmS = round(self.dT*1000) # dT in microSeconds
- def restart(self):
- self.cnt = 1
+ def reset(self):
+ self.cnt = 0 # onTic will increase it right away
+ self.isRestart = False
self.startTime = datetime.now()
- self.updPos()
+
+ def onTic(self):
+ if not self.isOn:
+ self.isTicRunning = False
+ return
+ self.widget.after(self.dTmS, self.onTic)
+ if self.isTicRunning:
+ print("Overflow in Sweeper: need more time to finish a tic.")
+ return
+ self.isTicRunning = True
+ if self.isRestart:
+ self.reset()
+ self.isRestart = False
+ self.incr()
+ print(self.cnt)
+ # if self.onTicCallbacks is None:
+ # self.isTicRunning = False
+ # return
+ # print(self.onTicCallbacks)
+ # for cb in self.onTicCallbacks:
+ # print(cb)
+ # cb(self)
+ self.isTicRunning = False
+
+ def cmdRestart(self):
+ self.cnt = 0
+ if self.isOn:
+ self.isRestart = True
+ return
+ self.reset()
+ self.isOn = True
+ self.onTic()
+
+ def cmdStart(self):
+ self.isOn = True
+ self.onTic()
+
+ def cmdStop(self):
+ self.isOn = False
def incr(self):
self.cnt += 1
@@ -65,20 +111,26 @@ class Experiment:
self.guiSetup(root)
self.hardware = {}
self.hardwareSetup()
- self.sweeper = Sweeper(1, 10, 10, 10)
- self.root.after(1000, self.hello )
+ self.sweeper = Sweeper(self.root, 1, 10, 10, 10)
+ # self.root.after(1000, self.hello )
def hardwareSetup(self):
self.hardware['LabJack'] = ue9qol.UE9qol()
def guiSetup(self, root):
- self.bStart=Button(root,text="START",command=self.hello,font=('Arial','24'))
+ self.bRestart=Button(root,text="RESTART",command=self.restart,font=('Arial','24'))
+ self.bRestart.pack()
+
+ self.bStart=Button(root,text="START",command=self.start,font=('Arial','24'))
self.bStart.pack()
- self.bStop=Button(root,text="STOP",command=exit,font=('Arial','24'))
+ self.bStop=Button(root,text="STOP",command=self.stop,font=('Arial','24'))
self.bStop.pack()
+ self.bExit=Button(root,text="EXIT",command=exit,font=('Arial','24'))
+ self.bExit.pack()
+
self.fig=plt.figure()
self.ax = self.fig.add_subplot(1,1,1)
@@ -99,9 +151,18 @@ class Experiment:
# placing the toolbar on the Tkinter window
self.canvas.get_tk_widget().pack()
- def hello(self):
- self.root.after(1000, self.hello )
- self.sweeper.incr()
+ def stop(self):
+ self.sweeper.cmdStop()
+
+ def start(self):
+ self.sweeper.cmdStart()
+
+ def restart(self):
+ self.sweeper.cmdRestart()
+
+ def onTic(self):
+ # self.root.after(1000, self.hello )
+ # self.sweeper.incr()
tic = self.sweeper.getCnt()
x = self.sweeper.getPos()
# y = self.sweeper.getPos()