Skip to content

Commit

Permalink
292 put error message if pathfinder is not available (#295)
Browse files Browse the repository at this point in the history
* Soft close if Pathfinder server not found

* Handle no ShankCount input

* Version bump

* Update EXE name

* Lint fixes
  • Loading branch information
kjy5 authored Jan 30, 2024
1 parent b6e1083 commit a25294c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ephys_link.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ephys_link/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.2.1"
16 changes: 12 additions & 4 deletions src/ephys_link/platforms/new_scale_pathfinder_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit a25294c

Please sign in to comment.