From 334855b4db651846b0606933b26859728f3749ac Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Mon, 7 Mar 2022 22:05:10 +0100 Subject: [PATCH] add try catch while reading timeout on the serial port --- ModemPool.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ModemPool.py b/ModemPool.py index 7e7ae22..7122d4e 100644 --- a/ModemPool.py +++ b/ModemPool.py @@ -91,12 +91,16 @@ class ModemPool: def _send_command(self, cmd: str, ser, wait_time_in_s: int = 0) -> bytes: ser.write(cmd.encode()) - msg = ser.read(100) - count = 0 - while 'OK' not in str(msg) and count < wait_time_in_s: - time.sleep(1) - count = count + 1 + msg = None + try: msg = ser.read(100) + count = 0 + while 'OK' not in str(msg) and count < wait_time_in_s: + time.sleep(1) + count = count + 1 + msg = ser.read(100) + except Exception as exc: + print(exc) # msg = ser.read(100) print(msg) return msg