def switch(self): """ switches illuminator """ onoff = pypsepics.get(self.pv_OnOff) if onoff == 1: pypsepics.put(self.pv_OnOff, 1) elif onoff == 0: pypsepics.put(self.pv_OnOff, 0)
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 __init__(self, local_iocbase="SXR:ECS:IOC:01:", sequence_group=4): #self.iocbase = "IOC:IN20:EV01:ECS" self.iocbase = "ECS:SYS0:%d" % (sequence_group) self.local_iocbase = local_iocbase self.sequence_group = sequence_group self.__mode = ["Once", "Repeat N Times", "Repeat Forever"] self.__status = ["Stopped", "Waiting", "Playing"] self.__beamrate = "EVNT:SYS0:1:LCLSBEAMRATE" self.define_pvnames() self.dictRateToSyncMarker = { 0.5: 0, 1: 1, 5: 2, 10: 3, 30: 4, 60: 5, 120: 6, 360: 7, 0: 6 } self.setSyncMarker(self.beamrate()) pypsepics.put(self.__pv_beamrequest, 0) # TimeSlot self.maxEventCount = 2048 self.__ec = [0] * self.maxEventCount self.__bd = [0] * self.maxEventCount self.__fd = [0] * self.maxEventCount self.__bc = [0] * self.maxEventCount
def set_burst_rate(self, rate): if not (rate in self.__dictRateToEnum): print "!! Rate should be one of:", print self.__dictRateToEnum.keys() else: pypsepics.put("PATT:SYS0:1:MPSBURSTRATE", self.__dictRateToEnum[rate])
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 set_fburst(self, f="Full"): f.replace(" ", "") # remove spaces if not (f in self.__freqs): print "!! Frequency should be one of:", print self.__freqs.keys() else: pypsepics.put("PATT:SYS0:1:MPSBURSTRATE", self.__freqs[f])
def speed(self, value=None): if (value is not None): pypsepics.put(self.speed_pv, value) if (self.speed_rbv is None): s = pypsepics.get(self.speed_pv) else: s = pypsepics.get(self.speed_rbv) return s
def period(self, periodval=None): """Set the collection preriod""" if periodval == None: return pypsepics.get(self._pvperiod + "_RBV") elif 0 < periodval <= 10: pypsepics.put(self._pvperiod, periodval) else: print('period out of range (0,10)')
def gain(self, gainval=None): '''set the gain of camera, or reads back gain if no value is passed''' if gainval == None: return pypsepics.get(self._pvgain + "_RBV") elif 0 <= gainval <= 32: pypsepics.put(self._pvgain, round(gainval)) else: print('gain out of range (0,32)')
def set_testburst_rate(self, rate): dictRateToEnum = {0.5: 5, 1: 4, 5: 3, 10: 2, 30: 1, 120: 0, 0: 0} if not (rate in dictRateToEnum): print "!! Rate should be one of:", print dictRateToEnum.keys() else: pypsepics.put(self.__pv_testburst_dep, 0) pypsepics.put(self.__pv_testburst_rate, dictRateToEnum[rate])
def __move(self, pos): pypsepics.put(self.__pvbase + ":GO", 0) pypsepics.put(self.__pvbase + ":STOP", 1) pypsepics.put(self.__pvbase + ":CTRL_POS", int(pos * 1.0e6 / self.__getstepsize())) pypsepics.put(self.__pvbase + ":GO", 1) pypsepics.put(self.__pvbase + ":STOP", 0) pass
def reset(self): '''resets the ioc of the camera, if the soic_pv is defined''' if self._soic_pv != None: pypsepics.put(self._soic_pv + ":SYSRESET", 1) else: print( "No SOIC pvname defined. Change self._soic_pv to correct iocname" )
def moveDSPhi(self, phi): """ Move physical motors in sample/detector stages to get Phi reflection geometry """ if not self.assertLimitsDSPhi(phi): return self.reflectdet.move_silent(phi) self.phi.move_silent(phi) if self.pvBase is not None: pypsepics.put(self.pvBase + ":GON:REF", phi) pass
def wm(self): if (self.pvoff is None): offset=0 else: offset=pypsepics.get(self.pvoff) user = self.direction*self.wm_dial()+offset if (self.pvpos is not None): pypsepics.put(self.pvpos,user) return user
def __set_offset(self, value): '''Writes the value to the PV that holds the offset value. The value is a motor position in mm. The offset is the motor value on the delay stage that will result in time delay calculation of 0 (i.e. put the delay motor at the offset value and the delay() command will return 0) ''' pypsepics.put(self._offset_pv, value)
def move(self, position): if position in self.__positionMap: curpos = self.__getPosition() if curpos == positoin: print "WARNING: Stopper is already %s\n" % (position) else: pypsepics.put(self.__getPV(self.__cmdPV), position) else: print "ERROR: '%s' is not a valid position, please use one of: %s\n" % (position,__positionMap.keys())
def gain(self, value=None): ''' Reads or changes gain in the PD feedback loop usage: gain(): reads back current gain gain(value): sets gain to passed value ''' if (value is None): return pypsepics.get(self.__pv_gain) else: pypsepics.put(self.__pv_gain, value)
def exposuretime(self, expval=None): """Set the exposure time""" period = pypsepics.get(self._pvperiod + "_RBV") if expval == None: return pypsepics.get(self._pvtime + "_RBV") elif 0 < expval <= period: pypsepics.put(self._pvtime, expval) else: print('exposure time out of range (0,%s)' % period)
def disableAllEventsForGivenTrigger(self, trigger): """ Disable all events code for a give trigger """ if (trigger > self.__ntriggers - 1): print "in disableAllEventsForGivenTrigger you asked for a trigger that is not defined ... exiting" return 0 for i in range(self.__nevent_numbers): names = self.__getpvnames(i + 1) # starts with 1 and not zero pypsepics.put(names[trigger], 0) return 1
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 set(self,value): if (self.__set is not None): self.__set(value) elif (self.pvoff is not None): offset = value - self.direction*self.wm_dial() pypsepics.put(self.pvoff,offset) sleep(0.1); # gives epics time to update offset pv self.wm() else: print "user position not defined for this motor"
def get_burst(self, n=None, wait=False): if n is not None: self.set_nburst(n) time.sleep(0.03) # make sure PV is written before executing # if wait: # pypsepics. pypsepics.put("PATT:SYS0:1:MPSBURSTCTRL", 1)
def delay_abs(self,delay=None): '''reads back the delay, if no argument is passed, or sets delay when argument passed useage: .delay_abs() : reads back absolute qswitch delay, in s .delay_abs(258.434e-6) : sets delay to 258.434microseconds checks wether delay is between the low_lim and high_lim ''' if delay==None: delay_read=pypsepics.get(self._pvbase+'DelaySI') return float(delay_read[5:]) else: if self._low_lim < delay < self._high_lim: pypsepics.put(self._pvbase+'DelayAO',delay) else: print('Delay outside of allowed range')
def moveDetPhi(self, phi): """ Move Detector to phi reflection (2*phi). This requires translating det-y and rotating det-gamma """ self.checkDetPhiConfig() if not self.assertLimitsDetPhi(phi): return tphi = 2. * phi y_off = -1. * self.detCenOffset * math.tan(tphi * math.pi / 180.) print "moving gam,dy to %f,%f" % (tphi, y_off) self.gam.move_silent(tphi) self.dy.move_silent(y_off) if self.pvBase is not None: pypsepics.put(self.pvBase + ":GON:REFD", phi) pass
def level(self, level='status'): """changes illumination level""" if level is "status": volt = pypsepics.get(self.pv_Volt) level = (volt - self.Vlow) / (self.Vhigh - self.Vlow) return level else: level = float(level) if level > 1: level = level / 100. print 'Illuminator Level was interpreted as percent' levelinvolt = self.Vlow + level * (self.Vhigh - self.Vlow) pypsepics.put(self.pv_Volt, levelinvolt)
def delay(self, value=None): '''return the current delay of the X-rays with respect to laser if value is None. If a value is passed, the delay is change to that value. All values in seconds. ''' if value == None: delay_value = self.get_offset() - self.dial_delay() if self._delay_pv_name != None: pypsepics.put(self._delay_pv_name, delay_value) return delay_value else: self.dial_delay(self.get_offset() - value) if self._delay_pv_name != None: pypsepics.put(self._delay_pv_name, value)
def moveEn(self, energy): """ Move Energy to value -> Analyzer crystal to according theta, detector to 2theta """ self.energy = energy th = convertEnergyToAngle(energy) print "moving th, tth to %f,%f" % (th,2 * th) self.ath.move_silent(th) self.atth.move_silent(2 * th) if self.pvBase is not None: #Fix this: #pypsepics.put(self.pvBase + ":EN:REFD",energy) #print "putting energy" pypsepics.put(self.pvBase + ":710:Analyzer_Energy.VAL",energy) pass pass
def dial_delay(self, value=None): '''return the current delay if value is None. If a value is passed, the delay is change to that value. All values in seconds. The returned values are those directly read of the DG645, without offset taken into account. ''' if value == None: delay_read = pypsepics.get(self._pvbase + 'DelaySI') return double(delay_read[5:]) elif self._low_lim < value < self._high_lim: pypsepics.put(self._pvbase + 'DelayAO', value) else: print('Delay outside of allowed range')
def setDefaultsForTrigger(self, trigger): """ Set EVR defaults for a given trigger (including mapping trigger#i->out#i""" self.EVReventCode.setDefaultsForTrigger(trigger) pypsepics.put(self.ioc + ":CTRL.ENAB", 1) #enable card self.assignOutToTrigger(trigger, trigger) # assign out #i to trigger #i self.change("enable", 1, trigger) # enable trigger #i self.change("polarity", 0, trigger) # polarity normal for trigger #i self.change("prescale", 1, trigger) # default prescaler for trigger #i self.setWidth(1e-3, trigger) self.setDelay(1e-3, trigger)
def __move(self, pos): ll = self.get_lowlim() lh = self.get_hilim() if (pos < ll): print "ERROR: Commanded position (%.3f) exceeds low soft-limit (%.3f)" % ( pos, ll) pass elif (pos > lh): print "ERROR: Commanded position (%.3f) exceeds high soft-limit (%.3f)" % ( pos, lh) pass else: pypsepics.put(self.pvname, pos) self.__commanded_position = pos pass pass