Exemple #1
0
 def check_error(self, cmd):
     # Check error code
     (_err_nb, _err_str) = self._get_error()
     if _err_nb != 0:
         _str = "ERROR on cmd \"%s\": #%d(%s)" % (cmd, _err_nb, _err_str)
         # by default, an exception will be raised
         elog.error(_str)
Exemple #2
0
 def read_position(self, axis):
     elog.debug("read_position() called")
     reply = self.__xps.GroupPositionCurrentGet(axis.group, self.__nbAxes)
     if reply[0] != 0:
         elog.error("NewportXPS Error: Failed to read position", reply[1])
     else:
         return reply[int(axis.channel)]
Exemple #3
0
 def read_position(self, axis):
     elog.debug("read_position() called")
     reply = self.__xps.GroupPositionCurrentGet(axis.group, self.__nbAxes)
     if reply[0] != 0:
         elog.error("NewportXPS Error: Failed to read position", reply[1])
     else:
         return reply[int(axis.channel)]
Exemple #4
0
    def __init__(self, *args, **kwargs):
        Controller.__init__(self, *args, **kwargs)

        self._axis_moves = {}

        self.factor = 1

        # config
        _target_attribute_name = self.config.get("target_attribute")
        _gating_ds = self.config.get("gating_ds")

        try:
            self.target_attribute = AttributeProxy(_target_attribute_name)
        except:
            elog.error("Unable to connect to attrtribute %s " %
                       _target_attribute_name)

        # External DS to use for gating.
        # ex: PI-E517 for zap of HPZ.
        if _gating_ds is not None:
            self.gating_ds = DeviceProxy(_gating_ds)
            self.external_gating = True
            elog.info("external gating True ; gating ds= %s " % _gating_ds)
        else:
            # No external gating by default.
            self.external_gating = False

        # _pos0 must be in controller unit.
        self._pos0 = self.target_attribute.read().value * self.factor
        elog.info("initial position : %g (in ctrl units)" % self._pos0)
Exemple #5
0
    def _set_closed_loop(self, axis, onoff = True):
        """
        Sets Closed loop status (Servo state) (SVO command)
        """

        axis.closed_loop = onoff
        self.command("SVO %s %d" % (axis.channel, onoff))
        elog.debug("Piezo Servo %r" % onoff)


        # Only when closing loop: waits to be ON-Target.
        if onoff:
            _t0 = time.time()
            cl_timeout = .5

            _ont_state = self._get_on_target_status(axis)
            elog.info(u'axis {0:s} waiting to be ONTARGET'.format(axis.name))
            while (not _ont_state) and (time.time() - _t0) < cl_timeout:
                time.sleep(0.01)
                print ".",
                _ont_state = self._get_on_target_status(axis)
            if not _ont_state:
                elog.error('axis {0:s} NOT on-target'.format(axis.name))
                raise RuntimeError("Unable to close the loop : "
                                   "not ON-TARGET after %gs :( " % cl_timeout)
            else:
                elog.info('axis {0:s} ONT ok after {1:g} s'.format(axis.name, time.time() - _t0))

        # Updates bliss setting (internal cached) position.
        axis._position()  # "POS?"
Exemple #6
0
 def stop(self, motion):
     elog.debug("stop() called")
     error, reply = self.__xps.GroupMoveAbort(motion.axis.group + '.' + motion.axis.name)
     if error == -22:
         elog.info("NewportXPS: All positioners idle")
     elif error != 0 and error != -22:
         elog.error("NewportXPS Error: ", reply)
Exemple #7
0
    def __init__(self, name, config, axes, encoders):
        Controller.__init__(self, name, config, axes, encoders)

        self._axis_moves = {}

        self.factor = 1

        # config
        _target_attribute_name = self.config.get("target_attribute")
        _gating_ds = self.config.get("gating_ds")

        try:
            self.target_attribute = AttributeProxy(_target_attribute_name)
        except:
            elog.error("Unable to connect to attrtribute %s " % _target_attribute_name)

        # External DS to use for gating.
        # ex: PI-E517 for zap of HPZ.
        if _gating_ds is not None:
            self.gating_ds = DeviceProxy(_gating_ds)
            self.external_gating = True
            elog.info("external gating True ; gating ds= %s " % _gating_ds)
        else:
            # No external gating by default.
            self.external_gating = False

        # _pos0 must be in controller unit.
        self._pos0 = self.target_attribute.read().value * self.factor
        elog.info("initial position : %g (in ctrl units)" % self._pos0)
Exemple #8
0
    def _set_closed_loop(self, axis, onoff=True):
        """
        Sets Closed loop status (Servo state) (SVO command)
        """

        axis.closed_loop = onoff
        self.command("SVO %s %d" % (axis.channel, onoff))
        elog.debug("Piezo Servo %r" % onoff)

        # Only when closing loop: waits to be ON-Target.
        if onoff:
            _t0 = time.time()
            cl_timeout = .5

            _ont_state = self._get_on_target_status(axis)
            elog.info(u'axis {0:s} waiting to be ONTARGET'.format(axis.name))
            while (not _ont_state) and (time.time() - _t0) < cl_timeout:
                time.sleep(0.01)
                print ".",
                _ont_state = self._get_on_target_status(axis)
            if not _ont_state:
                elog.error('axis {0:s} NOT on-target'.format(axis.name))
                raise RuntimeError("Unable to close the loop : "
                                   "not ON-TARGET after %gs :( " % cl_timeout)
            else:
                elog.info('axis {0:s} ONT ok after {1:g} s'.format(
                    axis.name,
                    time.time() - _t0))

        # Updates bliss setting (internal cached) position.
        axis._position()  # "POS?"
Exemple #9
0
 def set_velocity(self, axis, velocity):
     log.debug("set_velocity() called")
     if velocity > MAX_VELOCITY or velocity < MIN_VELOCITY:
         log.error("PM600 Error: velocity out of range")
     reply = self.io_command("SV", axis.channel, velocity)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to set_velocity" + reply)
Exemple #10
0
 def home_search(self, axis, switch):
     reply = self.io_command("DM00100000", axis.channel)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to datum mode" + reply)
     reply = self.io_command("HD", axis.channel, (+1 if switch > 0 else -1))
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to home to datum" + reply)
Exemple #11
0
 def set_firstvelocity(self, axis, creep_speed):
     log.debug("set_firstvelocity() called")
     if creep_speed > MAX_CREEP_SPEED or velocity < MIN_CREEP_SPEED:
         log.error("PM600 Error: creep_speed out of range")
     reply = self.io_command("SC", axis.channel, creep_speed)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to set_firstvelocity" + reply)
Exemple #12
0
 def set_deceleration(self, axis, deceleration):
     log.debug("set_deceleration() called")
     if deceleration > MAX_DECELERATION or deceleration < MIN_DECELERATION:
         log.error("PM600 Error: deceleration out of range")
     reply = self.io_command("SD", axis.channel, deceleration)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to set_deceleration" + reply)
Exemple #13
0
 def stop_all(self, *motion_list):
     elog.debug("stop_all() called")
     error, reply = self.__xps.GroupMoveAbort(motion_list[0].axis.group)
     if error == -22:
         elog.info("NewportXPS: All positioners idle")
     elif error != 0:
         elog.error("NewportXPS Error: ", reply)
Exemple #14
0
 def stop_all(self, *motion_list):
     elog.debug("stop_all() called")
     error, reply = self.__xps.GroupMoveAbort(motion_list[0].axis.group)
     if error == -22:
         elog.info("NewportXPS: All positioners idle")
     elif error != 0:
         elog.error("NewportXPS Error: ", reply)
Exemple #15
0
 def disable_position_compare(self, axis):
     """
     Disable output pulses on the PCO connector
     """
     motor_name = axis.group + "." + axis.name
     error, reply = self.__xps.PositionerPositionCompareDisable(motor_name)
     if error != 0:
         elog.error("NewportXPS Error: ", reply)
Exemple #16
0
 def start_all(self, *motion_list):
     elog.debug("start_all() called")
     target_positions = [0, 0]
     for motion in motion_list:
         target_positions[int(motion.axis.channel)-1] = motion.target_pos
     error, reply = self.__xps.GroupMoveAbsolute(motion.axis.group, target_positions)
     if error != 0:
         elog.error("NewportXPS Error: ", reply)
Exemple #17
0
 def set_velocity(self, axis, velocity):
     log.debug("set_velocity() called")
     if velocity > MAX_VELOCITY or velocity < MIN_VELOCITY:
         log.error("PM600 Error: velocity out of range")
     reply = self.io_command("SV", axis.channel, velocity)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to set_velocity" +
                   reply)
Exemple #18
0
 def set_firstvelocity(self, axis, creep_speed):
     log.debug("set_firstvelocity() called")
     if creep_speed > MAX_CREEP_SPEED or velocity < MIN_CREEP_SPEED:
         log.error("PM600 Error: creep_speed out of range")
     reply = self.io_command("SC", axis.channel, creep_speed)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to set_firstvelocity" +
                   reply)
Exemple #19
0
 def event_list(self, axis):
     error, reply = self.__xps.EventExtendedAllGet()
     if error == -83:
         elog.debug("NewportXPS: No events in list")
     elif error != 0:
         elog.error("NewportXPS Error: ", reply)
     else:
         elog.debug("Event id list: ", reply)
Exemple #20
0
 def disable_position_compare(self, axis):
     """
     Disable output pulses on the PCO connector
     """
     motor_name = axis.group + "." + axis.name
     error, reply = self.__xps.PositionerPositionCompareDisable(motor_name)
     if error != 0:
         elog.error("NewportXPS Error: ", reply)
Exemple #21
0
 def set_deceleration(self, axis, deceleration):
     log.debug("set_deceleration() called")
     if deceleration > MAX_DECELERATION or deceleration < MIN_DECELERATION:
         log.error("PM600 Error: deceleration out of range")
     reply = self.io_command("SD", axis.channel, deceleration)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to set_deceleration" +
                   reply)
Exemple #22
0
 def home_search(self, axis, switch):
     reply = self.io_command("DM00100000", axis.channel)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to datum mode" + reply)
     reply = self.io_command("HD", axis.channel, (+1 if switch > 0 else -1))
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to home to datum" +
                   reply)
Exemple #23
0
 def event_list(self, axis):
     error, reply = self.__xps.EventExtendedAllGet()
     if error == -83:
         elog.debug("NewportXPS: No events in list")
     elif error != 0:
         elog.error("NewportXPS Error: ", reply)
     else:
         elog.debug("Event id list: ", reply)
Exemple #24
0
 def stop(self, motion):
     elog.debug("stop() called")
     error, reply = self.__xps.GroupMoveAbort(motion.axis.group + '.' +
                                              motion.axis.name)
     if error == -22:
         elog.info("NewportXPS: All positioners idle")
     elif error != 0 and error != -22:
         elog.error("NewportXPS Error: ", reply)
Exemple #25
0
 def start_one(self, motion):
     elog.debug("start_one() called")
     self.cv_trigger(motion.axis)
     motor_name = motion.axis.group + "." + motion.axis.name
     error, reply = self.__xps.GroupMoveAbsolute(motor_name, [motion.target_pos, ])
     print("Reply:", reply)
     if error != 0:
         elog.error("NewportXPS Error: Unexpected response to move absolute", reply)
Exemple #26
0
 def read_acceleration(self, axis):
     elog.debug("read_acceleration() called")
     results = self.__xps.PositionerSGammaParametersGet(axis.group + '.' + axis.name)
     print(results)
     if results[0] != 0:
         elog.error("NewportXPS Error: Unexpected response to read acceleration", results[1])
     else:
         return results[2]
Exemple #27
0
 def set_acceleration(self, axis, acceleration):
     elog.debug("set_acceleration() called")
     error, reply = self.__xps.PositionerSGammaParametersSet(
         axis.group + '.' + axis.name, axis.velocity(), acceleration,
         axis.minJerkTime, axis.maxJerkTime)
     if error != 0:
         elog.error(
             "NewportXPS Error: Unexpected response to setting acceleration",
             reply)
Exemple #28
0
 def set_acceleration(self, axis, acceleration):
     elog.debug("set_acceleration() called")
     error, reply = self.__xps.PositionerSGammaParametersSet(axis.group + '.' + axis.name,
                                                             axis.velocity(),
                                                             acceleration,
                                                             axis.minJerkTime,
                                                             axis.maxJerkTime)
     if error != 0:
         elog.error("NewportXPS Error: Unexpected response to setting acceleration", reply)
Exemple #29
0
 def start_all(self, *motion_list):
     elog.debug("start_all() called")
     target_positions = [0, 0]
     for motion in motion_list:
         target_positions[int(motion.axis.channel) - 1] = motion.target_pos
     error, reply = self.__xps.GroupMoveAbsolute(motion.axis.group,
                                                 target_positions)
     if error != 0:
         elog.error("NewportXPS Error: ", reply)
Exemple #30
0
 def home_search(self, axis, switch):
     elog.debug("home_search() called")
     # Moves the motor to a repeatable starting location allows
     # homing only once after a power cycle.
     error, reply = self.__xps.GroupHomeSearch(axis.group)
     if error == 0:
         elog.info("NewportXPS: homing successful")
     elif error == -22:
         elog.info("NewportXPS: Controller already homed")
     else:
         elog.error("NewportXPS: Controller homing failed: ", error)
Exemple #31
0
 def home_search(self, axis, switch):
     elog.debug("home_search() called")
     # Moves the motor to a repeatable starting location allows
     # homing only once after a power cycle.
     error, reply = self.__xps.GroupHomeSearch(axis.group)
     if error == 0:
         elog.info("NewportXPS: homing successful")
     elif error == -22:
         elog.info("NewportXPS: Controller already homed")
     else:
         elog.error("NewportXPS: Controller homing failed: ", error)
Exemple #32
0
 def read_acceleration(self, axis):
     elog.debug("read_acceleration() called")
     results = self.__xps.PositionerSGammaParametersGet(axis.group + '.' +
                                                        axis.name)
     print(results)
     if results[0] != 0:
         elog.error(
             "NewportXPS Error: Unexpected response to read acceleration",
             results[1])
     else:
         return results[2]
Exemple #33
0
 def start_one(self, motion):
     elog.debug("start_one() called")
     self.cv_trigger(motion.axis)
     motor_name = motion.axis.group + "." + motion.axis.name
     error, reply = self.__xps.GroupMoveAbsolute(motor_name, [
         motion.target_pos,
     ])
     print("Reply:", reply)
     if error != 0:
         elog.error(
             "NewportXPS Error: Unexpected response to move absolute",
             reply)
Exemple #34
0
    def init_device(self):
        self.debug_stream("In init_device() of axis")
        self.get_device_properties(self.get_device_class())

        # -v1
        self.info_stream("INFO STREAM ON ++++++++++++++++++++++++++")
        self.warn_stream("WARN STREAM ON ++++++++++++++++++++++++++")
        self.error_stream("ERROR STREAM ON ++++++++++++++++++++++++++")
        self.fatal_stream("FATAL STREAM ON ++++++++++++++++++++++++++")

        # -v3 (-v == -v4)
        self.debug_stream("DEBUG STREAM ON ++++++++++++++++++++++++++")

        try:
            self.axis = TgGevent.get_proxy(bliss.get_axis, self._axis_name)
            self.kontroler = TgGevent.get_proxy(self.axis.controller)
        except:
            elog.error("unable to get kontroller or axis")
            self.set_status(traceback.format_exc())

        self.debug_stream("axis found : %s" % self._axis_name)

        self.once = False

        self._init_time = time.time()
        self._t = time.time()

        self.attr_Home_position_read = 0.0
        self.attr_StepSize_read = 0.0
        self.attr_Steps_per_unit_read = 0.0
        self.attr_Acceleration_read = 1.0
        self.attr_HardLimitLow_read = False
        self.attr_HardLimitHigh_read = False
        self.attr_Backlash_read = 0.0
        self.attr_Offset_read = 0.0
        self.attr_Tolerance_read = 0.0
        self.attr_PresetPosition_read = 0.0
        self.attr_FirstVelocity_read = 0.0

        """
        self.attr_Steps_read = 0
        self.attr_Position_read = 0.0
        self.attr_Measured_Position_read = 0.0
        self.attr_Home_side_read = False
        """

        self.attr_trajpar_read = [[0.0]]

        # To force update of state and status.
        self.dev_state()

        # elog.info("    %s" % self.axis.get_info())
        elog.info(" BlissAxisManager.py Axis " + bcolors.PINK + self._ds_name + bcolors.ENDC + " initialized")
Exemple #35
0
    def initialize_axis(self, axis):

        axis.channel = axis.config.get("channel")

        if axis.channel == "X":
            self.ctrl_axis = axis

        axis.target_radius = axis.config.get("target_radius", int)
        axis.target_time = axis.config.get("target_time", int)
        axis.min_dead_zone = axis.config.get("min_dead_zone", int)
        axis.max_dead_zone = axis.config.get("max_dead_zone", int)
        axis.smoothing = axis.config.get("smoothing", int)
        axis.deceleration = axis.config.get("deceleration", float)

        add_axis_method(axis, self.get_id)

        # Enabling servo mode.
        self._flexdc_query("%sMO=1" % axis.channel)

        # Sets "point to point" motion mode.
        # 0 -> point to point
        # ( 1 -> jogging ;    2 -> position based gearing    )
        # ( 5 -> position based ECAM ;    8 -> Step command (no profile) )
        self._flexdc_query("%sMM=0" % axis.channel)

        # Special motion mode attribute parameter
        # 0 -> no special mode
        # ( 1 -> repetitive motion )
        self._flexdc_query("%sSM=0" % axis.channel)

        # Defines smoothing (typically 4).
        self._flexdc_query("%sWW=%d" % (axis.channel, axis.smoothing))

        # Target Time (settling time?)
        self.flexdc_parameter(axis, "TT", axis.target_time)

        # Target Radius (target window ?)
        self.flexdc_parameter(axis, "TR", axis.target_radius)

        # Checks if closed loop parameters have been set.
        _ans = self._flexdc_query("%sTT" % axis.channel)
        if _ans == "0":
            elog.error("Missing closed loop param TT (Target Time)!!")

        _ans = self._flexdc_query("%sTR" % axis.channel)
        if _ans == "0":
            elog.error("Missing closed loop param TR (Target Radius)!!")

        # Minimum dead zone
        self.flexdc_parameter(axis, "CA[36]", axis.min_dead_zone)

        # Maximum dead zone
        self.flexdc_parameter(axis, "CA[37]", axis.max_dead_zone)
Exemple #36
0
    def initialize_axis(self, axis):

        axis.channel = axis.config.get("channel")

        if axis.channel == "X":
            self.ctrl_axis = axis

        axis.target_radius = axis.config.get("target_radius", int)
        axis.target_time = axis.config.get("target_time", int)
        axis.min_dead_zone = axis.config.get("min_dead_zone", int)
        axis.max_dead_zone = axis.config.get("max_dead_zone", int)
        axis.smoothing = axis.config.get("smoothing", int)
        axis.deceleration = axis.config.get("deceleration", float)



        # Enabling servo mode.
        self._flexdc_query("%sMO=1" % axis.channel)

        # Sets "point to point" motion mode.
        # 0 -> point to point
        # ( 1 -> jogging ;    2 -> position based gearing    )
        # ( 5 -> position based ECAM ;    8 -> Step command (no profile) )
        self._flexdc_query("%sMM=0" % axis.channel)

        # Special motion mode attribute parameter
        # 0 -> no special mode
        # ( 1 -> repetitive motion )
        self._flexdc_query("%sSM=0" % axis.channel)

        # Defines smoothing (typically 4).
        self._flexdc_query("%sWW=%d" % (axis.channel, axis.smoothing))

        # Target Time (settling time?)
        self.flexdc_parameter(axis, "TT", axis.target_time)

        # Target Radius (target window ?)
        self.flexdc_parameter(axis, "TR", axis.target_radius)

        # Checks if closed loop parameters have been set.
        _ans = self._flexdc_query("%sTT" % axis.channel)
        if _ans == "0":
            elog.error("Missing closed loop param TT (Target Time)!!")

        _ans = self._flexdc_query("%sTR" % axis.channel)
        if _ans == "0":
            elog.error("Missing closed loop param TR (Target Radius)!!")

        # Minimum dead zone
        self.flexdc_parameter(axis, "CA[36]", axis.min_dead_zone)

        # Maximum dead zone
        self.flexdc_parameter(axis, "CA[37]", axis.max_dead_zone)
