def __init__(self, hardware, loop=None, broker=None, lock=None): self._broker = broker or Broker() self._hardware = hardware self._loop = loop self.state = None self._lock = lock self._has_homed = False
def __init__( self, protocol: UploadedProtocol, loop: asyncio.AbstractEventLoop, hardware: ThreadManager, motion_lock: ThreadedAsyncLock, ): """Constructor""" self._protocol = protocol self._loop = loop self._hardware = hardware self._motion_lock = motion_lock self._session: typing.Optional[ApiProtocolSession] = None self._broker = Broker() self._broker.subscribe(command_types.COMMAND, self._on_message) self._broker.subscribe(ApiProtocolSession.TOPIC, self._on_message) self._listeners: typing.List[ListenerType] = []
def __init__(self, hardware, loop=None, broker=None, lock=None): self._broker = broker or Broker() self._loop = loop or asyncio.get_event_loop() self.session = None self._session_lock = False self._hardware = hardware self._command_logger = logging.getLogger( 'opentrons.server.command_logger') self._broker.set_logger(self._command_logger) self._motion_lock = lock
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)
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) checked_hw = None if hardware: checked_hw = hardware.sync self.session_manager = SessionManager(hardware=checked_hw, loop=loop, broker=self._broker, lock=lock) self.calibration_manager = CalibrationManager(hardware=checked_hw, loop=loop, broker=self._broker, lock=lock)
def __init__(self, broker): self._broker = broker or Broker()
class ProtocolRunner: """A class that runs an UploadedProtocol. Protocols are run and simulated synchronously. A listener callback can be provided for inspecting and control flow of the protocol execution.""" def __init__( self, protocol: UploadedProtocol, loop: asyncio.AbstractEventLoop, hardware: ThreadManager, motion_lock: ThreadedAsyncLock, ): """Constructor""" self._protocol = protocol self._loop = loop self._hardware = hardware self._motion_lock = motion_lock self._session: typing.Optional[ApiProtocolSession] = None self._broker = Broker() self._broker.subscribe(command_types.COMMAND, self._on_message) self._broker.subscribe(ApiProtocolSession.TOPIC, self._on_message) self._listeners: typing.List[ListenerType] = [] def add_listener(self, listener: ListenerType): """Add a command listener""" self._listeners.append(listener) def remove_listener(self, listener: ListenerType): """Remove a command listener""" self._listeners.remove(listener) def load(self): """Create and simulate the api protocol session""" with ProtocolRunnerContext(self._protocol): self._session = ApiProtocolSession.build_and_prep( name=self._protocol.meta.protocol_file.path.name, contents=self._protocol.get_contents(), hardware=self._hardware, loop=self._loop, broker=self._broker, motion_lock=self._motion_lock, # TODO Amit 8/3/2020 - need an answer for custom labware extra_labware={}) def run(self): """Run the protocol""" if self._session: with ProtocolRunnerContext(self._protocol): self._session.run() def simulate(self): """Simulate the protocol""" if self._session: with ProtocolRunnerContext(self._protocol): self._session.refresh() def cancel(self): """Cancel running""" if self._session: self._session.stop() def pause(self): """Pause running""" if self._session: self._session.pause() def resume(self): """Resume running""" if self._session: self._session.resume() def _on_message(self, msg): """Dispatch the events""" for listener in self._listeners: listener(msg)