Esempio n. 1
0
def test_synch_adapter(loop):
    api = API.build_hardware_simulator(loop=loop)
    synch = adapters.SynchronousAdapter(api)
    synch.cache_instruments({Mount.LEFT: 'p10_single'})
    assert synch.attached_instruments[Mount.LEFT]['name']\
                .startswith('p10_single')
    synch.join()
Esempio n. 2
0
 def __init__(self, hardware):
     if None is hardware:
         self._is_orig = True
         self._current = adapters.SynchronousAdapter.build(
             API.build_hardware_simulator)
     elif isinstance(hardware, adapters.SynchronousAdapter):
         self._is_orig = False
         self._current = hardware
     else:
         self._is_orig = False
         self._current = adapters.SynchronousAdapter(hardware)
Esempio n. 3
0
 def set_hw(self, hardware):
     if self._is_orig:
         self._is_orig = False
         self._current.join()
     if isinstance(hardware, adapters.SynchronousAdapter):
         self._current = hardware
     elif isinstance(hardware, HardwareAPILike):
         self._current = adapters.SynchronousAdapter(hardware)
     else:
         raise TypeError(
             "hardware should be API or synch adapter but is {}"
             .format(hardware))
     return self._current
Esempio n. 4
0
    def __init__(self, hardware=None, loop=None, lock=None):
        topics = [Session.TOPIC, CalibrationManager.TOPIC]
        self._broker = Broker()
        self._notifications = Notifications(topics, self._broker, loop=loop)

        if hardware:
            hardware = adapters.SynchronousAdapter(hardware)
        self.session_manager = SessionManager(hardware=hardware,
                                              loop=loop,
                                              broker=self._broker,
                                              lock=lock)
        self.calibration_manager = CalibrationManager(hardware=hardware,
                                                      loop=loop,
                                                      broker=self._broker,
                                                      lock=lock)
Esempio n. 5
0
    def load_module(
            self, module_name: str,
            location: Optional[types.DeckLocation] = None) -> ModuleTypes:
        """ Load a module onto the deck given its name.

        This is the function to call to use a module in your protocol, like
        :py:meth:`load_instrument` is the method to call to use an instrument
        in your protocol. It returns the created and initialized module
        context, which will be a different class depending on the kind of
        module loaded.

        A map of deck positions to loaded modules can be accessed later
        using :py:attr:`loaded_modules`.

        :param str module_name: The name of the module.
        :param location: The location of the module. This is usually the
                         name or number of the slot on the deck where you
                         will be placing the module. Some modules, like
                         the Thermocycler, are only valid in one deck
                         location. You do not have to specify a location
                         when loading a Thermocycler - it will always be
                         in Slot 7.
        :type location: str or int or None
        :returns ModuleContext: The loaded and initialized
                                :py:class:`ModuleContext`.
        """
        resolved_name = ModuleGeometry.resolve_module_name(module_name)
        resolved_location = self._deck_layout.resolve_module_location(
                resolved_name, location)
        geometry = load_module(resolved_name,
                               self._deck_layout.position_for(
                                    resolved_location))
        hc_mod_instance = None
        hw = self._hw_manager.hardware._api._backend
        mod_class = {
            'magdeck': MagneticModuleContext,
            'tempdeck': TemperatureModuleContext,
            'thermocycler': ThermocyclerContext}[resolved_name]
        for mod in self._hw_manager.hardware.attached_modules:
            if mod.name() == resolved_name:
                hc_mod_instance = adapters.SynchronousAdapter(mod)
                break

        if isinstance(hw, Simulator) and hc_mod_instance is None:
            mod_type = {
                'magdeck': modules.magdeck.MagDeck,
                'tempdeck': modules.tempdeck.TempDeck,
                'thermocycler': modules.thermocycler.Thermocycler
                }[resolved_name]
            hc_mod_instance = adapters.SynchronousAdapter(mod_type(
                port='', simulating=True, loop=self._loop))
        if hc_mod_instance:
            mod_ctx = mod_class(self,
                                hc_mod_instance,
                                geometry,
                                self.api_version,
                                self._loop)
        else:
            raise RuntimeError(
                f'Could not find specified module: {resolved_name}')
        self._modules.add(mod_ctx)
        self._deck_layout[resolved_location] = geometry
        return mod_ctx