class WaitForHStableCommand(): def __init__(self): self.regexp_str="Wait(?: at most "+Regexfloat+" secs)? for magnet (X|Y|Z) to finish ramping" self.label="Wait (at most X secs) for magnet (X|Y|Z) to finish ramping" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) self.waiting=False self.waiting_start=0 def run(self,main): values=self.regexp.capturedTexts() #wait for field to stabilize (and lock only when accessing the instrument) with main.reserved_access_to_instr: magnet=eval("main.magnet_"+values[2]) stat=magnet.query_status() if self.waiting==False: self.waiting=True self.waiting_start=time.clock() if not(stat=='RAMPING to programmed current/field') or (values[1]!='' and time.clock()-self.waiting_start>float(values[1])): #ramping is finished or time limit is reached, go to next line of macro self.waiting=False self.next_move=1 self.wait_time=500 else: #wait 5s and check again self.next_move=0 self.wait_time=5000
class SetTempVTICommand(): def __init__(self): self.regexp_str="Set VTI Loop (\d+) to "+Regexfloat+" K(?: @ "+Regexfloat+" K/min)?" self.label="Set VTI Loop X to X K (@ X K/min)" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) self.waiting=False self.waiting_start=0 def run(self,main): values=self.regexp.capturedTexts() ##get the loop index and setpoint value loop=float(values[1]) setpoint=float(values[2]) #if a ramp rate was also provided, go to this setpoint at this rate VTI=main.instr_9 if values[3]!='': rate=float(values[3]) with main.reserved_access_to_instr: VTI.conf_ramp(loop,rate,'on') VTI.set_setpoint(loop,setpoint) else: with main.reserved_access_to_instr: VTI.switch_ramp(loop,'off') VTI.set_setpoint(loop,setpoint) #go to next line of macro after stdwtime (give some time to process other events) self.next_move=1 self.wait_time=500
class AngleCommand(): def __init__(self): #Text that will appear in the list of commands on the right side of the Macro editor self.label="Set start|stop|step angle to FLOAT" #Regular expression which may or may not catch parameters self.regexp_str="Set (start|stop|step) angle to "+Regexfloat #Add this to the beginning and end of the regular expression #so that whitespaces before and after will not prevent the regex from matching self.regexp_str="^ *"+self.regexp_str+" *$" #instantiate regex self.regexp=QRegExp(self.regexp_str) def run(self,main): #what to do when the regex defined just above in __init__ #has matched the current line of the Macro #get the captured parameters values=self.regexp.capturedTexts() #set the corresponding angle box if values[1] in ['stop','step','start']: anglebox=eval("main.ui.angle"+values[1]) anglebox.setValue(float(values[2])) #Finally go to next line of macro... self.next_move=1 #...after 10 milliseconds self.wait_time=10
class SetSaveFileCommand(): def __init__(self): self.regexp_str="Set Save file to "+Regexsimplefile+"" self.label="Set Save file to X" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() main.ui.savefile_txt_input.setText(values[1]) #new file name is set, go to next line of macro self.next_move=1 self.wait_time=500
class WaitCommand(): def __init__(self): self.regexp_str="Wait "+Regexfloat+" secs" self.label="Wait X secs" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() #self.values[1]!='' #go to next line of macro after 'values[1]' seconds self.next_move=1 self.wait_time=float(values[1])*1000
class SetVTIHeaterCommand(): def __init__(self): self.regexp_str="Set VTI heater range to (\d)" self.label="Set VTI heater range to DIGIT" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() #set the heater range with main.reserved_access_to_instr: main.instr_9.set_heater_range(int(values[1])) #go to next line of macro self.next_move=1 self.wait_time=500
class SetVCommand(): def __init__(self): self.regexp_str="Set voltage (\d) to "+Regexfloat+" V" self.label="Set voltage DIGIT to FLOAT V" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() #set the voltage if values[1] in ['1','2','3']: V_source_setpoint=eval("main.ui.V_setpoint_"+values[1]) V_source_setpoint.setValue(float(values[2])) #go to next line of macro self.next_move=1 self.wait_time=500
class StartMeasureCommand(): def __init__(self): #type name_of_program() to start it self.regexp_str="Start "+Regexprogramfile+"\((.*)\)" self.label="Start PROGRAM()" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() main.ui.measMode.setCurrentIndex(main.ui.measMode.findText(values[1])) #start measurements main.start_measurements() #go to next line of macro self.next_move=1 self.wait_time=500
class WaitForEpoch(): def __init__(self): self.regexp_str="Wait for Epoch \+ "+Regexfloat+" secs" self.label="Wait for Epoch + X secs" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() #test if the current time is greater than the time provided in the macro (in Epoch seconds) if float(values[1])>time.time(): self.next_move=0 self.wait_time=5000 else: self.next_move=1 self.wait_time=100
class SetICommand(): def __init__(self): self.regexp_str="Set current (\d) to "+Regexfloat+" A" self.label="Set current DIGIT to FLOAT A" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() #set the current if values[1]=='1': main.ui.I_source_setpoint.setValue(float(values[2])*1e6) elif values[1] in ['2','3']: I_source_setpoint=eval("main.ui.I_source_setpoint_"+values[1]) I_source_setpoint.setValue(float(values[2])*1e6) #go to next line of macro self.next_move=1 self.wait_time=10
class EmailCommand(): def __init__(self): self.regexp_str="E-mail message: "+Regexsimplefile self.label="E-mail message: MESSAGE" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() msg=values[1] try: email_alert=Email_alert(message=msg.encode('utf8'),address=main.ui.email_address.text(),subject="Message from PyGMI",smtpadd=main.mainconf['smtpadd'],login=main.mainconf['login'],mdp=main.mainconf['mdp'],smtpport=main.mainconf['smtpport']) print "message successfully sent by e-mail" except: print "Exception: message could not be sent by e-mail" #go to next line of macro self.next_move=1 self.wait_time=500
class EmailDirCommand(): def __init__(self): self.regexp_str="E-mail directory: "+Regexsimplefile self.label="E-mail directory: DIRECTORY" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() dir_path=values[1] try: message="Hi,\n\nat your request, here is the directory: "+os.path.normpath(os.path.abspath(dir_path.encode('utf8').strip()))+"\n\n PyGMI" email_alert=Email_directory(directory=dir_path.encode('utf8').strip(),address=main.ui.email_address.text(),message=message,subject="Data directory from PyGMI",smtpadd=main.mainconf['smtpadd'],login=main.mainconf['login'],mdp=main.mainconf['mdp'],smtpport=main.mainconf['smtpport']) print "directory successfully sent by e-mail" except: print "Exception: directory could not be sent by e-mail" #go to next line of macro self.next_move=1 self.wait_time=500
class SetPersistFieldCommand(): def __init__(self): self.regexp_str="Set persistent field in magnet (X|Y|Z) to "+Regexfloat+" T" self.label="Set persistent field in magnet X|Y|Z to x T" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() ##set the loop index and setpoint value magnet_setpoint=eval("main.ui.B_"+values[1]+"_setpoint") magnet_setpoint.setValue(float(values[2])) time.sleep(1) main.ui.measMode.setCurrentIndex(main.ui.measMode.findText("Change_persistent_"+values[1]+"_field")) #start measurements main.start_measurements() #go to next line of macro after stdwtime (give some time to process other events) self.next_move=1 self.wait_time=500
class WaitForTStableCommand(): def __init__(self): self.regexp_str="Wait(?: at most "+Regexfloat+" secs)? for channel (\w) to reach "+Regexfloat+" \+/\- "+Regexfloat+" K" self.label="Wait(at most X secs) for channel X to reach X +/- X K" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) self.waiting=False self.waiting_start=0 def run(self,main): values=self.regexp.capturedTexts() #wait for temperature to stabilize (and lock only when accessing the instrument) with main.reserved_access_to_instr: T=main.temp_controller.query_temp(values[2]) if self.waiting==False: self.waitTcounter=0 self.waiting=True self.waiting_start=time.clock() if values[1]!='' and time.clock()-self.waiting_start>float(values[1]): #time limit is reached, go to next line of macro self.waiting=False self.next_move=1 self.wait_time=500 elif abs(T-float(values[3]))<float(values[4]): #Wait for the temperature measurement to be ten times #within the specified limits, in a row, to consider it stable if self.waitTcounter<10: #count one, wait 0.5 secs and measure T again self.waitTcounter+=1 self.next_move=0 self.wait_time=500 else: #Temperature is stable, go to next line of macro self.waitTcounter=0 self.waiting=False self.next_move=1 self.wait_time=500 else: #wait 10s and check again, but reset the stable temperature counter self.waitTcounter=0 self.next_move=0 self.wait_time=10000
class SetFieldCommand(): def __init__(self): self.regexp_str="Set Field of magnet (X|Y|Z) to "+Regexfloat+" G(?: @ "+Regexfloat+" G/s)?" self.label="Set Field of magnet X|Y|Z to X G (@ X G/s)" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) def run(self,main): values=self.regexp.capturedTexts() with main.reserved_access_to_instr: magnet=eval("main.magnet_"+values[1]) if values[3]!='': #if a ramp rate was also provided, go to this setpoint at this rate magnet.program_ramp_rate_in_Gauss_per_second(float(values[3])) #print "Setting Field to ", magnet.program_field_in_kG(float(values[2])*1e-3) magnet.ramp_to_programmed_field() #go to next line of macro self.next_move=1 self.wait_time=500
class WaitForMeasureCommand(): def __init__(self): self.regexp_str="Wait(?: at most "+Regexfloat+" secs)? for measurements completion" self.label="Wait(at most X secs) for measurements completion" self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches self.regexp=QRegExp(self.regexp_str) self.waiting=False self.waiting_start=0 def run(self,main): values=self.regexp.capturedTexts() if self.waiting==False: self.waiting=True self.waiting_start=time.clock() if not(main.measurements_thread.isAlive()) or (values[1]!='' and time.clock()-self.waiting_start>float(values[1])): #Measurements are complete or time limit was reached, go to next line of macro self.waiting=False self.next_move=1 self.wait_time=500 else: #wait 1s and check again if measurements are complete self.next_move=0 self.wait_time=1000