From a25294cb1206df560f8fa22e5362b94192406870 Mon Sep 17 00:00:00 2001 From: Kenneth Yang <82800265+kjy5@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:25:05 -0800 Subject: [PATCH] 292 put error message if pathfinder is not available (#295) * Soft close if Pathfinder server not found * Handle no ShankCount input * Version bump * Update EXE name * Lint fixes --- ephys_link.spec | 2 +- src/ephys_link/__about__.py | 2 +- .../platforms/new_scale_pathfinder_handler.py | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ephys_link.spec b/ephys_link.spec index f3ba923..2783945 100644 --- a/ephys_link.spec +++ b/ephys_link.spec @@ -22,7 +22,7 @@ exe = EXE( a.binaries, a.datas, [], - name=f"ephys_link-v{version}-Windows-x86_64", + name=f"EphysLink-v{version}", debug=False, bootloader_ignore_signals=False, strip=False, diff --git a/src/ephys_link/__about__.py b/src/ephys_link/__about__.py index c68196d..a955fda 100644 --- a/src/ephys_link/__about__.py +++ b/src/ephys_link/__about__.py @@ -1 +1 @@ -__version__ = "1.2.0" +__version__ = "1.2.1" diff --git a/src/ephys_link/platforms/new_scale_pathfinder_handler.py b/src/ephys_link/platforms/new_scale_pathfinder_handler.py index 7e6553a..ee70073 100644 --- a/src/ephys_link/platforms/new_scale_pathfinder_handler.py +++ b/src/ephys_link/platforms/new_scale_pathfinder_handler.py @@ -8,8 +8,10 @@ from __future__ import annotations import json +from sys import exit from typing import TYPE_CHECKING from urllib import request +from urllib.error import URLError from ephys_link import common as com from ephys_link.platform_handler import PlatformHandler @@ -82,9 +84,11 @@ def __init__(self, port: int = 8080) -> None: # Test connection to New Scale HTTP server try: request.urlopen(f"http://localhost:{self.port}") - except Exception as e: - msg = f"New Scale HTTP server not online on port {self.port}" - raise ValueError(msg) from e + except URLError: + print(f"New Scale Pathfinder HTTP server not online on port {self.port}") + print("Please start the HTTP server and try again.") + input("Press Enter to exit...") + exit(1) def query_data(self) -> dict: """Query New Scale HTTP server for data and return as dict. @@ -192,7 +196,11 @@ def _get_angles(self, manipulator_id: str) -> com.AngularOutputData: def _get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData: for probe in self.query_data()["ProbeArray"]: if probe["Id"] == manipulator_id: - return com.ShankCountOutputData(probe["ShankCount"], "") + if "ShankCount" in probe: + return com.ShankCountOutputData(probe["ShankCount"], "") + + # Default to 1.0 if shank count is not found + return com.ShankCountOutputData(1, "") return com.ShankCountOutputData(-1, "Unable to find manipulator")