Fix/minor lamni fixes #292
@@ -95,6 +95,22 @@ class GalilController(Controller):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _wait_for_thread_idle(self, thread_id: int, timeout: float = 2.0) -> None:
|
||||
"""Poll until the given controller thread is no longer executing.
|
||||
|
||||
XQ dispatches a routine asynchronously and returns as soon as it starts,
|
||||
not once it finishes. #NEWPAR briefly keeps thread 0 busy dispatching a
|
||||
move, and the actual dispatch time varies with controller load, so a
|
||||
fixed sleep before starting the next routine on the same thread
|
||||
(#FES/#FRM) is inherently racy: send it too early and the controller
|
||||
replies '?' with error 19 ("thread already running") instead of ':'.
|
||||
"""
|
||||
start = time.time()
|
||||
while self.is_thread_active(thread_id):
|
||||
if time.time() - start > timeout:
|
||||
raise GalilError(f"Thread {thread_id} did not become idle within {timeout} s.")
|
||||
time.sleep(0.02)
|
||||
|
||||
def stop_all_axes(self) -> str:
|
||||
if not self.is_thread_active(1):
|
||||
return self.socket_put_and_receive("XQ#STOP,1")
|
||||
@@ -201,7 +217,7 @@ class GalilController(Controller):
|
||||
self.socket_put_confirmed(f"naxis={axis_Id_numeric}")
|
||||
self.socket_put_confirmed(f"ndir={direction_flag}")
|
||||
self.socket_put_confirmed("XQ#NEWPAR")
|
||||
time.sleep(0.2)
|
||||
self._wait_for_thread_idle(0)
|
||||
self.socket_put_confirmed("XQ#FES")
|
||||
time.sleep(0.1)
|
||||
axis_Id = self.axis_Id_numeric_to_alpha(axis_Id_numeric)
|
||||
@@ -236,7 +252,7 @@ class GalilController(Controller):
|
||||
time.sleep(0.1)
|
||||
self.socket_put_confirmed(f"naxis={axis_Id_numeric}")
|
||||
self.socket_put_and_receive("XQ#NEWPAR")
|
||||
time.sleep(0.3)
|
||||
self._wait_for_thread_idle(0)
|
||||
self.socket_put_confirmed("XQ#FRM")
|
||||
time.sleep(0.1)
|
||||
axis_Id = self.axis_Id_numeric_to_alpha(axis_Id_numeric)
|
||||
|
||||
@@ -257,7 +257,7 @@ class SmaractController(Controller):
|
||||
def get_communication_mode(self) -> SmaractCommunicationMode:
|
||||
return_val = self.socket_put_and_receive("GCM")
|
||||
if self._message_starts_with(return_val, f":CM"):
|
||||
return SmaractCommunicationMode(int(return_val.strip(":CM")))
|
||||
return SmaractCommunicationMode(int(return_val.removeprefix(":CM")))
|
||||
|
||||
@retry_once
|
||||
@axis_checked
|
||||
@@ -277,7 +277,7 @@ class SmaractController(Controller):
|
||||
"""
|
||||
return_val = self.socket_put_and_receive("GIV")
|
||||
if self._message_starts_with(return_val, f":IV"):
|
||||
return return_val.strip(":IV")
|
||||
return return_val.removeprefix(":IV")
|
||||
|
||||
@retry_once
|
||||
def get_number_of_channels(self) -> int:
|
||||
@@ -294,7 +294,7 @@ class SmaractController(Controller):
|
||||
"""
|
||||
return_val = self.socket_put_and_receive("GNC")
|
||||
if self._message_starts_with(return_val, f":N"):
|
||||
return int(return_val.strip(":N"))
|
||||
return int(return_val.removeprefix(":N"))
|
||||
|
||||
@retry_once
|
||||
def get_system_id(self) -> str:
|
||||
@@ -305,7 +305,7 @@ class SmaractController(Controller):
|
||||
"""
|
||||
return_val = self.socket_put_and_receive("GSI")
|
||||
if self._message_starts_with(return_val, f":ID"):
|
||||
return return_val.strip(":ID")
|
||||
return return_val.removeprefix(":ID")
|
||||
|
||||
@retry_once
|
||||
def reset(self) -> None:
|
||||
@@ -348,7 +348,7 @@ class SmaractController(Controller):
|
||||
if self._message_starts_with(return_val, f":GPL{axis_Id_numeric}"):
|
||||
return [
|
||||
float(limit) / 1e6
|
||||
for limit in return_val.strip(f":GPL{axis_Id_numeric},").split(",")
|
||||
for limit in return_val.removeprefix(f":GPL{axis_Id_numeric},").split(",")
|
||||
]
|
||||
|
||||
@retry_once
|
||||
@@ -376,7 +376,9 @@ class SmaractController(Controller):
|
||||
def get_sensor_type(self, axis_Id_numeric: int) -> SmaractSensorDefinition:
|
||||
return_val = self.socket_put_and_receive(f"GST{axis_Id_numeric}")
|
||||
if self._message_starts_with(return_val, f":ST{axis_Id_numeric}"):
|
||||
return self._sensors.avail_sensors.get(int(return_val.strip(f":ST{axis_Id_numeric},")))
|
||||
return self._sensors.avail_sensors.get(
|
||||
int(return_val.removeprefix(f":ST{axis_Id_numeric},"))
|
||||
)
|
||||
|
||||
@retry_once
|
||||
@axis_checked
|
||||
@@ -419,7 +421,7 @@ class SmaractController(Controller):
|
||||
|
||||
return_val = self.socket_put_and_receive(f"GCLS{axis_Id_numeric}")
|
||||
if self._message_starts_with(return_val, f":CLS{axis_Id_numeric}"):
|
||||
return float(return_val.strip(f":CLS{axis_Id_numeric},")) * 1e6
|
||||
return float(return_val.removeprefix(f":CLS{axis_Id_numeric},")) * 1e6
|
||||
|
||||
def describe(self) -> None:
|
||||
t = PrettyTable()
|
||||
|
||||
@@ -102,6 +102,7 @@ def test_axis_put(leyey, target_pos, socket_put_messages, socket_get_messages):
|
||||
b"naxis=0\r",
|
||||
b"ndir=1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"MG_XQ0\r",
|
||||
b"XQ#FES\r",
|
||||
b"MG_BGA\r",
|
||||
b"MGbcklact[0]\r",
|
||||
@@ -109,7 +110,7 @@ def test_axis_put(leyey, target_pos, socket_put_messages, socket_get_messages):
|
||||
b"MG_XQ2\r",
|
||||
b"MG _LRA, _LFA\r",
|
||||
],
|
||||
[b":", b":", b":", b":", b"0", b"0", b"-1", b"-1", b"1.000 0.000"],
|
||||
[b":", b":", b":", b"-1", b":", b"0", b"0", b"-1", b"-1", b"1.000 0.000"],
|
||||
),
|
||||
(
|
||||
1,
|
||||
@@ -118,6 +119,7 @@ def test_axis_put(leyey, target_pos, socket_put_messages, socket_get_messages):
|
||||
b"naxis=1\r",
|
||||
b"ndir=-1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"MG_XQ0\r",
|
||||
b"XQ#FES\r",
|
||||
b"MG_BGB\r",
|
||||
b"MGbcklact[1]\r",
|
||||
@@ -125,7 +127,7 @@ def test_axis_put(leyey, target_pos, socket_put_messages, socket_get_messages):
|
||||
b"MG_XQ2\r",
|
||||
b"MG _LRB, _LFB\r",
|
||||
],
|
||||
[b":", b":", b":", b":", b"0", b"0", b"-1", b"-1", b"0.000 1.000"],
|
||||
[b":", b":", b":", b"-1", b":", b"0", b"0", b"-1", b"-1", b"0.000 1.000"],
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -144,6 +146,7 @@ def test_drive_axis_to_limit(leyex, axis_nr, direction, socket_put_messages, soc
|
||||
[
|
||||
b"naxis=0\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"MG_XQ0\r",
|
||||
b"XQ#FRM\r",
|
||||
b"MG_BGA\r",
|
||||
b"MGbcklact[0]\r",
|
||||
@@ -151,13 +154,14 @@ def test_drive_axis_to_limit(leyex, axis_nr, direction, socket_put_messages, soc
|
||||
b"MG_XQ2\r",
|
||||
b"MG axisref[0]\r",
|
||||
],
|
||||
[b":", b":", b":", b"0", b"0", b"-1", b"-1", b"1.00"],
|
||||
[b":", b":", b"-1", b":", b"0", b"0", b"-1", b"-1", b"1.00"],
|
||||
),
|
||||
(
|
||||
1,
|
||||
[
|
||||
b"naxis=1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"MG_XQ0\r",
|
||||
b"XQ#FRM\r",
|
||||
b"MG_BGB\r",
|
||||
b"MGbcklact[1]\r",
|
||||
@@ -165,7 +169,7 @@ def test_drive_axis_to_limit(leyex, axis_nr, direction, socket_put_messages, soc
|
||||
b"MG_XQ2\r",
|
||||
b"MG axisref[1]\r",
|
||||
],
|
||||
[b":", b":", b":", b"0", b"0", b"-1", b"-1", b"1.00"],
|
||||
[b":", b":", b"-1", b":", b"0", b"0", b"-1", b"-1", b"1.00"],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -85,6 +85,7 @@ def test_axis_put(leyey, target_pos, socket_put_messages, socket_get_messages):
|
||||
b"naxis=0\r",
|
||||
b"ndir=1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"MG_XQ0\r",
|
||||
b"XQ#FES\r",
|
||||
b"MG_XQ0\r",
|
||||
b"MG _MOA\r",
|
||||
@@ -92,7 +93,7 @@ def test_axis_put(leyey, target_pos, socket_put_messages, socket_get_messages):
|
||||
b"MG _MOA\r",
|
||||
b"MG _LRA, _LFA\r",
|
||||
],
|
||||
[b":", b":", b":", b":", b"0", b"0", b"-1", b"-1", b"1.000 0.000"],
|
||||
[b":", b":", b":", b"-1", b":", b"0", b"0", b"-1", b"-1", b"1.000 0.000"],
|
||||
),
|
||||
(
|
||||
1,
|
||||
@@ -101,6 +102,7 @@ def test_axis_put(leyey, target_pos, socket_put_messages, socket_get_messages):
|
||||
b"naxis=1\r",
|
||||
b"ndir=-1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"MG_XQ0\r",
|
||||
b"XQ#FES\r",
|
||||
b"MG_XQ0\r",
|
||||
b"MG _MOB\r",
|
||||
@@ -108,7 +110,7 @@ def test_axis_put(leyey, target_pos, socket_put_messages, socket_get_messages):
|
||||
b"MG _MOB\r",
|
||||
b"MG _LRB, _LFB\r",
|
||||
],
|
||||
[b":", b":", b":", b":", b"0", b"0", b"-1", b"-1", b"0.000 1.000"],
|
||||
[b":", b":", b":", b"-1", b":", b"0", b"0", b"-1", b"-1", b"0.000 1.000"],
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -127,6 +129,7 @@ def test_drive_axis_to_limit(leyex, axis_nr, direction, socket_put_messages, soc
|
||||
[
|
||||
b"naxis=0\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"MG_XQ0\r",
|
||||
b"XQ#FRM\r",
|
||||
b"MG_XQ0\r",
|
||||
b"MG _MOA\r",
|
||||
@@ -134,13 +137,14 @@ def test_drive_axis_to_limit(leyex, axis_nr, direction, socket_put_messages, soc
|
||||
b"MG _MOA\r",
|
||||
b"MG axisref[0]\r",
|
||||
],
|
||||
[b":", b":", b":", b"0", b"0", b"-1", b"-1", b"1.00"],
|
||||
[b":", b":", b"-1", b":", b"0", b"0", b"-1", b"-1", b"1.00"],
|
||||
),
|
||||
(
|
||||
1,
|
||||
[
|
||||
b"naxis=1\r",
|
||||
b"XQ#NEWPAR\r",
|
||||
b"MG_XQ0\r",
|
||||
b"XQ#FRM\r",
|
||||
b"MG_XQ0\r",
|
||||
b"MG _MOB\r",
|
||||
@@ -148,7 +152,7 @@ def test_drive_axis_to_limit(leyex, axis_nr, direction, socket_put_messages, soc
|
||||
b"MG _MOB\r",
|
||||
b"MG axisref[1]\r",
|
||||
],
|
||||
[b":", b":", b":", b"0", b"0", b"-1", b"-1", b"1.00"],
|
||||
[b":", b":", b"-1", b":", b"0", b"0", b"-1", b"-1", b"1.00"],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user