Beispiel #1
0
    def set_atten(self, idx, value, strict_flag=True):
        """This function sets the attenuation of an attenuator given its index
        in the instrument.

        Args:
            idx: A zero-based index that identifies a particular attenuator in
                an instrument. For instruments that only have one channel, this
                is ignored by the device.
            value: A floating point value for nominal attenuation to be set.
            strict_flag: if True, function raises an error when given out of
                bounds attenuation values, if false, the function sets out of
                bounds values to 0 or max_atten.

        Raises:
            InvalidOperationError if the telnet connection is not open.
            IndexError if the index is not valid for this instrument.
            ValueError if the requested set value is greater than the maximum
                attenuation value.
        """

        if not self.is_open():
            raise attenuator.InvalidOperationError('Connection not open!')

        if idx >= self.num_atten:
            raise IndexError('Attenuator index out of range!', self.num_atten,
                             idx)

        if value > self.max_atten and strict_flag:
            raise ValueError('Attenuator value out of range!', self.max_atten,
                             value)
        # The actual device uses one-based index for channel numbers.
        self._tnhelper.cmd('CHAN:%s:SETATT:%s' % (idx + 1, value))
Beispiel #2
0
    def cmd(self, cmd_str, wait_ret=True):
        if not isinstance(cmd_str, str):
            raise TypeError('Invalid command string', cmd_str)

        if not self.is_open():
            raise attenuator.InvalidOperationError(
                'Telnet connection not open for commands')

        cmd_str.strip(self.tx_cmd_separator)
        self._tn.read_until(_ascii_string(self.prompt), 2)
        self._tn.write(_ascii_string(cmd_str + self.tx_cmd_separator))

        if wait_ret is False:
            return None

        match_idx, match_val, ret_text = self._tn.expect(
            [_ascii_string('\S+' + self.rx_cmd_separator)], 1)

        if match_idx == -1:
            logging.debug('Telnet Command: {}'.format(cmd_str))
            logging.debug('Telnet Reply: ({},{},{})'.format(
                match_idx, match_val, ret_text))
            self.diagnose_telnet()
            raise attenuator.InvalidDataError(
                'Telnet command failed to return valid data')

        ret_text = ret_text.decode()
        ret_text = ret_text.strip(self.tx_cmd_separator +
                                  self.rx_cmd_separator + self.prompt)

        return ret_text
    def set_atten(self, idx, value):
        r"""This function sets the attenuation of an attenuator given its index in the instrument.

        Parameters
        ----------
        idx : This zero-based index is the identifier for a particular attenuator in an
              instrument. For instruments that only has one channel, this is ignored by the device.
        value : This is a floating point value for nominal attenuation to be set.

        Raises
        ------
        InvalidOperationError
            This error occurs if the underlying telnet connection to the instrument is not open.
        IndexError
            If the index of the attenuator is greater than the maximum index of the underlying
            instrument, this error will be thrown. Do not count on this check programmatically.
        ValueError
            If the requested set value is greater than the maximum attenuation value, this error
            will be thrown. Do not count on this check programmatically.
        """

        if not self.is_open():
            raise attenuator.InvalidOperationError("Connection not open!")

        if idx >= self.num_atten:
            raise IndexError("Attenuator index out of range!", self.num_atten,
                             idx)

        if value > self.max_atten:
            raise ValueError("Attenuator value out of range!", self.max_atten,
                             value)
        # The actual device uses one-based index for channel numbers.
        self._tnhelper.cmd("CHAN:%s:SETATT:%s" % (idx + 1, value))
