is_panel = get_exec_pars().source != CommandSource.ui #Must be checked before callin "run" run("Devices/Elements") run("Devices/WireScanner") BPM_SENSORS = [("x","X1"), ("y","Y1"), ("q","Q1")] #(logic name sufix, channel sufix) #Paramter parsing prefix = args[0] if is_panel else "S30CB09-DWSC440" scan_type = args[1] if is_panel else WireScanner.WireX1 scan_range = args[2] if is_panel else [-200, 200] cycles = args[3] if is_panel else 5 velocity = args[4] if is_panel else 200 bpms = args[5] if is_panel else get_wire_scans_bpms(prefix) print "WireScan parameters: ", prefix, scan_type, scan_range, cycles, cycles, bpms #Creating WireScanner object print "Creating scanner..." if prefix not in get_wire_scans(): raise Exception("Invalid wire scan: " + prefix) scanner = WireScanner(prefix, scan_range, cycles, velocity, True) scanner.set_selection(get_scan_selection(scan_type)) scanner.init() scanner.waitValue("At start", 60000) #List of stream channels channels = [("m_pos", scanner.motor_bs_readback.get_name()), ("cur_cycle", scanner.curr_cycl.get_name()), ("scanning", scanner.status_channels[0].get_name())] #bpms = ["SINDI01-DBPM060", "SINDI02-DBPM010"] #For testing for i in range (len(bpms)): for sensor in BPM_SENSORS: channels.append (("bpm" + str(i+1) + "_" + sensor[0], bpms[i] + ":" + sensor[1])) #Stream creation print "Starting stream..." st = Stream("pulse_id", dispatcher) scanner.curr_cycl.write(0) st.setFilter(scanner.curr_cycl.get_name() + ">0") #scanner.status_channels[0].get_name() + ">0" not used because we must the transition to know when the finished for c in channels: st.addScalar(c[0], c[1], 10, 0) st.initialize() st.start() st.waitCacheChange(10000) #Wait stream be running before starting scan #Pseudo-device returning the wire position class w_pos(Readable): def read(self): return scanner.get_sel_wire_pos(st.getChildren()[0].take()) #End of scan checking scan_complete = None cur_cycle = None def check_end_scan(record, scan): global scan_complete,cur_cycle if record[3]<1: print "Data aquisition completed" scan_complete=True scan.abort() record.cancel() #So it won't be saved elif record[2] != cur_cycle: cur_cycle = record[2] get_context().dataManager.splitScanData(scan) #Metadata set_attribute("/", "Wire Scan", prefix) set_attribute("/", "Scan Type", scan_type) set_attribute("/", "Range", scan_range) set_attribute("/", "Cycles", cycles) set_attribute("/", "Velocity", velocity) #Scan def do_scan(): global scan_complete, cur_cycle scan_complete=False cur_cycle = 1 try: scanner.scan() #scanner.waitState(State.Busy, 60000) Not needed as stream filter will make the wait mscan (st, [w_pos()] + st.getReadables(), -1, -1, after_read = check_end_scan) except: if not scanner.isReady(): print "Aborting scan" scanner.abort() if not scan_complete: raise print "Starting scan..." try: set_exec_pars(group=scan_type in [WireScanner.WireY1, WireScanner.WireY1] ? "y_{count}" : "x_{count}"); do_scan() if scan_type in [WireScanner.Set1, WireScanner.Set2]: scanner.set_selection(get_scan_selection(scan_type)) scanner.curr_cycl.write(0) scanner.set_selection(get_scan_selection(scan_type, 1)) scanner.init() scanner.waitValue("At start", 60000) set_exec_pars(group="y_{count}", reset=True) do_scan() finally: print "Closing scanner" scanner.close() print "Closing stream" st.close()