예제 #1
0
    def query(self, command, *, send_args=(None, None),
              recv_args=(None, None)):
        """Send query to the stage and return the answer, after handling
        possible errors.

        :param command: command to be sent to the instrument
        :type command: string

        :param send_args: (termination, encoding) to override class defaults
        :param recv_args: (termination, encoding) to override class defaults
        """
        ans = super().query(command, send_args=send_args, recv_args=recv_args)
        if ans[0] == 'E':
            code = ans[2]
            if code == '8':
                raise errors.InstrumentError('Value out of range')
            elif code == '4':
                raise errors.InstrumentError(
                    'Command parse error, ie wrong number  of parameters')
            elif code == '5':
                raise errors.InstrumentError('Unknown command')
            elif code == '2':
                raise errors.InstrumentError('Invalid checksum')

        return ans
예제 #2
0
    def trigger_ecl_mode(self, value):
        """Trigger mode for ECL logic.
        """
        if self.recall('trigger_type') == 'ttl':
            raise errors.InstrumentError('Level triggering only with ECL')

        self.query_expect(value)
예제 #3
0
    def _find_interface(self, dev, setting):
        interfaces = find_interfaces(dev,
                                     bInterfaceClass=0xFE,
                                     bInterfaceSubClass=3)
        if not interfaces:
            raise errors.InstrumentError('USB TMC interface not found.')
        elif len(interfaces) > 1:
            self.log_warning('More than one interface found, selecting first.')

        return interfaces[0]
예제 #4
0
    def _return_handler(self, func_name, ret_value):
        if ret_value < 0:
            raise errors.InstrumentError(_ERRORS[ret_value])
        elif (ret_value > 0
              and func_name not in ('GET_COCTIME', 'GET_DELTIME',
                                    'GET_BELTIME', 'GET_EXPTIME')):
            self.log_warning('While calling {}: {}', func_name,
                             _ERRORS[ret_value])

        return ret_value
예제 #5
0
    def query(self, command, *, send_args=(None, None),
              recv_args=(None, None)):
        """Query the instrument and parse the response.

        :raises: InstrumentError
        """
        response = super().query(command,
                                 send_args=recv_args,
                                 recv_args=recv_args)
        command = command.strip()[0]
        if response in ('1x', '2x'):
            raise errors.InstrumentError(
                "Unknown command: '{}'".format(command))
        if not response.startswith(command):
            raise errors.InstrumentError(
                "Unknown response: '{}'".format(response))
        if response == 'X' or 'x':
            raise errors.InstrumentError('Unable to set')
        elif not response == '+':
            raise errors.InstrumentError(
                "Unknown response: '{}'".format(response))
        return response
예제 #6
0
 def average_voltage(self):
     """Cathode potential bias with respect of MCP.
     """
     if self.revision >= 2.0:
         ans = self.query_expect('AVE ?')
         ans = between(ans, 'AVE ?', 'ok')
         return float(ans.strip()) / 10.
     else:
         ans = self.query_expect('THRESHV @ .')[8:]
         try:
             pos = ans.index('.')
         except ValueError:
             raise errors.InstrumentError('Unsupported operation.')
         return float(ans[pos+2:pos+7]) / 10.
예제 #7
0
 def clamp_voltage(self):
     """Most negative value of the gate pulse.
     """
     if self.revision >= 2.0:
         ans = self.query_expect('CLAMP ?')
         ans = between(ans, 'CLAMP ?', 'ok').strip()
         return float(ans)
     else:
         ans = self.query_expect('CLAMP @ .')
         try:
             pos = ans.index('.')
         except ValueError:
             raise errors.InstrumentError('Unsupported operation.')
         return float(ans[pos+2:pos+7]) / 10.0
예제 #8
0
 def trigger_ecl_level(self):
     """Trigger level for ECL logic, mode level.
     """
     if self.revision >= 2.0:
         ans = self.query_expect('THRESHV ?')
         ans = between(ans, 'THRESHV ?', 'ok')
         return float(ans.strip())
     else:
         ans = self.query_expect('THRESHV @ .')[8:]
         try:
             pos = ans.index('.')
         except ValueError:
             raise errors.InstrumentError('Unsupported operation.')
         return float(ans[pos+2:pos+7])
