Skip to content

Commit

Permalink
[Avantes] check if handle/sdk are None on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
jborbely committed Dec 8, 2023
1 parent 7b3bd9c commit 1af65e7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions msl/equipment/resources/avantes/avaspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ def __init__(self, record):
A record from an :ref:`equipment-database`.
"""
self._handle = None
self._sdk = None
libtype = 'windll' if IS_WINDOWS else 'cdll'
super(Avantes, self).__init__(record, libtype)
self.set_exception_class(AvantesError)
Expand Down Expand Up @@ -779,7 +780,7 @@ def activate(self):

def deactivate(self):
"""Closes communication with the spectrometer."""
if self._handle != INVALID_AVS_HANDLE_VALUE:
if self._handle is not None and self._handle != INVALID_AVS_HANDLE_VALUE:
self.sdk.AVS_Deactivate(self._handle)
_handles.remove(self._handle)
self._handle = None
Expand Down Expand Up @@ -1054,14 +1055,14 @@ def get_status_by_serial(self, serial=None):

def done(self):
"""Closes communication and releases internal storage."""
self.sdk.AVS_Done()
if self._sdk is not None:
self.sdk.AVS_Done()

def disconnect(self):
"""Closes communication with the spectrometer."""
if self._handle is not None:
self.deactivate()
if not _handles:
self.done()
self.deactivate()
if not _handles:
self.done()

def get_ip_config(self):
"""Retrieve IP settings from the spectrometer.
Expand Down

0 comments on commit 1af65e7

Please sign in to comment.