import ch.psi.pshell.epics.ControlledVariable as ControlledVariable if get_exec_pars().source == CommandSource.ui: start = -180.0 stop = 180.0 step = 5.0 nb = 1 lat = 0.100 else: start = args[0] stop = args[1] step = args[2] nb = int(args[3]) lat = args[4] #phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-VSUM-PHASE", "SINEG01-RSYS:GET-VSUM-PHASE") phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-VSUM-PHASE", "SINEG01-RSYS:SET-VSUM-PHASE") phase.config.minValue =-180.0 phase.config.maxValue = 180.0 phase.config.precision = 3 phase.config.resolution = 1.0 phase.config.save() phase.initialize() #st = Stream("ICTstream", dispatcher) #q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0) #st.initialize() #st.start(True) q = Channel("SINEG01-DICT215:B1_CHARGE", type = 'd', alias='ICT-Q') phase0 = phase.read() print phase0 try: qb = create_averager(q, nb, 0.100) r = lscan(phase, (qb), start, stop, step, latency=lat) rf_phase = r.getPositions(0) charge = [val.mean for val in r.getReadable(0)] chargerms = [val.stdev for val in r.getReadable(0)] finally: phase.write(phase0) phase.close() #st.close() q.close() #Setting the return value y = charge x = rf_phase index_max = y.index(max(y)) phase_ref = x[index_max] - 80 set_return(phase_ref)