mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2026-02-04 22:28:41 +01:00
fix(controller): cleanup and fix logic for enable/off dependency.
This commit is contained in:
@@ -200,7 +200,7 @@ class Controller(OphydObject):
|
||||
if axis is not None
|
||||
)
|
||||
if all_disabled:
|
||||
self.off()
|
||||
self.off(update_config=False)
|
||||
|
||||
def set_all_devices_enable(self, enabled: bool) -> None:
|
||||
"""
|
||||
@@ -281,14 +281,15 @@ class Controller(OphydObject):
|
||||
else:
|
||||
logger.info("The connection has already been established.")
|
||||
|
||||
def off(self) -> None:
|
||||
def off(self, update_config: bool = True) -> None:
|
||||
"""Close the socket connection to the controller"""
|
||||
if self.connected and self.sock is not None:
|
||||
self.sock.close()
|
||||
self.connected = False
|
||||
self.sock = None
|
||||
# Disable all axes associated with this controller
|
||||
self.set_all_devices_enable(False)
|
||||
if update_config:
|
||||
# Disable all axes associated with this controller
|
||||
self.set_all_devices_enable(False)
|
||||
else:
|
||||
logger.info("The connection is already closed.")
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ class SocketIO:
|
||||
Args:
|
||||
timeout (int): Time in seconds to wait for connection
|
||||
"""
|
||||
logger.info(f"Connecting to {self.host}:{self.port}")
|
||||
logger.info(f"Connecting to {self.host}:{self.port}.")
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < timeout:
|
||||
try:
|
||||
@@ -197,11 +197,14 @@ class SocketIO:
|
||||
break
|
||||
except Exception as exc:
|
||||
self.sock = None
|
||||
logger.warning(f"Connection failed, retrying after 0.2 seconds... {exc}")
|
||||
logger.warning(
|
||||
f"Connection to {self.host}:{self.port} failed after {time.time()-start_time:.2f} seconds"
|
||||
f" with exception: {exc}. Retrying after 1 second..."
|
||||
)
|
||||
time.sleep(1)
|
||||
else:
|
||||
raise ConnectionError(
|
||||
f"Could not connect to {self.host}:{self.port} within {time.time()-start_time} seconds"
|
||||
f"Could not connect to {self.host}:{self.port} within {time.time()-start_time:.2f} seconds"
|
||||
)
|
||||
|
||||
def _put(self, msg_bytes):
|
||||
@@ -224,7 +227,7 @@ class SocketIO:
|
||||
return self._recv(buffer_length=buffer_length)
|
||||
|
||||
def open(self, timeout: int = 10):
|
||||
""" "
|
||||
"""
|
||||
Open the socket connection to the host:port
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user