我目前正在使用 pygtk 和 glade 创建一个程序,该程序将控制两个电压之间的电压扫描。
我想知道如果输出发生问题,如何将扫描作为安全功能中断。我已经在下面发布了我的扫描代码。基本上我想要的是一个连接到“停止”按钮的函数,我可以将其插入到我的脚本中,而无需运行 sys.exit() 并关闭 GUI 或程序。
def drange(start, stop, step):
r = start
while min(start, stop) <= r <= max(start, stop):
yield r
r = r + step
def setchan(self, widget, N, v_f=None):
delay = float(self.delayer.get_text())/1000
if (v_f == None): float( self.volt_widgets[int(N-1)][0].get_text())
self.min = float( self.volt_widgets[int(N-1)][1].get_text())
self.max = float( self.volt_widgets[int(N-1)][2].get_text())
if v_f > self.max:
print "The channel voltage would be set to more than the allowed maximum"
raise ValueError
if v_f < self.min:
print "The channel voltage would be set to less than the allowed minimum"
raise ValueError
v_f = self.translate_Vf_to_Vb(self.poldacs[int(N-1)], v_f)
self.device.do_set_dac( v_f, N )
def sweepchan(self, widget, N):
self.get_pol()
delay = float(self.delayer.get_text())/1000
numstep = int(self.stepper.get_text())
v_i = self.translate_Vb_to_Vf(self.poldacs[N-1], self.device.do_get_dac(N))
v_f = float( self.volt_widgets[int(N-1)][0].get_text())
self.min = float( self.volt_widgets[int(N-1)][1].get_text())
self.max = float( self.volt_widgets[int(N-1)][2].get_text())
if v_f > self.max:
print "The final voltage is set to higher than the allowed maximum"
return
if v_f < self.min:
print "The final voltage is set to less than the allowed minimum"
return
vstep = (v_f - v_i)/numstep
if abs(vstep) <= 0.00001:
print "The current voltage and final voltage are the same"
return
for V in drange(v_i, v_f, vstep):
self.setchan( None, N, V)
time.sleep(delay)