예제 #9
0
    def query_expect(self, command, read_termination=None, expected='ok'):
        """Send a query and check that the answer contains the string.

        :type command: str
        :type read_termination: str | None
        :type expected: str | None
        """
        if command and not self.recall('remote'):
            self.log_info('Setting Remote.')
            self.remote = True
        self.resource.write(command)
        ans = self.read(read_termination)
        if expected and not expected in ans:
            raise errors.InstrumentError("'{}' not in '{}'".format(
                expected, ans))
        return ans
예제 #10
0
    def query(self, command, *, send_args=(None, None),
              recv_args=(None, None)):
        """Send query to the laser and return the answer, after handling
        possible errors.

        :param command: command to be sent to the instrument
        :type command: string

        :param send_args: (termination, encoding) to override class defaults
        :param recv_args: (termination, encoding) to override class defaults
        """
        ans = super().query(command, send_args=send_args, recv_args=recv_args)
        # TODO: Echo handling
        code = ans[0]
        if code != 0:
            if code == '1':
                raise errors.InstrumentError('Command invalid')
            elif code == '2':
                raise errors.InstrumentError('Wrong number of parameters')
            elif code == '3':
                raise errors.InstrumentError('Parameter value is out of range')
            elif code == '4':
                raise errors.InstrumentError('Unlocking code is wrong')
            elif code == '5':
                raise errors.InstrumentError(
                    'Device is locked for this command')
            elif code == '6':
                raise errors.InstrumentError('This function is not supported')
            elif code == '7':
                raise errors.InstrumentError(
                    'Timeout while reading command (60 s)')
            elif code == '8':
                raise errors.InstrumentError(
                    'This value is currently not available')

        ans = ans[2:]
        # TODO: Code reporting?
        return ans
예제 #11
0
 def analog_dif_in(self, key, gain=1):
     '''
     Differential channels can make use of the low noise precision PGA to provide gains up to 20. In differential mode, the voltage of each AI with respect to ground must be between +20 and -10 volts, but the range of voltage difference between the 2 AI is a function of gain (G) as follows:
     G=1     ±20 volts
     G=2     ±10 volts
     G=4     ±5 volts
     G=5     ±4 volts
     G=8     ±2.5 volts
     G=10    ±2 volts
     G=16    ±1.25 volts
     G=20    ±1 volt
     The reason the range is ±20 volts at G=1 is that, for example, AI0 could be +10 volts and AI1 could be -10 volts giving a difference of +20 volts, or AI0 could be -10 volts and AI1 could be +10 volts giving a difference of -20 volts. The PGA (programmable gain amplifier, available on differential channels only) amplifies the AI voltage before it is digitized by the A/D converter. The high level drivers then divide the reading by the gain and return the actual measured voltage.
     '''
     gain_list = [1, 2, 4, 5, 8, 10, 16, 20]
     gain_value = gain
     if gain_value not in gain_list:
         raise errors.InstrumentError(
             'Gain value not permitted, check driver code or Labjack user guide'
         )
     else:
         return self._internal.eAnalogIn(channel=key + 8,
                                         gain=gain_value)['voltage']
예제 #12
0
    def __init__(self,
                 vendor=None,
                 product=None,
                 serial_number=None,
                 **kwargs):
        super().__init__(vendor, product, serial_number, **kwargs)
        self.usb_intr_in = find_endpoint(self.usb_intf, usb.ENDPOINT_IN,
                                         usb.ENDPOINT_TYPE_INTERRUPT)
        self.log_debug('EP Address: intr={}'.format(
            self.usb_intr_in.bEndpointAddress))

        self.usb_dev.reset()

        time.sleep(0.01)

        self._get_capabilities()

        self._btag = 0

        if not (self.usb_recv_ep and self.usb_send_ep):
            raise errors.InstrumentError(
                "TMC device must have both Bulk-In and Bulk-out endpoints.")
예제 #13
0
 def _return_handler(self, func_name, ret_value):
     if ret_value != 0:
         raise errors.InstrumentError('{} ({})'.format(
             ret_value, _ERRORS[ret_value]))
     return ret_value
예제 #14
0
 def trigger_ttl_termination(self, value):
     """Trigger termination for TTL logic (for ECL is fixed to 50 ohm).
     """
     if self.recall('trigger_type') == 'ecl':
         raise errors.InstrumentError('Level triggering only with ECL')
     self.query_expect(value)
예제 #15
0
 def query_expect(self, command, recv_termination=None, expected='ok'):
     ans = self.query(command, recv_args=(recv_termination, HRI.ENCODING))
     if expected and not expected in ans:
         raise errors.InstrumentError("'{}' not in '{}'".format(expected, ans))
     return ans