add try catch while reading timeout on the serial port

This commit is contained in:
2022-03-07 22:05:10 +01:00
parent 184e708caf
commit 334855b4db
+9 -5
View File
@@ -91,12 +91,16 @@ class ModemPool:
def _send_command(self, cmd: str, ser, wait_time_in_s: int = 0) -> bytes: def _send_command(self, cmd: str, ser, wait_time_in_s: int = 0) -> bytes:
ser.write(cmd.encode()) ser.write(cmd.encode())
msg = ser.read(100) msg = None
count = 0 try:
while 'OK' not in str(msg) and count < wait_time_in_s:
time.sleep(1)
count = count + 1
msg = ser.read(100) 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) # msg = ser.read(100)
print(msg) print(msg)
return msg return msg