def _execute_cmd(self, raw_cmd, errcheck=True):
        """
        Takes a string command and executes it on Newport


        :param str raw_cmd:
        :param bool errcheck:


        :return: response of device
        :rtype: `str`

        """
        query_resp = None

        if "?" in raw_cmd:
            query_resp = self.query(raw_cmd)
        else:
            self.sendcmd(raw_cmd)

        if errcheck:
            err_resp = self.query('TB?')

            # pylint: disable=unused-variable
            code, timestamp, msg = err_resp.split(",")
            code = int(code)
            if code != 0:
                raise NewportError(code)

        return query_resp
 def stop_motion(self):
     """
     Stop all motion on axis. With programmed deceleration rate
     """
     try:
         self._newport_cmd("ST", target=self.axis_id)
     except NewportError as e:
         raise NewportError(e)
Exemplo n.º 3
0
def test_axis():
    """Get axis for given error code."""
    cls = NewportError(errcode=313)
    assert cls.axis == cls._axis
Exemplo n.º 4
0
def test_timestamp():
    """Get the timestamp for a given error."""
    cls = NewportError()
    assert cls.timestamp == cls._timestamp
Exemplo n.º 5
0
def test_errcode():
    """Get the error code reported by device."""
    cls = NewportError(errcode=7)
    assert cls.errcode == cls._errcode
Exemplo n.º 6
0
def test_get_message():
    """Get the message for a given error code."""
    err_code = "7"
    cls = NewportError()
    assert cls.get_message(err_code) == cls.messageDict[err_code]
Exemplo n.º 7
0
def test_init_with_error_code_axis():
    """Initialize with axis-specific error code."""
    err_code = 313  # ax 3 not enabled
    cls = NewportError(errcode=err_code)
    assert cls._axis == 3
    assert cls._errcode == 13
Exemplo n.º 8
0
def test_init_with_error_code():
    """Initialize with non-axis specific error code."""
    err_code = 7  # parameter out of range
    cls = NewportError(errcode=err_code)
    assert cls._axis is None
    assert cls._errcode == 7
Exemplo n.º 9
0
def test_init_with_timestamp():
    """Initialized with a time stamp."""
    timestamp = datetime.datetime.now()
    cls = NewportError(timestamp=timestamp)
    assert isinstance(cls._timestamp, datetime.timedelta)
Exemplo n.º 10
0
def test_init_none():
    """Initialized with both arguments as `None`."""
    cls = NewportError()
    assert isinstance(cls._timestamp, datetime.timedelta)
    assert cls._errcode is None
    assert cls._axis is None