Skip to content

Commit

Permalink
call AVS_Done only if all handles were deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
jborbely committed Dec 8, 2023
1 parent e6d5a97 commit 7b3bd9c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions msl/equipment/resources/avantes/avaspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7b3bd9c

Please sign in to comment.