Skip to content

Commit 713be61

Browse files
authored
No error in init (#457)
* Does not crash if invalid connection * Version bump * Hatch static analysis * Move initial axis count to init * Hatch static analysis * Fix type hint for axis_count and remove redundant type check
1 parent a65228f commit 713be61

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/ephys_link/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.1.0b0"
1+
__version__ = "2.1.0b1"

src/ephys_link/bindings/ump_binding.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,9 @@ def __init__(self) -> None:
3434
UMP.set_library_path(RESOURCES_DIRECTORY)
3535
self._ump: UMP = UMP.get_ump() # pyright: ignore [reportUnknownMemberType]
3636

37-
# Exit if no manipulators are connected.
38-
device_ids: list[str] = list(map(str, self._ump.list_devices()))
39-
if len(device_ids) == 0:
40-
msg = "No manipulators connected."
41-
raise RuntimeError(msg)
42-
43-
# Currently only supports using uMp-4 XOR uMp-3. Exit if both are connected.
44-
45-
# Use the first device as the reference for the number of axes.
46-
self.num_axes: int = self._get_device(device_ids[0]).n_axes()
47-
48-
if any(self._get_device(device_id).n_axes() != self.num_axes for device_id in device_ids): # pyright: ignore [reportUnknownArgumentType, reportUnknownMemberType]
49-
msg = "uMp-4 and uMp-3 cannot be used at the same time."
50-
raise RuntimeError(msg)
37+
# Compute axis count, assumed as the first device. 0 if no devices are connected.
38+
device_ids = list(map(str, self._ump.list_devices()))
39+
self.axis_count: int = 0 if len(device_ids) == 0 else self._get_device(device_ids[0]).n_axes()
5140

5241
@staticmethod
5342
@override
@@ -61,11 +50,18 @@ def get_cli_name() -> str:
6150

6251
@override
6352
async def get_manipulators(self) -> list[str]:
64-
return list(map(str, self._ump.list_devices()))
53+
device_ids = list(map(str, self._ump.list_devices()))
54+
55+
# Currently only supports using uMp-4 XOR uMp-3. Throw error if both are connected.
56+
if any(self._get_device(device_id).n_axes() != self.axis_count for device_id in device_ids): # pyright: ignore [reportUnknownArgumentType]
57+
msg = "uMp-4 and uMp-3 cannot be used at the same time."
58+
raise RuntimeError(msg)
59+
60+
return device_ids
6561

6662
@override
6763
async def get_axes_count(self) -> int:
68-
return self.num_axes
64+
return self.axis_count
6965

7066
@override
7167
def get_dimensions(self) -> Vector4:
@@ -236,4 +232,4 @@ def _is_ump_3(self) -> bool:
236232
Returns:
237233
True if the device is uMp-3, False otherwise.
238234
"""
239-
return self.num_axes == self.UMP_3_NUM_AXES
235+
return self.axis_count == self.UMP_3_NUM_AXES

0 commit comments

Comments
 (0)