From 57685d02f411beb477c742c34d4057d5344ef1be Mon Sep 17 00:00:00 2001 From: Franz Hempel Date: Wed, 22 May 2024 15:29:19 +0200 Subject: [PATCH] MCC DAQ -> Handle import error in connect and find_ports to allow loading driver in GUI --- src/Logger-MCC_DAQ/main.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Logger-MCC_DAQ/main.py b/src/Logger-MCC_DAQ/main.py index 336c607d..80550317 100644 --- a/src/Logger-MCC_DAQ/main.py +++ b/src/Logger-MCC_DAQ/main.py @@ -42,7 +42,7 @@ from mcculw import ul from mcculw.device_info import DaqDeviceInfo from mcculw.enums import AnalogInputMode, InterfaceType, ULRange -except FileNotFoundError: +except: mcculw_library_missing = True @@ -61,9 +61,6 @@ class Device(EmptyDevice): def __init__(self) -> None: """Initialize driver parameters.""" EmptyDevice.__init__(self) - if mcculw_library_missing: - msg = "MCC DAQ Software missing. Install Universal Library (UL)." - raise ImportError(msg) self.shortname = "MCC-DAQ" # short name will be shown in the sequencer self.variables = [] @@ -84,12 +81,15 @@ def __init__(self) -> None: self.daq_info = None # AI Range - self.available_ai_ranges = { - "10 V": ULRange.BIP10VOLTS, - "5 V": ULRange.BIP5VOLTS, - "2 V": ULRange.BIP2VOLTS, - "1 V": ULRange.BIP1VOLTS, - } + if mcculw_library_missing: + self.available_ai_ranges = {} + else: + self.available_ai_ranges = { + "10 V": ULRange.BIP10VOLTS, + "5 V": ULRange.BIP5VOLTS, + "2 V": ULRange.BIP2VOLTS, + "1 V": ULRange.BIP1VOLTS, + } self.ai_range = None def set_GUIparameter(self) -> dict: # noqa: N802 @@ -115,6 +115,7 @@ def get_GUIparameter(self, parameter: dict) -> None: # noqa: N802 def find_ports(self) -> list: """Find ports of available DAQ devices.""" + self.check_mcculw() ul.ignore_instacal() ul.release_daq_device(self.board_num) @@ -127,6 +128,7 @@ def find_ports(self) -> list: def connect(self) -> None: """Connect to the selected port.""" + self.check_mcculw() ul.ignore_instacal() inventory = ul.get_daq_device_inventory(InterfaceType.ANY) @@ -200,3 +202,10 @@ def create_device_list() -> list: device_list.append(str(device) + "_" + device.unique_id) return device_list + + @staticmethod + def check_mcculw() -> None: + """Check if the mcculw library is installed.""" + if mcculw_library_missing: + msg = "MCC DAQ Software missing. Install Universal Library (UL)." + raise ImportError(msg)