Ejemplo n.º 1
0
    def __init__(self, name=None, settings=None):

        QThread.__init__(self)
        Instrument.__init__(self, name, settings)
        self._is_connected = True
        self._output = 0
        self.start()
Ejemplo n.º 2
0
    def update(self, settings):
        '''
        updates the internal dictionary and sends changed values to instrument
        Args:
            settings: parameters to be set
        # mabe in the future:
        # Returns: boolean that is true if update successful

        '''
        Instrument.update(self, settings)

        for key, value in settings.iteritems():
            if key == 'test1':
                self._internal_state = value
def export_default_instruments(target_folder,
                               source_folder=None,
                               raise_errors=False):
    """
    tries to instantiate all the instruments that are imported in /instruments/__init__.py
    and saves instruments that could be instantiate into a .b2 file in the folder path
    Args:
        target_folder: target path for .b26 files
    """

    loaded_instruments = {}

    instruments_to_load = get_classes_in_folder(source_folder, Instrument)

    print('attempt to load {:d} instruments: '.format(
        len(instruments_to_load)))
    loaded_instruments, failed = Instrument.load_and_append(
        instruments_to_load, raise_errors=raise_errors)
    for name, value in loaded_instruments.iteritems():
        filename = os.path.join(target_folder, '{:s}.b26'.format(name))

        value.save_b26(filename)

    print('\n================================================')
    print('================================================')
    print('saved {:d} instruments, {:d} failed'.format(len(loaded_instruments),
                                                       len(failed)))
    if failed != {}:
        for error_name, error in failed.iteritems():
            print('failed to create instruments: ', error_name, error)
Ejemplo n.º 4
0
    def test_loading_and_saving(self):

        from src.core.read_write_functions import load_b26_file
        filename = "Z:\Lab\Cantilever\Measurements\\__tmp\\XX.b26"
        data = load_b26_file(filename)
        inst = {}
        instruments, instruments_failed = Instrument.load_and_append(data['instruments'], instruments=inst)
Ejemplo n.º 5
0
                    # here we should also create an instrument instance at some point as in the other cases...
                    # instrument_instance =
                    raise NotImplementedError
                elif issubclass(instrument_class_name, Instrument):
                    class_of_instrument = instrument_class_name
                    if instrument_settings is None:
                        # this creates an instance of the class with default settings
                        instrument_instance = class_of_instrument(
                            name=instrument_name)
                    else:
                        # this creates an instance of the class with custom settings
                        instrument_instance = class_of_instrument(
                            name=instrument_name, settings=instrument_settings)

                updated_instruments[instrument_name] = instrument_instance

        return updated_instruments, loaded_failed


if __name__ == '__main__':

    from PyLabControl.src.core import Script, Instrument
    folder_name = 'b26_toolkit'
    folder_name = '/Users/rettentulla/Projects/Python/b26_toolkit/src/'
    # folder_name = '/Users/rettentulla/Projects/Python/PyLabControl/src/'
    x = Instrument.get_instruments_in_path(folder_name)

    for k, v in x.iteritems():
        print(k, issubclass(v['x'], Script), issubclass(v['x'], Instrument))
Ejemplo n.º 6
0
                self.instruments['MagnetCoils']
                ['instance'].settings['magnetic_fields']['z_field']))

        print('requested fields',
              self.instruments['MagnetCoils']['instance'].requested_fields)
        print('applied fields',
              self.instruments['MagnetCoils']['instance'].applied_fields)

        self.data['new_voltages'] = self.instruments['MagnetCoils'][
            'instance'].new_voltages
        self.data['requested_fields'] = self.instruments['MagnetCoils'][
            'instance'].requested_fields
        self.data['applied_fields'] = self.instruments['MagnetCoils'][
            'instance'].applied_fields


if __name__ == '__main__':
    from PyLabControl.src.core import Instrument

    instruments, instruments_failed = Instrument.load_and_append(
        {'MagnetCoils': MagnetCoils})

    script, failed, instruments = Script.load_and_append(
        script_dict={'SetMagneticCoils': SetMagneticCoils},
        instruments=instruments)

    script['SetMagneticCoils']._function()

    print(script)
    print(failed)
    # print(instruments)
