add try catch while reading timeout on the serial port
This commit is contained in:
+9
-5
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user