Exemple #37
0
    def _get_closed_loop_status(self, axis):
        _ans = self.send(axis, "SVO? %s" % (axis.channel))

        _status = _ans.split("=")[1]

        if _status == "1":
            return True
        elif _status == "0":
            return False
        else:
            elog.error("ERROR on _get_closed_loop_status, _ans=%r" %
                       _ans, raise_exception=False)
            return -1
Exemple #38
0
 def get_info(self, axis):
     log.debug("get_info() called")
     nlines = 23
     cmd = axis.channel + "QA\r"
     replyList = self.sock.write_readlines(cmd, nlines, eol="\r\n",timeout=5)
     # Strip the echoed command from the first reply
     idx = replyList[0].find('\r')
     if idx == -1:
         log.error("PM600 Error: No echoed command")
     answer = replyList[0][idx+1:]
     for i in range(1,nlines):
         answer = answer + "\n" + replyList[i]
     log.debug(answer)
     return answer
Exemple #39
0
    def initialize_axis(self, axis):
        self.trace("axis initialization")

        axis.channel = axis.config.get("channel", int)

        # check communication
        try:
            _ans = self.get_identifier(axis, 0.1)
        except Exception as ex:
            _str = "%r\nERROR on \"%s\": switch on the controller" % (ex, self.host)
            # by default, an exception will be raised
            elog.error(_str)

        # Enables the closed-loop.
        self._set_closed_loop(axis, True)
Exemple #40
0
 def get_info(self, axis):
     log.debug("get_info() called")
     nlines = 23
     cmd = axis.channel + "QA\r"
     replyList = self.sock.write_readlines(cmd,
                                           nlines,
                                           eol="\r\n",
                                           timeout=5)
     # Strip the echoed command from the first reply
     idx = replyList[0].find('\r')
     if idx == -1:
         log.error("PM600 Error: No echoed command")
     answer = replyList[0][idx + 1:]
     for i in range(1, nlines):
         answer = answer + "\n" + replyList[i]
     log.debug(answer)
     return answer
Exemple #41
0
    def enable_position_compare(self, axis, start, stop, step):
        """
        Generate output pulse on the PCO connector. The first pulse is output when
        the positioner crosses the start position and the last pulse is given at the
        stop position. The difference between the start and the stop position should
        be an integer multiple of the position step.

        example: Pos.setPositionCompare(5.0, 25.0, 0.002)
                 will generate pulses between 5mm and 25mm every 0.002mm
        """
        motor_name = axis.group + "." + axis.name
        elog.debug(motor_name, start, stop, step)
        error, reply = self.__xps.PositionerPositionCompareSet(motor_name, start, stop, step)
        if error != 0:
            elog.error("NewportXPS Error: ", reply)
        else:
            error, reply = self.__xps.PositionerPositionCompareEnable(motor_name)
            if error != 0:
                elog.error("NewportXPS Error: ", reply)
Exemple #42
0
    def enable_position_compare(self, axis, start, stop, step):
        """
        Generate output pulse on the PCO connector. The first pulse is output when
        the positioner crosses the start position and the last pulse is given at the
        stop position. The difference between the start and the stop position should
        be an integer multiple of the position step.

        example: Pos.setPositionCompare(5.0, 25.0, 0.002)
                 will generate pulses between 5mm and 25mm every 0.002mm
        """
        motor_name = axis.group + "." + axis.name
        elog.debug(motor_name, start, stop, step)
        error, reply = self.__xps.PositionerPositionCompareSet(
            motor_name, start, stop, step)
        if error != 0:
            elog.error("NewportXPS Error: ", reply)
        else:
            error, reply = self.__xps.PositionerPositionCompareEnable(
                motor_name)
            if error != 0:
                elog.error("NewportXPS Error: ", reply)
Exemple #43
0
    def io_command(self, command, channel, value=None):
        log.debug("io_command() called")
        if value:
            cmd = channel + command + str(value) + "\r"
            log.debug("io_command() sending command " + cmd[:-1])
        else:
            cmd = channel + command + "\r"
            log.debug("io_command() sending command " + cmd[:-1])

        reply = self.sock.write_readline(cmd, eol="\r\n")
        # The response from the PM600 is terminated with CR/LF.  Remove these
        newreply = reply.rstrip("\r\n")
        # The PM600 always echoes the command sent to it, before sending the response.  It is terminated
        # with a carriage return.  So we need to delete all characters up to and including the first
        # carriage return
        idx = newreply.find('\r')
        if idx == -1:
            log.error("PM600 Error: No echoed command")
        answer = newreply[idx + 1:]
        # check for the error character !
        idx = answer.find("!")
        if idx != -1:
            log.error("PM600 Error: " + answer[idx:])
        # Now remove the channel from the reply and check against the requested channel
        idx = answer.find(':')
        repliedChannel = int(answer[:idx])
        if int(channel) != repliedChannel:
            log.error("PM600 Error: Wrong channel replied %s" % repliedChannel)
        log.debug("io_command() reply " + answer[idx + 1:])
        return answer[idx + 1:]
Exemple #44
0
 def io_command(self, command, channel, value=None):
     log.debug("io_command() called")
     if value:
         cmd = channel + command + str(value) + "\r"
         log.debug("io_command() sending command " + cmd[:-1])
     else:
         cmd = channel + command + "\r"
         log.debug("io_command() sending command " + cmd[:-1])
     
     reply = self.sock.write_readline(cmd, eol="\r\n")
     # The response from the PM600 is terminated with CR/LF.  Remove these
     newreply = reply.rstrip("\r\n")
     # The PM600 always echoes the command sent to it, before sending the response.  It is terminated
     # with a carriage return.  So we need to delete all characters up to and including the first
     # carriage return
     idx = newreply.find('\r')
     if idx == -1:
         log.error("PM600 Error: No echoed command")
     answer = newreply[idx+1:]
     # check for the error character !
     idx = answer.find("!")
     if idx != -1:
         log.error("PM600 Error: " + answer[idx:])
     # Now remove the channel from the reply and check against the requested channel
     idx = answer.find(':')
     repliedChannel = int(answer[:idx])
     if int(channel) != repliedChannel:
         log.error("PM600 Error: Wrong channel replied %s" % repliedChannel)
     log.debug("io_command() reply " + answer[idx+1:])
     return answer[idx+1:]
Exemple #45
0
 def cv_trigger(self, axis):
     """
     Generate a pulses on the GPIO connector when the positioner reaches
     constant velocity motion.
     """
     elog.debug("cv_trigger start")
     motor_name = axis.group + "." + axis.name
     category = ".SGamma"
     event1 = motor_name + category + ".ConstantVelocityStart"
     action = axis.gpioConn + ".DO.DOPulse"
     error, reply = self.__xps.EventExtendedConfigurationTriggerSet(
         [event1], [0], [0], [0], [0])
     if error != 0:
         elog.error("NewportXPS Error: ", reply)
     else:
         error, reply = self.__xps.EventExtendedConfigurationActionSet(
             [action], [4], [0], [0], [0])
         if error != 0:
             elog.error("NewportXPS Error: ", reply)
         else:
             error, reply = self.__xps.EventExtendedStart()
             if error != 0:
                 elog.error("NewportXPS Error: ", reply)
             elog.debug("cv_trigger eventid ", reply)
     elog.debug("cv_trigger stop")
Exemple #46
0
 def cv_trigger(self, axis):
     """
     Generate a pulses on the GPIO connector when the positioner reaches
     constant velocity motion.
     """
     elog.debug("cv_trigger start")
     motor_name = axis.group + "." + axis.name
     category = ".SGamma"
     event1 = motor_name + category + ".ConstantVelocityStart"
     action = axis.gpioConn + ".DO.DOPulse"
     error, reply = self.__xps.EventExtendedConfigurationTriggerSet(
         [event1], [0], [0], [0], [0])
     if error != 0:
         elog.error("NewportXPS Error: ", reply)
     else:
         error, reply = self.__xps.EventExtendedConfigurationActionSet(
             [action], [4], [0], [0], [0])
         if error != 0:
             elog.error("NewportXPS Error: ", reply)
         else:
             error, reply = self.__xps.EventExtendedStart()
             if error != 0:
                 elog.error("NewportXPS Error: ", reply)
             elog.debug("cv_trigger eventid ", reply)
     elog.debug("cv_trigger stop")
Exemple #47
0
    def initialize_axis(self, axis):
        elog.debug("initialize_axis() called")
        axis.channel = axis.config.get("address")
        axis.group = axis.config.get("group")
        axis.autoHome = axis.config.get("autoHome")
        axis.minJerkTime = axis.config.get("minJerkTime")
        axis.maxJerkTime = axis.config.get("maxJerkTime")
        axis.gpioConn = axis.config.get("gpio_conn")

        error, reply = self.__xps.GroupInitialize(axis.group)
        if error == 0:
            elog.debug("NewportXPS: initialisation successful")
        elif error == -22:
            elog.debug("NewportXPS: Controller already initialised")
        else:
            elog.error("NewportXPS: Controller initialise failed: ", error)

        if axis.autoHome:
            self.home_search(axis, False)
        self.read_velocity(axis)

        elog.debug("initialize_axis() complete")
