From 7b3bd9ccbbf8665b49bba153bf6a1d025ee1289d Mon Sep 17 00:00:00 2001 From: jborbely Date: Fri, 8 Dec 2023 16:33:08 +1300 Subject: [PATCH] call AVS_Done only if all handles were deactivated --- msl/equipment/resources/avantes/avaspec.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/msl/equipment/resources/avantes/avaspec.py b/msl/equipment/resources/avantes/avaspec.py index e25ef9d..b5fe99e 100644 --- a/msl/equipment/resources/avantes/avaspec.py +++ b/msl/equipment/resources/avantes/avaspec.py @@ -471,6 +471,8 @@ class DeviceConfigType(Structure): from ctypes import CFUNCTYPE FUNCTYPE = CFUNCTYPE +_handles: list[int] = [] + MeasureCallback = FUNCTYPE(None, POINTER(c_int32), POINTER(c_int32)) """Used as a decorator for a callback function when a scan is available.""" @@ -768,14 +770,18 @@ def activate(self): for item in out: if item.SerialNumber.decode() == self.equipment_record.serial: self._handle = self.sdk.AVS_Activate(item) + if self._handle == INVALID_AVS_HANDLE_VALUE: + self.raise_exception('Invalid handle') + _handles.append(self._handle) return self.raise_exception('Did not find the Avantes serial number {!r}' 'in the list of devices.'.format(self.equipment_record.serial)) def deactivate(self): """Closes communication with the spectrometer.""" - if self._handle: + if self._handle != INVALID_AVS_HANDLE_VALUE: self.sdk.AVS_Deactivate(self._handle) + _handles.remove(self._handle) self._handle = None def get_analog_in(self, analog_id): @@ -1054,7 +1060,8 @@ def disconnect(self): """Closes communication with the spectrometer.""" if self._handle is not None: self.deactivate() - self.done() + if not _handles: + self.done() def get_ip_config(self): """Retrieve IP settings from the spectrometer.