|
8 | 8 | from __future__ import annotations |
9 | 9 |
|
10 | 10 | import json |
| 11 | +from sys import exit |
11 | 12 | from typing import TYPE_CHECKING |
12 | 13 | from urllib import request |
| 14 | +from urllib.error import URLError |
13 | 15 |
|
14 | 16 | from ephys_link import common as com |
15 | 17 | from ephys_link.platform_handler import PlatformHandler |
@@ -82,9 +84,11 @@ def __init__(self, port: int = 8080) -> None: |
82 | 84 | # Test connection to New Scale HTTP server |
83 | 85 | try: |
84 | 86 | request.urlopen(f"http://localhost:{self.port}") |
85 | | - except Exception as e: |
86 | | - msg = f"New Scale HTTP server not online on port {self.port}" |
87 | | - raise ValueError(msg) from e |
| 87 | + except URLError: |
| 88 | + print(f"New Scale Pathfinder HTTP server not online on port {self.port}") |
| 89 | + print("Please start the HTTP server and try again.") |
| 90 | + input("Press Enter to exit...") |
| 91 | + exit(1) |
88 | 92 |
|
89 | 93 | def query_data(self) -> dict: |
90 | 94 | """Query New Scale HTTP server for data and return as dict. |
@@ -192,7 +196,11 @@ def _get_angles(self, manipulator_id: str) -> com.AngularOutputData: |
192 | 196 | def _get_shank_count(self, manipulator_id: str) -> com.ShankCountOutputData: |
193 | 197 | for probe in self.query_data()["ProbeArray"]: |
194 | 198 | if probe["Id"] == manipulator_id: |
195 | | - return com.ShankCountOutputData(probe["ShankCount"], "") |
| 199 | + if "ShankCount" in probe: |
| 200 | + return com.ShankCountOutputData(probe["ShankCount"], "") |
| 201 | + |
| 202 | + # Default to 1.0 if shank count is not found |
| 203 | + return com.ShankCountOutputData(1, "") |
196 | 204 |
|
197 | 205 | return com.ShankCountOutputData(-1, "Unable to find manipulator") |
198 | 206 |
|
|
0 commit comments