Skip to content

Commit

Permalink
update absorbance reader state in protocol engine
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed May 24, 2024
1 parent 92be490 commit 4f5b916
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async def build(
driver=driver,
hw_control_loop=hw_control_loop,
)
await module.setup()
return module

def __init__(
Expand Down Expand Up @@ -181,6 +182,12 @@ async def start_measure(self, wavelength: int) -> List[float]:
measurement = await self._driver.get_single_measurement(wavelength)
return measurement

async def setup(self) -> None:
"""Setup the Absorbance Reader."""
is_open = await self._driver.is_connected()
if not is_open:
await self._driver.connect()

async def get_current_wavelength(self) -> None:
"""Get the Absorbance Reader's current active wavelength."""
pass
Expand Down
1 change: 1 addition & 0 deletions api/src/opentrons/protocol_api/core/engine/module_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def initialize(self, wavelength: int) -> None:
self._engine_client.absorbance_reader_initialize(
module_id=self.module_id, wavelength=wavelength
)
self._initialized_value = wavelength

def initiate_read(self) -> None:
"""Initiate read on the Absorbance Reader."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Heater-Shaker Module sub-state."""
from dataclasses import dataclass
from typing import NewType
from typing import NewType, Optional, List


AbsorbanceReaderId = NewType("AbsorbanceReaderId", str)
Expand All @@ -11,3 +11,7 @@ class AbsorbanceReaderSubState:
"""Absorbance-Plate-Reader-specific state."""

module_id: AbsorbanceReaderId
configured: bool
measured: bool
data: Optional[List[float]]
configured_wavelength: Optional[int]
50 changes: 49 additions & 1 deletion api/src/opentrons/protocol_engine/state/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
heater_shaker,
temperature_module,
thermocycler,
absorbance_reader,
)
from ..actions import Action, SucceedCommandAction, AddModuleAction
from .abstract_store import HasState, HandlesActions
Expand Down Expand Up @@ -265,6 +266,15 @@ def _handle_command(self, command: Command) -> None:
):
self._handle_thermocycler_module_commands(command)

if isinstance(
command.result,
(
absorbance_reader.InitializeResult,
absorbance_reader.MeasureAbsorbanceResult,
),
):
self._handle_absorbance_reader_commands(command)

def _add_module_substate(
self,
module_id: str,
Expand Down Expand Up @@ -325,7 +335,11 @@ def _add_module_substate(
)
elif ModuleModel.is_absorbance_reader(actual_model):
self._state.substate_by_module_id[module_id] = AbsorbanceReaderSubState(
module_id=AbsorbanceReaderId(module_id)
module_id=AbsorbanceReaderId(module_id),
configured=False,
measured=False,
data=None,
configured_wavelength=None,
)

def _update_additional_slots_occupied_by_thermocycler(
Expand Down Expand Up @@ -515,6 +529,40 @@ def _handle_thermocycler_module_commands(
target_lid_temperature=lid_temperature,
)

def _handle_absorbance_reader_commands(
self,
command: Union[
absorbance_reader.Initialize,
absorbance_reader.MeasureAbsorbance,
],
) -> None:
module_id = command.params.moduleId
absorbance_reader_substate = self._state.substate_by_module_id[module_id]
assert isinstance(
absorbance_reader_substate, AbsorbanceReaderSubState
), f"{module_id} is not an absorbance plate reader."

# Get current values
configured = absorbance_reader_substate.configured
configured_wavelength = absorbance_reader_substate.configured_wavelength

if isinstance(command.result, absorbance_reader.InitializeResult):
self._state.substate_by_module_id[module_id] = AbsorbanceReaderSubState(
module_id=AbsorbanceReaderId(module_id),
configured=True,
measured=False,
data=None,
configured_wavelength=command.params.sampleWavelength,
)
elif isinstance(command.result, absorbance_reader.MeasureAbsorbanceResult):
self._state.substate_by_module_id[module_id] = AbsorbanceReaderSubState(
module_id=AbsorbanceReaderId(module_id),
configured=configured,
configured_wavelength=configured_wavelength,
measured=True,
data=command.result.data,
)


class ModuleView(HasState[ModuleState]):
"""Read-only view of computed module state."""
Expand Down

0 comments on commit 4f5b916

Please sign in to comment.