Ejemplo n.º 7
0
        Returns:

        """
        import scipy.optimize as optimize

        def f(x):
            y = np.squeeze(np.asarray(np.dot(Cmat, x) -
                                      fields))  #convert from matrix to array
            return np.dot(y, y)

        bounds = ((0, 1), (0, 1), (0, 1))
        opt = optimize.minimize(f, proposed_voltage, bounds=bounds)

        return opt.x


if __name__ == '__main__':
    instruments, failed = Instrument.load_and_append(
        instrument_dict={'MagnetCoils': MagnetCoils})

    # instruments['MagnetCoils'].update({'magnetic_fields': {'x_field': 10, 'y_field': -10, 'z_field': 40}})
    instruments['MagnetCoils'].update(
        {'magnetic_fields': {
            'x_field': 10,
            'y_field': -1,
            'z_field': 0
        }})

    # print(instruments['MagnetCoils'].is_connected())
    # instruments['MagnetCoils'].update({'magnetic_fields':{'x_field': 1}})
Ejemplo n.º 8
0
    ])


class ChamberPressureGauge(PressureGauge):
    """
    This class implements the AGC100 pressure gauge. The class communicates with the device over RS232 using pyserial.
    """

    _possible_com_ports = ['COM' + str(i) for i in range(0, 256)]

    _DEFAULT_SETTINGS = Parameter([
        Parameter('port', 'COM7', _possible_com_ports,
                  'com port to which the gauge controller is connected'),
        Parameter(
            'timeout', 1.0, float, 'amount of time to wait for a response '
            'from the gauge controller for each query'),
        Parameter('baudrate', 9600, int,
                  'baudrate of serial communication with gauge')
    ])


if __name__ == '__main__':
    instruments, failed = Instrument.load_and_append(
        instrument_dict={'GaugeController': PumpLinePressureGauge})

    print(instruments['GaugeController'])
    print('PumpLinePressureGauge', instruments['GaugeController'].pressure)

    instruments, failed = Instrument.load_and_append(
        instrument_dict={'GaugeController': ChamberPressureGauge})
    print('ChamberPressureGauge', instruments['GaugeController'].pressure)
Ejemplo n.º 9
0
        # '\xab\xb6\xb0\xae\xb5\xb6\xb9\r\x8a'
        # '\xab\xb6\xb0\xae\xb5\xb67\r\x8a'
        # ======================================

        # repr(response) forces python not to interpret \x as a hex value
        # temperature = float(''.join([s for s in repr(response) if s.isdigit()])[0:-1])/1000.0

        temperature = float(response[1:7])

        return temperature, response

    def is_connected(self):
        """
        checks if serial connection is still open with instrument.

        :return: boolean connection status
        """
        return self.serial_connection.isOpen()

    def __del__(self):
        """
        Destructor, to close the serial connection when the instance is this class is garbage collected
        """
        self.serial_connection.close()


if __name__ == '__main__':
    instruments, failed = Instrument.load_and_append(
        instrument_dict={'TemperatureController': TemperatureController})
    print(instruments['TemperatureController']._get_temperature())
Ejemplo n.º 10
0
    def read_probes(self, key):
        pass

    def get_name(self, channel):
        #COMMENT_ME
        for key, value in self.settings:
            if 'channel' in value.keys() and value['channel'] == channel:
                return key

        raise AttributeError('Could not find instrument name attached to channel {s}'.format(channel))


if __name__ == '__main__':

    #pb = Script.load_and_append() #B26PulseBlaster()
    inst, failed = Instrument.load_and_append({'B26PulseBlaster': B26PulseBlaster})

    # for i in range(5):
    #     pulse_collection = [Pulse(channel_id=1, start_time=0, duration=2000),
    #                         Pulse(channel_id=1, start_time=2000, duration=2000),
    #                         Pulse(channel_id=1, start_time=4000, duration=2000),
    #                         Pulse(channel_id=0, start_time=6000, duration=2000)]
    #     # pulse_collection = [Pulse('apd_readout', i, 100) for i in range(0, 2000, 200)]
    #     pb.program_pb(pulse_collection, num_loops=5E5)
    #     pb.start_pulse_seq()
    #     pb.wait()
    #     print 'finished #{0}!'.format(i)

    #   pb.update({'laser': {'status': True}})