Exemple #48
0
    def initialize_axis(self, axis):
        elog.debug("initialize_axis() called")
        axis.channel = axis.config.get("address")
        axis.group = axis.config.get("group")
        axis.autoHome = axis.config.get("autoHome")
        axis.minJerkTime = axis.config.get("minJerkTime")
        axis.maxJerkTime = axis.config.get("maxJerkTime")
        axis.gpioConn = axis.config.get("gpio_conn")

        error, reply = self.__xps.GroupInitialize(axis.group)
        if error == 0:
            elog.debug("NewportXPS: initialisation successful")
        elif error == -22:
            elog.debug("NewportXPS: Controller already initialised")
        else:
            elog.error("NewportXPS: Controller initialise failed: ", error)

        if axis.autoHome:
            self.home_search(axis, False)
        self.read_velocity(axis)

        elog.debug("initialize_axis() complete")
Exemple #49
0
def __recreate(db=None, new_server=False):

    if db is None:
        db = tango.Database()

    server_name, server_instance, server_name = get_server_info()
    registered_servers = set(db.get_instance_name_list('BlissAxisManager'))

    # check if server exists in database. If not, create it.
    if server_instance not in registered_servers:
        if new_server:
            register_server(db=db)
        else:
            print "The device server %s is not defined in database. " \
                  "Exiting!" % server_name
            print "hint: start with '-n' to create a new one automatically"
            sys.exit(255)

    dev_map = get_devices_from_server(db=db)

    # if in a jive wizard workflow, return no axis
    if not dev_map.get('BlissAxisManager', ()):
        return ()

    axis_names = get_server_axis_names()

    # gather info about current axes registered in database and
    # new axis from config

    manager_dev_name = dev_map['BlissAxisManager'][0]

    if db.get_device_property(manager_dev_name, "config_file")["config_file"]:
        elog.error(
            'Use of XML configuration not supported anymore. '
            'Turn to beacon',
            raise_exception=False)
        sys.exit(-1)

    if db.get_device_property(manager_dev_name, "axes")["axes"]:
        elog.error('Use of \'axes\' property not supported anymore',
                   raise_exception=False)
        elog.error('Configure by adding: \'tango_server: %s\' in each '
                   'axis yaml instead' % server_instance,
                   raise_exception=False)
        sys.exit(-1)

    return __recreate_axes(server_name,
                           manager_dev_name,
                           axis_names,
                           dev_map,
                           db=db)
Exemple #50
0
def __recreate(db=None, new_server=False):

    if db is None:
        db = tango.Database()

    server_name, server_instance, server_name = get_server_info()
    registered_servers = set(db.get_instance_name_list('BlissAxisManager'))

    # check if server exists in database. If not, create it.
    if server_instance not in registered_servers:
        if new_server:
            register_server(db=db)
        else:
            print "The device server %s is not defined in database. " \
                  "Exiting!" % server_name
            print "hint: start with '-n' to create a new one automatically"
            sys.exit(255)

    dev_map = get_devices_from_server(db=db)

    # if in a jive wizard workflow, return no axis
    if not dev_map.get('BlissAxisManager', ()):
        return ()

    axis_names = get_server_axis_names()

    # gather info about current axes registered in database and
    # new axis from config

    manager_dev_name = dev_map['BlissAxisManager'][0]

    if db.get_device_property(manager_dev_name, "config_file")["config_file"]:
        elog.error('Use of XML configuration not supported anymore. '
                   'Turn to beacon', raise_exception=False)
        sys.exit(-1)

    if db.get_device_property(manager_dev_name, "axes")["axes"]:
        elog.error('Use of \'axes\' property not supported anymore',
                   raise_exception=False)
        elog.error('Configure by adding: \'tango_server: %s\' in each '
                   'axis yaml instead' % server_instance,
                   raise_exception=False)
        sys.exit(-1)

    return __recreate_axes(server_name, manager_dev_name,
                           axis_names, dev_map, db=db)
Exemple #51
0
    def initialize(self):
        """
        Opens one socket for 2 channels.
        """
        try:
            self.serial = get_comm(self.config.config_dict, SERIAL, timeout=1)
            self._status = "SERIAL communication configuration found"
            elog.debug(self._status)
        except ValueError:
            try:
                serial_line = self.config.get("serial_line")
                warn(
                    "'serial_line' keyword is deprecated. Use 'serial' instead",
                    DeprecationWarning)
                comm_cfg = {'serial': {'url': serial_line}}
                self.serial = get_comm(comm_cfg, timeout=1)
            except:
                self._status = "Cannot find serial configuration"
                elog.error(self._status)

        try:
            # should be : 'VSCANNER 01.02\r\n'
            _ans = self.serial.write_readline("?VER\r\n")
            self._status += "\ncommunication ok "
            elog.debug(self._status + _ans)
        except OSError:
            _ans = "no ans"
            self._status = sys.exc_info()[1]
            elog.error(self._status)
        except:
            _ans = "no ans"
            self._status = "communication error : cannot communicate with serial \"%s\"" % self.serial
            elog.error(self._status)
            traceback.print_exc()

        try:
            _ans.index("VSCANNER")
            self._status += "VSCANNER found (substring VSCANNER found in answer to ?VER)."
        except:
            self._status = "communication error : no VSCANNER found on serial \"%s\"" % self.serial

        elog.debug(self._status)
