From 0735a5982f1684cf648797ebf6a39b2f20c617bc Mon Sep 17 00:00:00 2001 From: Bryce Bixler Date: Mon, 20 Nov 2023 22:49:57 +0000 Subject: [PATCH] Fixes to pre-commit failures --- socs/agents/hwp_pid/drivers/pid_controller.py | 7 +++---- socs/agents/hwp_pmx/drivers/PMX_ethernet.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/socs/agents/hwp_pid/drivers/pid_controller.py b/socs/agents/hwp_pid/drivers/pid_controller.py index cd3ac6361..60d7c874a 100644 --- a/socs/agents/hwp_pid/drivers/pid_controller.py +++ b/socs/agents/hwp_pid/drivers/pid_controller.py @@ -32,7 +32,7 @@ def __init__(self, ip, port, verb=False): self.set_direction('0') @staticmethod - def _establish_connection(ip, port, timeout=5): + def _establish_connection(ip, port, timeout=2): """Connect to PID controller. Args: @@ -54,9 +54,8 @@ def _establish_connection(ip, port, timeout=5): try: conn.connect((ip, port)) break - except (ConnectionRefusedError, OSError) as e: + except (ConnectionRefusedError, OSError): print(f"Failed to connect to device at {ip}:{port}") - time.sleep(5) else: raise RuntimeError('Could not connect to PID controller') return conn @@ -267,7 +266,7 @@ def send_message(self, msg): time.sleep(0.5) # Don't send messages too quickly data = self.conn.recv(4096).decode().strip() return data - except (socket.timeout, OSError) as e: + except (socket.timeout, OSError): print("Caught timeout waiting for response from PID controller. " + "Trying again...") time.sleep(1) diff --git a/socs/agents/hwp_pmx/drivers/PMX_ethernet.py b/socs/agents/hwp_pmx/drivers/PMX_ethernet.py index 62925293a..e4df3c523 100644 --- a/socs/agents/hwp_pmx/drivers/PMX_ethernet.py +++ b/socs/agents/hwp_pmx/drivers/PMX_ethernet.py @@ -27,7 +27,7 @@ def __init__(self, ip, port): self.buffer_size = 128 self.conn = self._establish_connection(self.ip, int(self.port)) - def _establish_connection(self, ip, port, timeout=5): + def _establish_connection(self, ip, port, timeout=2): conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.settimeout(timeout) attempts = 3 @@ -35,9 +35,8 @@ def _establish_connection(self, ip, port, timeout=5): try: conn.connect((ip, port)) break - except (ConnectionRefusedError, OSError) as e: + except (ConnectionRefusedError, OSError): print(f"Failed to connect to device at {ip}:{port}") - time.sleep(5) else: raise RuntimeError('Could not connect to PID controller') return conn @@ -54,7 +53,7 @@ def send_message(self, msg, read=True): data = self.conn.recv(self.buffer_size).decode('utf-8') return data return - except (socket.timeout, OSError) as e: + except (socket.timeout, OSError): print("Caught timeout waiting for responce from PMX. Trying again...") time.sleep(1) if attempt == 1: