From ef486d4c3899890ae1f9e5948dac4a1afbcb48fc Mon Sep 17 00:00:00 2001 From: Ryan howard Date: Wed, 26 Jul 2023 12:53:00 -0400 Subject: [PATCH] gracefully exit gpio --- .../hardware_testing/gravimetric/__main__.py | 25 +++++++++++-------- .../drivers/eeprom/eeprom.py | 1 + .../drivers/gpio/__init__.py | 8 ++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/hardware-testing/hardware_testing/gravimetric/__main__.py b/hardware-testing/hardware_testing/gravimetric/__main__.py index 07609e72da4..b82271eaab4 100644 --- a/hardware-testing/hardware_testing/gravimetric/__main__.py +++ b/hardware-testing/hardware_testing/gravimetric/__main__.py @@ -317,14 +317,19 @@ def _main(args: argparse.Namespace, _ctx: ProtocolContext) -> None: deck_version="2", extra_labware=custom_defs, ) - if args.tip == 0: - for tip in get_tip_volumes_for_qc( - args.pipette, args.channels, args.extra, args.photometric - ): - hw = _ctx._core.get_hardware() - if not _ctx.is_simulating(): - ui.alert_user_ready(f"Ready to run with {tip}ul tip?", hw) - args.tip = tip + try: + if args.tip == 0: + for tip in get_tip_volumes_for_qc( + args.pipette, args.channels, args.extra, args.photometric + ): + hw = _ctx._core.get_hardware() + if not _ctx.is_simulating(): + ui.alert_user_ready(f"Ready to run with {tip}ul tip?", hw) + args.tip = tip + _main(args, _ctx) + else: _main(args, _ctx) - else: - _main(args, _ctx) + except Exception: + pass + finally: + _ctx._core.get_hardware()._backend.eeprom_driver._gpio.__del__() diff --git a/hardware/opentrons_hardware/drivers/eeprom/eeprom.py b/hardware/opentrons_hardware/drivers/eeprom/eeprom.py index 4437158c50a..be2e28694d6 100644 --- a/hardware/opentrons_hardware/drivers/eeprom/eeprom.py +++ b/hardware/opentrons_hardware/drivers/eeprom/eeprom.py @@ -128,6 +128,7 @@ def close(self) -> bool: logger.debug("Closing eeprom file descriptor") os.close(self._eeprom_fd) self._eeprom_fd = -1 + self._gpio.__del__() return True def property_read(self, prop_ids: Optional[Set[PropId]] = None) -> Set[Property]: diff --git a/hardware/opentrons_hardware/drivers/gpio/__init__.py b/hardware/opentrons_hardware/drivers/gpio/__init__.py index bd02bec3adc..bb54878b4b6 100644 --- a/hardware/opentrons_hardware/drivers/gpio/__init__.py +++ b/hardware/opentrons_hardware/drivers/gpio/__init__.py @@ -63,6 +63,14 @@ def __init__(self, consumer_name: Optional[str] = None) -> None: self.deactivate_eeprom_wp() sleep(1) + def __del__(self) -> None: + try: + self._estop_out_line.release() + self._nsync_out_line.release() + self._eeprom_wp_out_line.release() + except Exception: + pass + def activate_estop(self) -> None: """Assert the emergency stop, which will disable all motors.""" self._estop_out_line.set_value(0)