def set_recorder_data_type(self, *motor_data_type): """ Configure the data recorder Args: motor_data_type should be a list of tuple with motor and datatype i.e: motor_data_type=[px,px.CURRENT_POSITION_OF_AXIS, py,py.CURRENT_POSITION_OF_AXIS] """ nb_recorder_table = len(motor_data_type) / 2 if nb_recorder_table * 2 != len(motor_data_type): raise RuntimeError("Argument must be grouped by 2 " "(motor1,data_type1,motor2,data_type2...)") self.command("SPA 1 0x16000300 %d" % nb_recorder_table) max_nb_recorder = int(self.command("TNR?")) if nb_recorder_table > max_nb_recorder: raise RuntimeError( "Device %s too many recorder data, can only record %d" % (self.name, max_nb_recorder)) cmd = "DRC " cmd += ' '.join( ('%d %s %d' % (rec_id + 1, motor.channel, data_type) for rec_id, ( motor, data_type) in enumerate(grouped(motor_data_type, 2)))) self.command(cmd)
def _simultaneous_rmove(self, *args): axis_list = [] targets = [] for axis, target in grouped(args, 2): axis_list.append(axis) targets.append(axis.position() + target) g = Group(*axis_list) g.move(dict(zip(axis_list, targets)))
def _simultaneous_rmove(self, *args): axis_list = [] targets = [] for axis, target in grouped(args, 2): axis_list.append(axis) targets.append(axis.position()+target) g = Group(*axis_list) g.move(dict(zip(axis_list,targets)))
def __init__(self, nb_point, *args, **keys): if len(args) % 3: raise TypeError( 'LinearStepTriggerMaster: argument is a nb_point,mot1,start1,stop1,mot2,start2,stop2,...') params = list() for axis, start, stop in grouped(args, 3): params.extend((axis, start, stop, nb_point)) _StepTriggerMaster.__init__(self, *params, **keys)
def _send(self): while(1): self._send_event.wait() self._send_event.clear() #local transfer pending_subscribe = self._pending_subscribe pending_unsubscribe = self._pending_unsubscribe pending_channel_value = self._pending_channel_value pending_init = self._pending_init pubsub = self._pubsub self._pending_subscribe = list() self._pending_unsubscribe = list() self._pending_channel_value = OrderedDict() self._pending_init = list() if pending_unsubscribe: pubsub.unsubscribe(pending_unsubscribe) no_listener_4_values = set() if pending_subscribe: result = self._redis.execute_command('pubsub','numsub',*pending_subscribe) no_listener_4_values = set((name for name,nb_listener in grouped(result,2) if int(nb_listener) == 0)) pubsub.subscribe(pending_subscribe) for channel_name in pending_subscribe: for waiting_event in self._wait_event.get(channel_name,set()): waiting_event.set() if self._listen_task is None: self._listen_task = gevent.spawn(self._listen) if pending_channel_value: pipeline = self._redis.pipeline() for name,channel_value in pending_channel_value.iteritems(): try: pipeline.publish(name,cPickle.dumps(channel_value,protocol=-1)) except cPickle.PicklingError: exctype,value,traceback = sys.exc_info() message = "Can't pickle in channel <%s> %r with values <%r> " % \ (name,type(channel_value.value),channel_value.value) sys.excepthook(exctype,message,traceback) pipeline.execute() if pending_init: pipeline = self._redis.pipeline() for name,default_value in pending_init: if name in CHANNELS_VALUE: # we got an update continue if name not in no_listener_4_values: pipeline.publish(name,cPickle.dumps(ValueQuery(),protocol=-1)) else: # we are alone CHANNELS_VALUE[name] = _ChannelValue(time.time(),default_value) for waiting_event in self._wait_event.get(name,set()): waiting_event.set() pipeline.execute()
def move_motors(self, *args): """Simultaneous move for all the listed motors. Args: motor,position(list): motor_object0, position0, motor_object1, ... """ par = "" for axis, target in grouped(args, 2): par += "%s=%f," % (axis.root_name, target) self._exporter.execute("startSimultaneousMoveMotors", par) self._wait_ready(20)
def __init__(self, nb_point, *args, **keys): if len(args) % 3: raise TypeError( 'LinearStepTriggerMaster: argument is a nb_point,mot1,start1,stop1,mot2,start2,stop2,...' ) params = list() for axis, start, stop in grouped(args, 3): params.extend((axis, start, stop, nb_point)) _StepTriggerMaster.__init__(self, *params, **keys)
def axis_group_move(self, axes_pos): axes = map(get_bliss_obj, axes_pos[::2]) axes_positions = map(float, axes_pos[1::2]) axes_pos_dict = dict(zip(axes, axes_positions)) group = Group(*axes) event.connect(group, 'move_done', self.__on_axis_group_move_done) group.move(axes_pos_dict, wait=False) group_id = ','.join(map(':'.join, grouped(axes_pos, 2))) self.group_dict[group_id] = group return group_id
def get_values(self, from_index, *counters): result_size = self.controller._proxy.ResultSize all_result = self.controller._proxy.GetResults(from_index) nb_result = len(all_result) / result_size counter2index = [(numpy.zeros((nb_result,)), self.controller._name2index[cnt.name]) for cnt in counters] for i, raw in enumerate(grouped(all_result, result_size)): for res, j in counter2index: res[i] = raw[j] return [x[0] for x in counter2index]
def get_values(self, from_index, *counters): result_size = self.controller._proxy.ResultSize all_result = self.controller._proxy.GetResults(from_index) nb_result = len(all_result) / result_size counter2index = [(numpy.zeros( (nb_result, )), self.controller._name2index[cnt.name]) for cnt in counters] for i, raw in enumerate(grouped(all_result, result_size)): for res, j in counter2index: res[i] = raw[j] return [x[0] for x in counter2index]
def pos_read(self): self.connect() state = list(grouped(itertools.chain(*self.wago.get("status")), 2)) if self.read_mode != 0: state.reverse() bits = 0 for i, (s, t) in enumerate(state): if i in self.empty_jacks: continue if s and not t: bits += 1<<i #(1 << n-i) return bits
def GroupMove(self, axes_pos): """ Absolute move multiple motors """ axes_dict = self._get_axis_devices() axes_names = axes_pos[::2] if not set(axes_names).issubset(set(axes_dict)): raise ValueError("unknown axis(es) in motion") axes = [axes_dict[name].axis for name in axes_names] group = Group(*axes) event.connect(group, 'move_done', self.group_move_done) positions = map(float, axes_pos[1::2]) axes_pos_dict = dict(zip(axes, positions)) group.move(axes_pos_dict, wait=False) groupid = ','.join(map(':'.join, grouped(axes_pos, 2))) self.group_dict[groupid] = group return groupid
def __init__(self, *args, **keys): trigger_type = keys.pop('trigger_type', AcquisitionMaster.SOFTWARE) self.next_mv_cmd_arg = list() if len(args) % 4: raise TypeError( '_StepTriggerMaster: argument is a mot1,start,stop,nb points,mot2,start2...') self._motor_pos = list() self._axes = list() for axis, start, stop, nb_point in grouped(args, 4): self._axes.append(axis) self._motor_pos.append(numpy.linspace(start, stop, nb_point)) mot_group = Group(*self._axes) group_name = '/'.join((x.name for x in self._axes)) AcquisitionMaster.__init__(self, mot_group, group_name, trigger_type=trigger_type, **keys) self.channels.extend( (AcquisitionChannel(axis.name, numpy.double, ()) for axis in self._axes))
def __init__(self, *args, **keys): trigger_type = keys.pop('trigger_type', AcquisitionMaster.SOFTWARE) self.next_mv_cmd_arg = list() if len(args) % 2: raise TypeError('_VariableStepTriggerMaster: argument is a mot, positions ...') self._motor_pos = list() self._axes = list() for _axis, pos_list in grouped(args, 2): self._axes.append(_axis) self._motor_pos.append(pos_list) mot_group = Group(*self._axes) group_name = '/'.join((x.name for x in self._axes)) AcquisitionMaster.__init__(self, mot_group, group_name, trigger_type=trigger_type, **keys) self.channels.extend( (AcquisitionChannel(axis.name, numpy.double, ()) for axis in self._axes))
def move(self, *args, **kwargs): initial_state = self.state() if initial_state != "READY": raise RuntimeError("all motors are not ready") self._reset_motions_dict() self.__move_task = None wait = kwargs.pop("wait", True) relative = kwargs.pop("relative", False) polling_time = kwargs.pop("polling_time", DEFAULT_POLLING_TIME) axis_pos_dict = dict() if len(args) == 1: axis_pos_dict.update(args[0]) else: for axis, target_pos in grouped(args, 2): axis_pos_dict[axis] = target_pos for axis, target_pos in axis_pos_dict.iteritems(): motion = axis.prepare_move(target_pos, relative=relative) if motion is not None: axis._in_group_move = True # motion can be None if axis is not supposed to move, # let's filter it self._motions_dict.setdefault(axis.controller, []).append(motion) all_motions = self._start_motion(self._motions_dict) self.__move_done.clear() self.__move_task = self._handle_move(all_motions, polling_time, wait=False) self.__move_task._being_waited = wait self.__move_task._motions = all_motions self.__move_task.link(self._set_move_done) if wait: self.wait_move()
def move(self, *args, **kwargs): initial_state = self.state() if initial_state != "READY": raise RuntimeError("all motors are not ready") self._reset_motions_dict() self.__move_task = None wait = kwargs.pop("wait", True) relative = kwargs.pop("relative", False) polling_time = kwargs.pop("polling_time", DEFAULT_POLLING_TIME) axis_pos_dict = dict() if len(args) == 1: axis_pos_dict.update(args[0]) else: for axis, target_pos in grouped(args, 2): axis_pos_dict[axis] = target_pos for axis, target_pos in axis_pos_dict.iteritems(): motion = axis.prepare_move(target_pos, relative=relative) if motion is not None: axis._in_group_move = True # motion can be None if axis is not supposed to move, # let's filter it self._motions_dict.setdefault( axis.controller, []).append( motion) all_motions = self._start_motion(self._motions_dict) self.__move_done.clear() self.__move_task = self._handle_move(all_motions, polling_time, wait=False) self.__move_task._being_waited = wait self.__move_task._motions = all_motions self.__move_task.link(self._set_move_done) if wait: self.wait_move()
def __init__(self, *args, **keys): trigger_type = keys.pop('trigger_type', AcquisitionMaster.SOFTWARE) self.next_mv_cmd_arg = list() if len(args) % 4: raise TypeError( '_StepTriggerMaster: argument is a mot1,start,stop,nb points,mot2,start2...' ) self._motor_pos = list() self._axes = list() for axis, start, stop, nb_point in grouped(args, 4): self._axes.append(axis) self._motor_pos.append(numpy.linspace(start, stop, nb_point)) mot_group = Group(*self._axes) group_name = '/'.join((x.name for x in self._axes)) AcquisitionMaster.__init__(self, mot_group, group_name, trigger_type=trigger_type, **keys) self.channels.extend((AcquisitionChannel(axis.name, numpy.double, ()) for axis in self._axes))
def __init__(self, *args, **keys): trigger_type = keys.pop('trigger_type', AcquisitionMaster.SOFTWARE) self.next_mv_cmd_arg = list() if len(args) % 2: raise TypeError( '_VariableStepTriggerMaster: argument is a mot, positions ...') self._motor_pos = list() self._axes = list() for _axis, pos_list in grouped(args, 2): self._axes.append(_axis) self._motor_pos.append(pos_list) mot_group = Group(*self._axes) group_name = '/'.join((x.name for x in self._axes)) AcquisitionMaster.__init__(self, mot_group, group_name, trigger_type=trigger_type, **keys) self.channels.extend((AcquisitionChannel(axis.name, numpy.double, ()) for axis in self._axes))
def set_recorder_data_type(self,*motor_data_type): """ Configure the data recorder Args: motor_data_type should be a list of tuple with motor and datatype i.e: motor_data_type=[px,px.CURRENT_POSITION_OF_AXIS, py,py.CURRENT_POSITION_OF_AXIS] """ nb_recorder_table = len(motor_data_type) / 2 if nb_recorder_table * 2 != len(motor_data_type): raise RuntimeError("Argument must be grouped by 2 " "(motor1,data_type1,motor2,data_type2...)") self.command("SPA 1 0x16000300 %d" % nb_recorder_table) max_nb_recorder = int(self.command("TNR?")) if nb_recorder_table > max_nb_recorder: raise RuntimeError("Device %s too many recorder data, can only record %d" % (self.name,max_nb_recorder)) cmd = "DRC " cmd += ' '.join(('%d %s %d' % (rec_id+1,motor.channel,data_type) for rec_id,(motor,data_type) in enumerate(grouped(motor_data_type,2)))) self.command(cmd)
def _simultaneous_move(self, *args): axis_list = [] for axis, target in grouped(args, 2): axis_list.append(axis) g = Group(*axis_list) g.move(*args)
def _simultaneous_rmove(self, *args): axis_list = [] for axis, target in grouped(args, 2): axis_list.append(axis) axis.rmove(target, wait=False) return [axis.wait_move() for axis in axis_list]
def _send(self): while (1): self._send_event.wait() self._send_event.clear() #local transfer pending_subscribe = self._pending_subscribe pending_unsubscribe = self._pending_unsubscribe pending_channel_value = self._pending_channel_value pending_init = self._pending_init pubsub = self._pubsub self._pending_subscribe = list() self._pending_unsubscribe = list() self._pending_channel_value = OrderedDict() self._pending_init = list() if pending_unsubscribe: pubsub.unsubscribe(pending_unsubscribe) no_listener_4_values = set() if pending_subscribe: result = self._redis.execute_command('pubsub', 'numsub', *pending_subscribe) no_listener_4_values = set( (name for name, nb_listener in grouped(result, 2) if int(nb_listener) == 0)) pubsub.subscribe(pending_subscribe) for channel_name in pending_subscribe: for waiting_event in self._wait_event.get( channel_name, set()): waiting_event.set() if self._listen_task is None: self._listen_task = gevent.spawn(self._listen) if pending_channel_value: pipeline = self._redis.pipeline() for name, channel_value in pending_channel_value.iteritems(): try: pipeline.publish( name, cPickle.dumps(channel_value, protocol=-1)) except cPickle.PicklingError: exctype, value, traceback = sys.exc_info() message = "Can't pickle in channel <%s> %r with values <%r> " % \ (name,type(channel_value.value),channel_value.value) sys.excepthook(exctype, message, traceback) pipeline.execute() if pending_init: pipeline = self._redis.pipeline() for name, default_value in pending_init: if name in CHANNELS_VALUE: # we got an update continue if name not in no_listener_4_values: pipeline.publish( name, cPickle.dumps(ValueQuery(), protocol=-1)) else: # we are alone CHANNELS_VALUE[name] = _ChannelValue( time.time(), default_value) for waiting_event in self._wait_event.get(name, set()): waiting_event.set() pipeline.execute()