Beispiel #4
0
    def get_atten(self, idx):
        """Returns the current attenuation of the attenuator at the given index.

        Args:
            idx: The index of the attenuator.

        Raises:
            InvalidOperationError if the telnet connection is not open.

        Returns:
            the current attenuation value as a float
        """
        if not self.is_open():
            raise attenuator.InvalidOperationError('Connection not open!')

        if idx >= self.num_atten or idx < 0:
            raise IndexError('Attenuator index out of range!', self.num_atten,
                             idx)

        if self.num_atten == 1:
            atten_val_str = self._tnhelper.cmd(':ATT?')
        else:
            atten_val_str = self._tnhelper.cmd('CHAN:%s:ATT?' % (idx + 1))
        atten_val = float(atten_val_str)
        return atten_val
    def get_atten(self, idx):
        r"""This function returns the current attenuation from an attenuator at a given index in
        the instrument.

        Parameters
        ----------
        idx : This zero-based index is the identifier for a particular attenuator in an instrument.

        Raises
        ------
        InvalidOperationError
            This error occurs if the underlying telnet connection to the instrument is not open.

        Returns
        -------
        float
            Returns a the current attenuation value
        """

        if not self.is_open():
            raise attenuator.InvalidOperationError("Connection not open!")

        if idx >= self.num_atten or idx < 0:
            raise IndexError("Attenuator index out of range!", self.num_atten,
                             idx)

        atten_val_str = self._tnhelper.cmd("CHAN:%s:ATT?" % (idx + 1))
        atten_val = float(atten_val_str)
        return atten_val
Beispiel #6
0
    def get_atten(self, idx):
        r"""This function returns the current attenuation from an attenuator at a given index in
        the instrument.

        Parameters
        ----------
        idx : This zero-based index is the identifier for a particular attenuator in an instrument.

        Raises
        ------
        InvalidOperationError
            This error occurs if the underlying telnet connection to the instrument is not open.

        Returns
        -------
        float
            Returns a the current attenuation value
        """
        if not self.is_open():
            raise attenuator.InvalidOperationError("Connection not open!")

#       Potentially redundant safety check removed for the moment
#       if idx >= self.num_atten:
#           raise IndexError("Attenuator index out of range!", self.num_atten, idx)

        atten_val = self._tnhelper.cmd("ATTN? " + str(idx + 1))

        return float(atten_val)
Beispiel #7
0
    def set_atten(self, idx, value):
        """This function sets the attenuation of an attenuator given its index
        in the instrument.

        Args:
            idx: A zero-based index that identifies a particular attenuator in
                an instrument. For instruments that only have one channel, this
                is ignored by the device.
            value: A floating point value for nominal attenuation to be set.

        Raises:
            InvalidOperationError if the telnet connection is not open.
            IndexError if the index is not valid for this instrument.
            ValueError if the requested set value is greater than the maximum
                attenuation value.
        """
        if not self.is_open():
            raise attenuator.InvalidOperationError('Connection not open!')

        if idx >= self.num_atten:
            raise IndexError('Attenuator index out of range!', self.num_atten,
                             idx)

        if value > self.max_atten:
            raise ValueError('Attenuator value out of range!', self.max_atten,
                             value)

        self._tnhelper.cmd('ATTN ' + str(idx + 1) + ' ' + str(value), False)
    def cmd(self, cmd_str, wait_ret=True):
        if not isinstance(cmd_str, str):
            raise TypeError("Invalid command string", cmd_str)

        if not self.is_open():
            raise attenuator.InvalidOperationError(
                "Telnet connection not open for commands")

        cmd_str.strip(self.tx_cmd_separator)
        self._tn.read_until(_ascii_string(self.prompt), 2)
        self._tn.write(_ascii_string(cmd_str + self.tx_cmd_separator))

        if wait_ret is False:
            return None

        match_idx, match_val, ret_text = \
            self._tn.expect([_ascii_string("\S+"+self.rx_cmd_separator)], 1)

        if match_idx == -1:
            raise attenuator.InvalidDataError(
                "Telnet command failed to return valid data")

        ret_text = ret_text.decode()
        ret_text = ret_text.strip(self.tx_cmd_separator +
                                  self.rx_cmd_separator + self.prompt)

        return ret_text
Beispiel #9
0
    def get_atten(self, idx):
        """Returns the current attenuation of the attenuator at the given index.

        Args:
            idx: The index of the attenuator.

        Raises:
            InvalidOperationError if the telnet connection is not open.

        Returns:
            the current attenuation value as a float
        """
        if not self.is_open():
            raise attenuator.InvalidOperationError('Connection not open!')

        #       Potentially redundant safety check removed for the moment
        #       if idx >= self.num_atten:
        #           raise IndexError("Attenuator index out of range!", self.num_atten, idx)

        atten_val = self._tnhelper.cmd('ATTN? ' + str(idx + 1))

        return float(atten_val)