Exemple #52
0
    def initialize(self):
        """
        Opens one socket for 2 channels.
        """
        try:
            self.serial = get_comm(self.config.config_dict, SERIAL, timeout=1)
            self._status = "SERIAL communication configuration found"
            elog.debug(self._status)
        except ValueError:
            try:
                serial_line = self.config.get("serial_line")
                warn("'serial_line' keyword is deprecated. Use 'serial' instead",
                     DeprecationWarning)
                comm_cfg = {'serial': {'url': serial_line } }
                self.serial = get_comm(comm_cfg, timeout=1)
            except:
                self._status = "Cannot find serial configuration"
                elog.error(self._status)

        try:
            # should be : 'VSCANNER 01.02\r\n'
            _ans = self.serial.write_readline("?VER\r\n")
            self._status += "\ncommunication ok "
            elog.debug(self._status + _ans)
        except OSError:
            _ans = "no ans"
            self._status = sys.exc_info()[1]
            elog.error(self._status)
        except:
            _ans = "no ans"
            self._status = "communication error : cannot communicate with serial \"%s\"" % self.serial
            elog.error(self._status)
            traceback.print_exc()

        try:
            _ans.index("VSCANNER")
            self._status += "VSCANNER found (substring VSCANNER found in answer to ?VER)."
        except:
            self._status = "communication error : no VSCANNER found on serial \"%s\"" % self.serial

        elog.debug(self._status)
Exemple #53
0
 def log_error(self, msg):
     """Logging method"""
     log.error(_ICEPAP_TAB + msg)
Exemple #54
0
    def init_device(self):
        self.debug_stream("In init_device() of axis")
        Device.init_device(self)

        # -v1
        self.info_stream("INFO STREAM ON ++++++++++++++++++++++++++")
        self.warn_stream("WARN STREAM ON ++++++++++++++++++++++++++")
        self.error_stream("ERROR STREAM ON ++++++++++++++++++++++++++")
        self.fatal_stream("FATAL STREAM ON ++++++++++++++++++++++++++")

        # -v3 (-v == -v4)
        self.debug_stream("DEBUG STREAM ON ++++++++++++++++++++++++++")

        # force a get of axis and controller to update status in case of error
        try:
            axis = self.axis
            controller = self.axis.controller
        except:
            traceback.print_exc()
            elog.error("unable to get kontroller or axis")
            self.set_status(traceback.format_exc())
            _ctrl = 'UNKNOWN'
        else:
            m_attr = self.get_device_attr()
            try:
                m_attr.get_attr_by_name('Position').set_write_value(axis.position())
            except:
                pass
            try:
                m_attr.get_attr_by_name('Velocity').set_write_value(axis.velocity())
            except:
                pass
            _ctrl = controller.get_class_name()

        self.debug_stream("axis found : %s" % self._axis_name)

        self._init_time = time.time()
        self._t = time.time()

        self.attr_Home_position_read = 0.0
        self.attr_StepSize_read = 0.0
        self.attr_Steps_per_unit_read = 0.0
        self.attr_Acceleration_read = 1.0
        self.attr_HardLimitLow_read = False
        self.attr_HardLimitHigh_read = False
        self.attr_Backlash_read = 0.0
        self.attr_Sign_read = 1
        self.attr_Offset_read = 0.0
        self.attr_Tolerance_read = 0.0
        self.attr_PresetPosition_read = 0.0
        self.attr_FirstVelocity_read = 0.0

        """
        self.attr_Steps_read = 0
        self.attr_Position_read = 0.0
        self.attr_Measured_Position_read = 0.0
        self.attr_Home_side_read = False
        """

        self.attr_trajpar_read = [[0.0]]

        # To force update of state and status.
        self._dev_state()

        # elog.info("    %s" % self.axis.get_info())

        elog.info("BlissAxisManager [%s] : \t" % _ctrl + bcolors.PINK + self._ds_name + bcolors.ENDC + "\t initialized")
Exemple #55
0
 def start_one(self, motion):
     log.debug("start_one() called")
     reply = self.io_command("MA", motion.axis.channel, motion.target_pos)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to move absolute" +
                   reply)
Exemple #56
0
 def set_position(self, axis, position):
     log.debug("set_position() called")
     reply = self.io_command("AP", axis.channel, position)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to set_position" +
                   reply)
Exemple #57
0
 def stop(self, motion):
     log.debug("stop() called")
     reply = self.io_command("ST", motion.axis.channel)
     if reply != "OK":
         log.error("PM600 Error: Unexpected response to stop" + reply)