How to use the hardware.hardware function in hardware

To help you get started, we’ve selected a few hardware examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wright-group / PyCMDS / hardware / spectrometers / spectrometers.py View on Github external
### hardware ##################################################################


class Hardware(hw.Hardware):
    
    def __init__(self, *args, **kwargs):
        self.kind = 'spectrometer'
        hw.Hardware.__init__(self, *args, **kwargs)


### import ####################################################################


ini_path = os.path.join(directory, 'spectrometers.ini')
hardwares, gui, advanced_gui = hw.import_hardwares(ini_path, name='Spectrometers', Driver=Driver, GUI=GUI, Hardware=Hardware)
github wright-group / PyCMDS / hardware / delays / delays.py View on Github external
# --- define --------------------------------------------------------------------------------------


main_dir = g.main_dir.read()
app = g.app.read()

directory = os.path.dirname(os.path.abspath(__file__))
ini = wt.kit.INI(os.path.join(directory, 'delays.ini'))


# --- driver --------------------------------------------------------------------------------------


class Driver(hw.Driver):
    
    def __init__(self, *args, **kwargs):
        self.hardware_ini = ini
        self.motor_units = kwargs.pop('motor_units')
        hw.Driver.__init__(self, *args, **kwargs)
        self.factor = self.hardware.factor
        self.factor.write(kwargs['factor'])
        self.motor_limits = self.hardware.motor_limits
        self.motor_position = self.hardware.motor_position
        self.zero_position = self.hardware.zero_position
        self.zero_position.write(kwargs['zero_position'])
        self.recorded['_'.join([self.name, 'zero'])] = [self.zero_position, 'mm', 0.001, self.name[-1], True]
        self.native_per_mm = 1
        
    def save_status(self):
        self.hardware_ini.write(self.name, 'zero_position', self.zero_position.read(self.motor_units))
github wright-group / PyCMDS / hardware / delays / delays.py View on Github external
self.motor_limits = pc.NumberLimits(min_value=0, max_value=50, units='mm')
        self.motor_position = pc.Number(units='mm', display=True, limits=self.motor_limits)        
        self.zero_position = pc.Number(display=True)
        hw.Hardware.__init__(self, *arks, **kwargs)
        self.label = pc.String(self.name, display=True)
        
    def set_motor_position(self, motor_position, units='mm'):
        # TODO: should probably support 'motor native units'
        self.q.push('set_motor_position', motor_position)


# --- import --------------------------------------------------------------------------------------


ini_path = os.path.join(directory, 'delays.ini')
hardwares, gui, advanced_gui = hw.import_hardwares(ini_path, name='Delays', Driver=Driver, GUI=GUI, Hardware=Hardware)
github wright-group / PyCMDS / hardware / opas / opas.py View on Github external
def motor_names(self):
        # TODO: a more thread-safe operation
        return self.driver.motor_names
        
    def run_auto_tune(self, worker):
        self.driver.auto_tune.run(worker)
    
    def set_motor(self, motor, destination):
        self.q.push('set_motor', motor, destination)


### initialize ################################################################


ini_path = os.path.join(directory, 'opas.ini')
hardwares, gui, advanced_gui = hw.import_hardwares(ini_path, name='OPAs', Driver=Driver, GUI=GUI, Hardware=Hardware)
github wright-group / PyCMDS / hardware / filters / filters.py View on Github external
def on_set_zero(self):
        new_zero = self.zero_destination.read('deg')
        self.driver.set_zero(new_zero)
        self.driver.offset.write(0)
        name = self.hardware.name
        g.coset_control.read().zero(name)
        self.driver.get_position()

    def update(self):
        pass


# --- hardware ------------------------------------------------------------------------------------


class Hardware(hw.Hardware):
    
    def __init__(self, *arks, **kwargs):
        self.kind = 'filter'        
        self.factor = pc.Number(1, decimals=0)
        self.motor_limits = pc.NumberLimits(min_value=-360., max_value=360., units='deg')
        self.motor_position = pc.Number(units='deg', display=True, limits=self.motor_limits)        
        self.zero_position = pc.Number(display=True)
        hw.Hardware.__init__(self, *arks, **kwargs)
        self.label = pc.String(self.name, display=True)
        
    def set_motor_position(self, motor_position, units='deg'):
        # TODO: should probably support 'motor native units'
        self.q.push('set_motor_position', motor_position)


# --- import --------------------------------------------------------------------------------------
github wright-group / PyCMDS / hardware / delays / delays.py View on Github external
def update_recorded(self):
        self.recorded.clear()
        self.recorded['d' + str(self.index)] = [self.position, self.native_units, 1., self.label.read(), False]
        self.recorded['d' + str(self.index) + '_position'] = [self.motor_position, 'mm', 1., self.label.read(), False]
        self.recorded['d' + str(self.index) + '_zero'] = [self.zero_position, 'mm', 1., self.label.read(), False] 

    def set_zero(self, new_zero):
        pass



# --- gui -----------------------------------------------------------------------------------------


class GUI(hw.GUI):

    def initialize(self):
        self.layout.addWidget(self.scroll_area)
        # attributes
        self.attributes_table.add('Label', self.hardware.label)
        self.attributes_table.add('Factor', self.hardware.factor)
        self.scroll_layout.addWidget(self.attributes_table)
        # mm input table
        input_table = pw.InputTable()
        input_table.add('Motor Position', None)
        input_table.add('Current', self.hardware.motor_position)
        self.motor_destination = self.hardware.motor_position.associate(display=False)
        input_table.add('Destination', self.motor_destination)
        self.scroll_layout.addWidget(input_table)
        # set mm button
        self.set_motor_button = pw.SetButton('SET POSITION')
github wright-group / PyCMDS / hardware / opas / opas.py View on Github external
def __init__(self, *args, **kwargs):
        self.hardware_ini = ini
        self.index = kwargs['index']
        self.motor_positions = collections.OrderedDict()
        self.homeable = {}  # TODO:
        self.poynting_type = kwargs.pop('poynting_type')
        self.poynting_correction  = None
        self.poynting_curve_path = kwargs.pop('poynting_curve_path')
        hw.Driver.__init__(self, *args, **kwargs)
        if not hasattr(self, 'motor_names'):  # for virtual...
            self.motor_names = ['Delay', 'Crystal', 'Mixer']
        if not hasattr(self, 'curve_paths'):  # for virtual...
            self.curve_paths = collections.OrderedDict()
        if not hasattr(self, 'interaction_string_combo'):  # for virtual...
            self.interaction_string_combo = pc.Combo(allowed_values=['sig'])
        if self.poynting_type is not None:
            self.motor_names += ['Phi', 'Theta'] #TODO: Generalize
        self.curve = None
        # poynting correction
        if self.poynting_type == 'zaber':
            self.poynting_correction = ZaberCorrectionDevice(kwargs.pop('poynting_port'), kwargs.pop('poynting_indexes'))
        else:
            self.poynting_correction = None
            self.poynting_type = None