def takeEmptyShots(self, nshots, shotspacing, use_daq=False, record=None): calibcontrols = { 'nshots': ConfigVal(nshots), 'shotspacing': ConfigVal(shotspacing) } if shotspacing > 0: self._prepSpacedNonMagShots(nshots, shotspacing) else: self._prepNonMagShots(nshots) #configure daq if being used if use_daq: daq.record = record daq.configure(events=0, controls=calibcontrols) try: if use_daq: daq.begin(events=nshots, controls=calibcontrols) seq.start() self.seq_wait() if use_daq: daq.wait() except KeyboardInterrupt: seq.stop() finally: if use_daq: daq.record = None daq.disconnect()
def takeEmptyShots(self, nshots, shotspacing, use_daq=False, record=None): self.nshots.value = nshots self.shotspacing.value = shotspacing calibcontrols=[ (self.nshots), (self.shotspacing) ] if shotspacing > 0: self._prepSpacedNonMagShots(self.nshots.value, self.shotspacing.value) else: self._prepNonMagShots(self.nshots.value) #configure daq if being used if use_daq: daq.record = record daq.configure(events=0, controls=calibcontrols) try: if use_daq: daq.begin(event=nshots,controls=calibcontrols) seq.start() seq.pause() if use_daq: daq.wait() except KeyboardInterrupt: seq.stop() finally: if use_daq: daq.record = None daq.disconnect()
def go120Hz(self): try: daq.disconnect() except: print('DAQ might already be disconnected') lp('IN') pp.open() sync_mark = int(self._sync_markers[120]) seq.sync_marker.put(sync_mark) seq.play_mode.put(2) shot_sequence = [] shot_sequence.append([85, 0, 0, 0]) shot_sequence.append([87, 0, 0, 0]) seq.sequence.put_seq(shot_sequence) time.sleep(0.5) seq.start()
def gridScanAtt_Daq(self, motor, posList, sample, iRange, jRange, deltaX, snake=True): plan = self.gridScanAtt(motor, posList, sample, iRange, jRange, deltaX, snake) try: daq.disconnect() except: print('DAQ might be disconnected already') daq.connect() daq.begin() RE(plan) daq.end_run()
def dumbSnake(self, yStart, yEnd, xDelta, nRoundTrips, sweepTime): """ simple rastering for running at 120Hz with shutter open/close before and after motion stop. Need some testing how to deal with intermittent motion errors. """ #gon_sx.umv(xStart) sam_y.umv(yStart) daq.connect() daq.begin() time.sleep(2) print('Reached horizontal start position') # looping through n round trips for i in range(nRoundTrips): print('starting round trip %d' % (i + 1)) sam_y.mv(yEnd) time.sleep(0.5) pp.open() time.sleep(sweepTime) pp.close() sam_y.wait() sam_x.mvr(xDelta) time.sleep(2) #orignal was 1 sam_y.mv(yStart) time.sleep(0.5) pp.open() time.sleep(sweepTime) pp.close() sam_y.wait() sam_x.mvr(xDelta) time.sleep(2) #original was 1 print('xpos', sam_x.wm()) #print('round trip %d didn not end happily' % i) daq.end_run() daq.disconnect()
def takeMagnetShot(self, nemptyshots, emptyshotspacing=0, isfire=False, record=None): calibcontrols = { 'mag_isfire': ConfigVal(isfire), 'mag_trigger_delay': self.trigger_mag.ns_delay, 'mag_trig_width': self.trigger_mag.width, 'mag_trig_eventcode': self.trigger_mag.eventcode, 'nemptyshots': ConfigVal(nemptyshots), 'emptyshotspacing': ConfigVal(emptyshotspacing) } # check the machine burst rate and set to Full rate if not self.check_burst_rate() # disable BYKIK before taking shots lcls.bykik_disable() # check if emptyshotspacing is valid if 0 < emptyshotspacing < self._min_empty_delay: raise ValueError( "When using spacing between empty shots it must be >= %d" % self._min_empty_delay) spacer = "*********************************" print("\n%s\n* Preparing to take magnet shot *\n%s\n" % (spacer, spacer)) if emptyshotspacing > 0: mag_status = "Taking %d shots, with a spacing between each of %d beam pulses, before firing the magnet\n" % ( nemptyshots, emptyshotspacing) else: mag_status = "Taking %d shots before firing the magnet\n" % nemptyshots mag_status += "Magnet pulse eventcode: %d\n" % self.trigger_mag.get_eventcode( ) mag_status += "Magnet pulse trigger delay: %f\n" % self.trigger_mag.get_delay( ) mag_status += "Magnet pulse trigger width: %f\n" % self.trigger_mag.get_width( ) mag_status += "Magnet to be fired: %s\n" % isfire print(mag_status) try: daq.record = record daq.configure(events=0, controls=calibcontrols) # Pre empty shots if nemptyshots > 0: print("\nPreparing sequencer for pre-firing, non-magnet shots") if emptyshotspacing > 0: self._prepSpacedNonMagShots(nemptyshots, emptyshotspacing) else: self._prepNonMagShots(nemptyshots) time.sleep(self.pause_time) daq.begin(events=nemptyshots, controls=calibcontrols) print("\nTaking %d pre-firing, non-magnet shots\n" % nemptyshots) # pause after changing pulse picker mode time.sleep(self.pause_time) self._takeNonMagShots() print('Taking shots') self.seq_wait() print('seq finished') daq.wait() print('daq finished') else: print("\nSkipping prefiring, non-magnet shots\n") # pause after empty shots time.sleep(self.pause_time) print('sleep finished') # Fire the magnet sequence based on isfire flag if isfire: print("Start magnet firing sequence\n") else: print("Start magnet test 'firing' sequence\n") print("\nPreparing sequencer for magnet shot") if emptyshotspacing > 0: self._prepMagShot(isfire, emptyshotspacing) else: self._prepMagShot(isfire) time.sleep(self.pause_time) # pause after changing pulse picker mode time.sleep(self.pause_time) #checking ipm4?? num_tries = 0 i0_good = False while num_tries < self.i0_mag_retry: i0_val = self.i0_avg.get() if i0_val < self.i0_threshold: print( "\nNot firing magnet due to low beam current (ipm4): %.3f \n" % (i0_val)) backoff_time = 2**num_tries print("Sleeping for %d seconds...\n" % backoff_time) time.sleep(backoff_time) num_tries += 1 else: #ipm4 is good - fire! i0_good = True print("\nInitial intensity(ipm4) looks good: %.3f\n" % i0_val) break if not i0_good: print( "Max number of i0 checks (%d) exceeded! - Abort shot attempt.\n" % self.i0_mag_retry) return False # take the magnet shot daq.begin(events=1, controls=calibcontrols) print("\nTaking magnet shot\n") self._takeMagShot() self.seq_wait() daq.wait() #pause after magnet shots time.sleep(self.pause_time) #post empty shots if nemptyshots > 0: print( "\nPreparing sequencer for post-firing, non-magnet shots") if emptyshotspacing > 0: self._prepSpacedNonMagShots(nemptyshots, emptyshotspacing) else: self._prepNonMagShots(nemptyshots) time.sleep(self.pause_time) daq.begin(events=nemptyshots, controls=calibcontrols) print("\nTaking %d post-firing, non-magnet shots\n" % nemptyshots) # pause after changing pulse picker mode time.sleep(self.pause_time) self._takeNonMagShots() self.seq_wait() daq.wait() else: print("\nSkipping post-firing, non-magnet shots\n") return True except KeyboardInterrupt: seq.stop() daq.stop() return False finally: daq.record = None daq.disconnect() lcls.bykik_enable()