From c301402fef745ea32d30a79e24aadc73629f760e Mon Sep 17 00:00:00 2001 From: Florian Rau Date: Wed, 1 Nov 2023 13:21:18 +0000 Subject: [PATCH] optional skipping of Bpod initialization --- iblrig/gui/wizard.py | 4 ++-- iblrig/hardware.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/iblrig/gui/wizard.py b/iblrig/gui/wizard.py index 2752d7524..bffcbd700 100644 --- a/iblrig/gui/wizard.py +++ b/iblrig/gui/wizard.py @@ -651,7 +651,7 @@ def flush(self): self.enable_UI_elements() try: - bpod = Bpod(self.model.hardware_settings['device_bpod']['COM_BPOD']) # bpod is a singleton + bpod = Bpod(self.model.hardware_settings['device_bpod']['COM_BPOD'], skip_initialization=True) bpod.manual_override(bpod.ChannelTypes.OUTPUT, bpod.ChannelNames.VALVE, 1, self.uiPushFlush.isChecked()) except (OSError, exceptions.bpod_error.BpodErrorException): print(traceback.format_exc()) @@ -668,7 +668,7 @@ def toggle_status_led(self, is_toggled: bool): self.enable_UI_elements() try: - bpod = Bpod(self.model.hardware_settings['device_bpod']['COM_BPOD']) + bpod = Bpod(self.model.hardware_settings['device_bpod']['COM_BPOD'], skip_initialization=True) bpod.set_status_led(is_toggled) except (OSError, exceptions.bpod_error.BpodErrorException, AttributeError): self.uiPushStatusLED.setChecked(False) diff --git a/iblrig/hardware.py b/iblrig/hardware.py index 96032b7e0..68f340027 100644 --- a/iblrig/hardware.py +++ b/iblrig/hardware.py @@ -44,10 +44,11 @@ def __new__(cls, *args, **kwargs): Bpod._instances[serial_port] = instance return instance - def __init__(self, *args, **kwargs): - # # skip initialization if it has already been performed before - # if self._is_initialized: - # return + def __init__(self, *args, skip_initialization: bool = False, **kwargs): + # skip initialization if it has already been performed before + # IMPORTANT: only use this for non-critical tasks (e.g., flushing valve from GUI) + if skip_initialization and self._is_initialized: + return # try to instantiate once for nothing try: