def move(self, value): self.__user_desidered_pos = value if (numpy.isnan(value)): logprint( "Problem interpreting requested position for motor %s (pv %s)... not continuing" % (self.name, self.pvname), print_screen=1) return self.wm() if ((value < self.get_lowlim()) or (value > self.get_hilim())): logprint("Asked to move %s (pv %s) outside limit, aborting" % (self.name, self.pvname), print_screen=1) return self.wm() (status, msg) = self.check_limit_switches() if ((status == "high") and (value > self.wm())): logprint(msg + ",aborting", print_screen=1) return self.wm() elif ((status == "low") and (value < self.wm())): logprint(msg + ",aborting", print_screen=1) return self.wm() logprint("moving %s (pv %s) to %f, previous position: %f" % (self.name, self.pvname, value, self.wm())) if self.__writepv is not None: return pypsepics.put(self.__writepv, value) else: return pypsepics.put(self.pvname, value)
def dial_delay(self, value=None): '''Reads or writes directly to the angle shift pv. This doesnt use the offsett. usage: dial_delay(): read pack the angle shift pv dial_delay(value): writes to the angle shift variable, and toggles gain to get new value fast. ''' if (value is None): return pypsepics.get(self.__pv_angleshift_rbv) * 1e-15 else: #m = 0; M=14.7e-9 m = 0 M = 19.2e-9 if ((value < m) or (value > M)): logprint( "Phase shifter has a range (%.2e,%.2e), asked for %.3e, aborting" % (m, M, value), print_screen=True) return self.__desired_value = value if abs(pypsepics.get(self.__pv_angleshift_rbv) * 1e-15 - value) > 5e-12: self.lowgain() pypsepics.put(self.__pv_angleshift, int(value * 1e15)) self.wait() self.higain() else: pypsepics.put(self.__pv_angleshift, int(value * 1e15)) return
def connect(self): if (self.pyamiE is not None): return try: self.pyamiE = pyami.Entry(self.aminame) except RuntimeError: s = "detector %s cannot be found" % self.name logprint(s, print_screen=True) self.pyamiE = None
def monitor_start(self): """ start monitoring for the Pv, new values are added to the `values` list """ evtmask = pyca.DBE_VALUE | pyca.DBE_LOG | pyca.DBE_ALARM self.monitor(evtmask, ctrl=False) self.ismonitored = True pyca.flush_io() # self.values=[] if (is_debug_on()): logprint("start monitoring for %s" % self.name)
def move_relative(self, howmuch): current = self.wm() if (numpy.isnan(current)): logprint( "Problem retreiving current position for motor %s (pv %s)... not continuing" % self.name, self.pvname) return None else: return self.move(current + howmuch)
def trip(self, value=None): """ Sets or Returns the gauge trip point for the vacuum PLC """ previous_trip = pypsepics.get(self.__pstatsprbck) if (value is not None): pypsepics.put(self.__pstatspdes, value) s = "Resetting PLC trip point of `%s` from %.4g to %.4g" % ( self.name, previous_trip, value) logprint(s, print_screen=True) else: print "%s trip point is %.4g" % (self.name, previous_trip)
def setE(self,E=None): """ set the energy (in keV) for calculation of transmission if called without parameter, it reads the value from the machine """ if ( E is None ): self.__E = self.__lcls.getXrayeV()/1e3 else: self.__E=E logprint("lusiatt: setting energy for transmission calculation to %.3f keV" % self.__E) return self.__E
def set(self, value=0, show_previous=True): # EPICS does user = dial + offset # offset = value + self.__sign()*self.wm_dial() current_dial = self.wm_dial() current_user = self.wm() offset = value - self.__sign() * current_dial if (show_previous): s = "Resetting user `%s` (PV: %s) from (dial,user) = (%.4g,%.4g) to (%.4g,%.4g)" % ( self.name, self.pvname, current_dial, current_user, current_dial, value) logprint(s, print_screen=True) self.put_par("offset", offset)
def monitor_start(self, monitor_append=False): """ start monitoring for the Pv, new values are added to the `values` list """ if (self.ismonitored and self.monitor_append == monitor_append): return if (self.ismonitored and self.monitor_append != monitor_append): self.monitor_stop() self.monitor_append = monitor_append evtmask = pyca.DBE_VALUE | pyca.DBE_LOG | pyca.DBE_ALARM self.monitor(evtmask, ctrl=False) self.ismonitored = True pyca.flush_io() self.values = [] if (is_debug_on()): logprint("start monitoring for %s" % self.name)
def __init__(self, name): pycaPv.__init__(self, name) try: self.connect(time_out_connect) except pyca.pyexc: print "## WARNING ## connecting to %s timeout, will try once more" % name logprint( "## WARNING ## connecting to %s timeout, will try once more" % name) time.sleep(0.1) self.connect(time_out_connect) self.monitor_cb = self.monitor_handler self.values = [] self.ismonitored = False self.monitor_append = False self.last_update = "Never"
def move_dial(self,value): if (self.low_dial_lim is not None): check_low = (value>=self.low_dial_lim) else: check_low = True if (self.high_dial_lim is not None): check_high = (value<=self.high_dial_lim) else: check_high = True check = check_low and check_high if (not check): logprint("Asked to move %s (pv %s) to dial %f that is outside limits, aborting" % (self.name,self.pvname,value),print_screen=1) else: self.__desidered_value = value self.__move_dial(value) pos=self.wm()
def set_dial(self, value=0, show_previous=True): current_dial = self.wm_dial() current_user = self.wm() self.put_par("set", 1) # go in set mode sleep(0.1) # to make sure we are in set mode if (self.get_par("set") != 1): print "Failed to go in set mode, try again" return self.put_par("dial_drive", value) self.put_par("set", 0) # go in use mode s = "Resetting dial `%s` (PV: %s) from (dial,user) = (%.4g,%.4g) to (%.4g,%.4g)" % ( self.name, self.pvname, current_dial, current_user, value, current_user) logprint(s, print_screen=True)
def monitor_get(self): """ retuns statistics for the current `values` list as dictionary """ # skip first 'pulse' because its values comes from before monitoring .. a = numpy.array(self.values[1:]) ret = {} if (len(a) == 0): ret["mean"] = ret["std"] = ret["num"] = ret["err"] = numpy.nan ret["num"] = 0 if (is_debug_on()): logprint("No pulses.... while monitoring %s" % self.name) return ret # remove "bad readings" ret["mean"] = a.mean() ret["std"] = a.std() ret["num"] = len(a) ret["err"] = ret["std"] / numpy.sqrt(ret["num"]) if (is_debug_on()): logprint("get monitoring for %s" % self.name) return ret
def create_ami(self): try: if self.__filter_string is None: #print "MATT: about to create ami entry" self.pyamiE = pyami.Entry(self.aminame, "Scalar") #print "MATT: created ami entry" pass else: #print "MATT: about to create ami entry" self.pyamiE = pyami.Entry(self.aminame, "Scalar", self.__filter_string) #print "MATT: created ami entry" pass except RuntimeError: s = "detector %s cannot be found" % self.name logprint(s, print_screen=True) self.pyamiE = None pass pass
def get(self, handle_no_ioc=True): """ returns current value for the Pv """ if (is_debug_on()): logprint("caget %s: " % self.name) try: pycaPv.get(self, False, time_out_get) self.last_update = self.timestr() if (is_debug_on()): logprint("got %s\n" % self.value.__str__()) return self.value except pyca.pyexc: logprint("caget %s: " % self.name, newline=False) logprint("failed (PV timed out) !!, returning nan") return numpy.nan
def move(self, value): if ((value < self.get_lowlim()) or (value > self.get_hilim())): logprint("Asked to move %s (pv %s) outside limit, aborting" % (self.name, self.pvname), print_screen=1) return self.wm() (status, msg) = self.check_limit_switches() if ((status == "high") and (value > self.wm())): logprint(msg + ",aborting", print_screen=1) return self.wm() elif ((status == "low") and (value < self.wm())): logprint(msg + ",aborting", print_screen=1) return self.wm() logprint("moving %s (pv %s) to %f, previous position: %f" % (self.name, self.pvname, value, self.wm())) return pypsepics.put(self.pvname, value)
def moveX(self,x): if ((x<=self.__lowlimX)or(x>=self.__hilimX)): logprint("Asked to move %s (pv %s) outside limit, aborting" % (self.XT.name,self.XT.pvname),print_screen=1) else: try: x1=xTox12(x) x2=xTox12(x) z=xToz(x) z_now=self.z.wm() if z>z_now: print 'moving z to %+4.f\n' % z self.z.mv(z) self.z.wait() print 'moving x1 to %+4.f and x2 to %.4f\n' % (x1,x2) self.x1.mv(x1);self.x2.mv(x2) else: print 'moving x1 to %+4.f and x2 to %.4f\n' % (x1,x2) self.x1.mv(x1);self.x2.mv(x2) self.x1.wait();self.x2.wait() print 'moving z to %+4.f\n' % z self.z.mv(z) except KeyboardInterrupt: self.stop()
def dial_delay_new(self, value=None): '''Seems to do exactly the same as dial_delay. Not sure what the difference is and cant be bothered now''' if (value is None): return pypsepics.get(self.__pv_angleshift_rbv) * 1e-15 else: #m = 0; M=14.7e-9 m = 0 M = 19.2e-9 if ((value < m) or (value > M)): logprint( "Phase shifter has a range (%.2e,%.2e), asked for %.3e, aborting" % (m, M, value), print_screen=True) return self.__desired_value = value if abs(pypsepics.get(self.__pv_angleshift_rbv) * 1e-15 - value) > 5e-12: self.lowgain() pypsepics.put(self.__pv_angleshift, int(value * 1e15)) self.wait() self.higain() else: pypsepics.put(self.__pv_angleshift, int(value * 1e15)) return
def move(self, value): self.__user_desidered_pos = value if ((value < self.get_lowlim()) or (value > self.get_hilim())): logprint( "Asked to move %s (pv %s) to %f, limits are %f-%f, aborting" % (self.name, self.pvname, value, self.get_lowlim(), self.get_hilim()), print_screen=1) return self.wm() (status, msg) = self.check_limit_switches() if ((status == "high") and (value > self.wm())): logprint(msg + ",aborting", print_screen=1) return self.wm() elif ((status == "low") and (value < self.wm())): logprint(msg + ",aborting", print_screen=1) return self.wm() logprint("moving %s (pv %s) to %f, previous position: %f" % (self.name, self.pvname, value, self.wm())) #return pypsepics.put(self.pvname,value) return self.put_par("drive", value)
def move_dial(self, value): try: if ((value < self.get_dial_lowlim()) or (value > self.get_dial_hilim())): logprint("Asked to move %s (pv %s) outside limit, aborting" % (self.name, self.pvname), print_screen=1) return self.wm_dial() (status, msg) = self.check_limit_switches() if ((status == "high") and (value > self.wm_dial())): logprint(msg, print_screen=1) return self.wm_dial() elif ((status == "low") and (value < self.wm_dial())): logprint(msg, print_screen=1) return self.wm_dial() except: pass return pypsepics.put(self.__dialpv, value)
def err_log(self,k,msg): logprint("%s: %s" % (k,msg))
def monitor_stop_all(clear=False): """ stop monitoring for all PVs defined in cache list """ for pv in g_pv_chache_list: g_pv_chache_list[pv].monitor_stop() if (clear): g_pv_chache_list[pv].monitor_clear() logprint("stopping monitoring for %s" % pv)
def monitor_clear(self): """ clear the `values` list """ self.values = [] if (is_debug_on()): logprint("clear monitoring for %s" % self.name)
def monitor_stop(self): """ stop monitoring for the Pv, note that this does not clear the `values` list """ self.unsubscribe() self.ismonitored = False if (is_debug_on()): logprint("stop monitoring for %s" % self.name)
def put(self, value): """ put value to the Pv, returns the value itself """ if (is_debug_on()): logprint("caput %s in %s\n" % (value, self.name)) pycaPv.put(self, value, time_out_get) return value