fix(npoint): retry on wait_for_connection
This commit was merged in pull request #204.
This commit is contained in:
@@ -448,26 +448,14 @@ class NPointAxis(Device, PositionerBase):
|
||||
self.high_limit_travel.put(limits[1])
|
||||
|
||||
def wait_for_connection(self, timeout: float = 30.0) -> bool:
|
||||
self.controller.on(timeout=timeout)
|
||||
self._update_setpoint_from_readback()
|
||||
|
||||
def _update_setpoint_from_readback(self):
|
||||
"""
|
||||
The setpoint is only stored locally. After a restart,
|
||||
we need to update it to match the current readback value.
|
||||
"""
|
||||
for attempt in range(5):
|
||||
for _ in range(5):
|
||||
try:
|
||||
self.user_setpoint.setpoint = self.readback.get()
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"NPointAxis {self.name}: Failed to update the setpoint from the readback value on attempt {attempt+1} during startup: {e}"
|
||||
)
|
||||
self.controller.on(timeout=timeout)
|
||||
self._update_setpoint_from_readback()
|
||||
except TimeoutError:
|
||||
self.controller.off(update_config=False)
|
||||
time.sleep(1)
|
||||
else:
|
||||
logger.info(
|
||||
f"NPointAxis {self.name}: Successfully updated the setpoint from the readback value on attempt {attempt+1} during startup."
|
||||
)
|
||||
break
|
||||
else:
|
||||
raise TimeoutError(
|
||||
@@ -475,6 +463,13 @@ class NPointAxis(Device, PositionerBase):
|
||||
f"Try to reload the config and if the problem persists, check the connection to the nPoint controller "
|
||||
f"and ensure that it is powered on and accessible at {self.controller._socket_host}:{self.controller._socket_port}."
|
||||
)
|
||||
|
||||
def _update_setpoint_from_readback(self):
|
||||
"""
|
||||
The setpoint is only stored locally. After a restart,
|
||||
we need to update it to match the current readback value.
|
||||
"""
|
||||
self.user_setpoint.setpoint = self.readback.get()
|
||||
|
||||
def destroy(self):
|
||||
"""Make sure to turn off the controller socket on destroy."""
|
||||
|
||||
Reference in New Issue
Block a user