Skip to content

Commit d9cb040

Browse files
committed
Minor fixes for Linkam module.
* Made base classes private. * Replace addressof with byref to avoid truncation errors. * Fixed get_sdk_version - replaced self with __class__. * Search several locations for license file and throw exception if absent.
1 parent ab43260 commit d9cb040

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

microscope/stages/linkam.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ def __getattribute__(self, name):
900900
}
901901

902902

903-
class LinkamBase(devices.FloatingDeviceMixin, devices.Device):
903+
class _LinkamBase(devices.FloatingDeviceMixin, devices.Device):
904904
"""Base class for connecting to Linkam SDK devices.
905905
906906
This class deals with SDK initialisation and setting callbacks to
@@ -921,7 +921,7 @@ class LinkamBase(devices.FloatingDeviceMixin, devices.Device):
921921
def get_sdk_version():
922922
"""Fetch the SDK version."""
923923
b = ctypes.create_string_buffer(_max_version_length)
924-
self._lib.linkamGetVersion(b, _max_version_length)
924+
__class__._lib.linkamGetVersion(b, _max_version_length)
925925
return b.value
926926

927927
@staticmethod
@@ -939,8 +939,16 @@ def init_sdk():
939939
# sdk_log = b''
940940
#else:
941941
import os
942+
lpaths = ['', os.path.dirname(__file__), os.path.dirname(devices.__file__)]
942943
sdk_log = os.devnull
943-
_lib.linkamInitialiseSDK(sdk_log, b'', True)
944+
while True:
945+
try:
946+
p = lpaths.pop()
947+
except IndexError:
948+
raise Exception("Could not init SDK: no linkam license file (Linkam.lsk) found.")
949+
lskpath = os.path.join(p, 'Linkam.lsk').encode()
950+
if (_lib.linkamInitialiseSDK(sdk_log, lskpath, True)):
951+
break
944952
# NewValue event callback
945953
cfunc = ctypes.CFUNCTYPE(_uint32_t, _CommsHandle, _ControllerStatus)(__class__._on_new_value)
946954
_lib.linkamSetCallbackNewValue(cfunc)
@@ -1130,8 +1138,8 @@ def close_comms(self):
11301138
def open_comms(self):
11311139
"""Open the comms link and store the comms handle."""
11321140
self._process_msg(Msg.OpenComms,
1133-
addressof(self._commsinfo),
1134-
addressof(self._h),
1141+
byref(self._commsinfo),
1142+
byref(self._h),
11351143
result=self._connectionstatus)
11361144
if self._h.value != 0:
11371145
__class__._connectionMap[self._h.value] = self
@@ -1205,7 +1213,7 @@ def get_status(self, *args):
12051213
return status
12061214

12071215

1208-
class LinkamMDSMixin():
1216+
class _LinkamMDSMixin():
12091217
"""A mixin for motor-driven stages"""
12101218
def __init__(self, **kwargs):
12111219
super().__init__(**kwargs)
@@ -1266,7 +1274,7 @@ def get_position(self):
12661274
return pos
12671275

12681276

1269-
class LinkamCMS(LinkamMDSMixin, LinkamBase):
1277+
class LinkamCMS(_LinkamMDSMixin, _LinkamBase):
12701278
"""Linkam correlative-microscopy stage."""
12711279
_refill_map = {'sample': 'sampleDewarFillSignal',
12721280
'external': 'mainDewarFillSignal'}

0 commit comments

Comments
 (0)