Skip to content

Commit

Permalink
add error code names
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed May 14, 2024
1 parent 34f0eee commit 5e82350
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
31 changes: 16 additions & 15 deletions api/src/opentrons/drivers/absorbance_reader/async_byonoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Optional, List, Dict


from .hid_protocol import AbsorbanceHidInterface as AbsProtocol
from .hid_protocol import AbsorbanceHidInterface as AbsProtocol, ErrorCodeNames
from opentrons.drivers.types import (
AbsorbanceReaderLidStatus,
AbsorbanceReaderPlatePresence,
Expand Down Expand Up @@ -127,33 +127,37 @@ def verify_device_handle(self) -> int:
)
return self._device_handle

def _raise_if_error(
self,
err_name: ErrorCodeNames,
msg: str = "Error occurred: ",
) -> None:
if err_name != "BYONOY_ERROR_NO_ERROR":
raise RuntimeError(msg, err_name)

def _get_device_information(self) -> AbsProtocol.DeviceInfo:
handle = self.verify_device_handle()
err, device_info = self._interface.byonoy_get_device_information(handle)
if err.name != "BYONOY_ERROR_NO_ERROR":
raise RuntimeError(f"Error getting device information: {err}")
self._raise_if_error(err.name, "Error getting device information: ")
return device_info

def _get_device_status(self) -> AbsProtocol.DeviceState:
handle = self.verify_device_handle()
err, status = self._interface.byonoy_get_device_status(handle)
if err.name != "BYONOY_ERROR_NO_ERROR":
raise RuntimeError(f"Error getting device status: {err}")
self._raise_if_error(err.name, "Error getting device status: ")
return status

def _get_slot_status(self) -> AbsProtocol.SlotState:
handle = self.verify_device_handle()
err, slot_status = self._interface.byonoy_get_device_slot_status(handle)
if err.name != "BYONOY_ERROR_NO_ERROR":
raise RuntimeError(f"Error getting slot status: {err}")
self._raise_if_error(err.name, "Error getting slot status: ")
return slot_status

def _get_lid_status(self) -> bool:
handle = self.verify_device_handle()
lid_on: bool
err, lid_on = self._interface.byonoy_get_device_parts_aligned(handle)
if err.name != "BYONOY_ERROR_NO_ERROR":
raise RuntimeError(f"Error getting slot status: {err}")
self._raise_if_error(err.name, "Error getting lid status: ")
return lid_on

def _get_supported_wavelengths(self) -> List[int]:
Expand All @@ -162,24 +166,21 @@ def _get_supported_wavelengths(self) -> List[int]:
err, wavelengths = self._interface.byonoy_abs96_get_available_wavelengths(
handle
)
if err.name != "BYONOY_ERROR_NO_ERROR":
raise RuntimeError(f"Error getting supported wavelengths: {err}")
self._raise_if_error(err.name, "Error getting available wavelengths: ")
self._supported_wavelengths = wavelengths
return wavelengths

def _initialize_measurement(self, conf: AbsProtocol.MeasurementConfig) -> None:
handle = self.verify_device_handle()
err = self._interface.byonoy_abs96_initialize_single_measurement(handle, conf)
if err.name != "BYONOY_ERROR_NO_ERROR":
raise RuntimeError(f"Error initializing measurement: {err}")
self._raise_if_error(err.name, "Error initializing measurement: ")
self._current_config = conf

def _single_measurement(self, conf: AbsProtocol.MeasurementConfig) -> List[float]:
handle = self.verify_device_handle()
measurements: List[float]
err, measurements = self._interface.byonoy_abs96_single_measure(handle, conf)
if err.name != "BYONOY_ERROR_NO_ERROR":
raise RuntimeError(f"Error getting single measurement: {err}")
self._raise_if_error(err.name, "Error getting single measurement: ")
return measurements

def _set_sample_wavelength(self, wavelength: int) -> AbsProtocol.MeasurementConfig:
Expand Down
30 changes: 28 additions & 2 deletions api/src/opentrons/drivers/absorbance_reader/hid_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Dict,
Protocol,
List,
Literal,
Tuple,
ClassVar,
runtime_checkable,
Expand All @@ -10,6 +11,31 @@

Response = TypeVar("Response")

ErrorCodeNames = Literal[
"BYONOY_ERROR_NO_ERROR",
"BYONOY_ERROR_UNKNOWN_ERROR",
"BYONOY_ERROR_DEVICE_CLOSED",
"BYONOY_ERROR_INVALID_ARGUMENT",
"BYONOY_ERROR_NO_MEMORY",
"BYONOY_ERROR_UNSUPPORTED_OPERATION",
"BYONOY_ERROR_DEVICE_COMMUNICATION_FAILURE",
"BYONOY_ERROR_DEVICE_OPERATION_FAILED",
"BYONOY_ERROR_DEVICE_OPEN_PREFIX",
"BYONOY_ERROR_DEVICE_NOT_FOUND",
"BYONOY_ERROR_DEVICE_TOO_NEW",
"BYONOY_ERROR_DEVICE_ALREADY_OPEN",
"BYONOY_ERROR_FIRMWARE_UPDATE_ERROR_PREFIX",
"BYONOY_ERROR_FIRMWARE_UPDATE_FILE_NOT_FOUND",
"BYONOY_ERROR_FIRMWARE_UPDATE_FILE_NOT_VALID",
"BYONOY_ERROR_FIRMWARE_UPDATE_FAILED",
"BYONOY_ERROR_FILE_ERROR_PREFIX",
"BYONOY_ERROR_FILE_WRITE_ERROR",
"BYONOY_ERROR_MEASUTEMNT_ERROR_PREFIX",
"BYONOY_ERROR_MEASUTEMNT_SLOT_NOT_EMPTY",
"BYONOY_ERROR_NOT_INITIALIZED",
"BYONOY_ERROR_INTERNAL",
]


@runtime_checkable
class AbsorbanceHidInterface(Protocol):
Expand All @@ -19,8 +45,8 @@ class Device(Protocol):

@runtime_checkable
class ErrorCode(Protocol):
__members__: Dict[str, int]
name: str
__members__: Dict[ErrorCodeNames, int]
name: ErrorCodeNames
value: int

@runtime_checkable
Expand Down

0 comments on commit 5e82350

Please sign in to comment.