From 0bc18d93c6863bd2fc1aa5b8e5603f9168f97479 Mon Sep 17 00:00:00 2001 From: Alexandre Bard Date: Thu, 13 Dec 2018 15:40:39 +0100 Subject: [PATCH] ublox-config: Improve python script performances and reliability --- .../ublox-configuration/files/ublox-config.py | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/recipes-connectivity/ublox-configuration/files/ublox-config.py b/recipes-connectivity/ublox-configuration/files/ublox-config.py index 3400791..16598c3 100755 --- a/recipes-connectivity/ublox-configuration/files/ublox-config.py +++ b/recipes-connectivity/ublox-configuration/files/ublox-config.py @@ -6,26 +6,32 @@ import time MAX_TRY = 5 tries = 0 -ser = serial.Serial('/dev/ttyACM0', 115200, timeout=2) +ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0.5) def execute_and_check(cmd): - ser.write(cmd) - s = ser.read(200) - if b"OK" not in s: - print("Failed cmd : " + str(cmd)) - print(s) - if ++tries < MAX_TRY: - time.sleep(1) - execute_and_check(cmd) - else: - sys.exit(-1) + global tries + ser.flushInput() + ser.write(cmd) + ser.write(b'\r') + s = ser.read_until(b'OK') + if b'OK' not in s: + print("Failed cmd : " + str(cmd)) + print("Output: " + str(s)) + tries += 1 + if tries < MAX_TRY: + time.sleep(1) + execute_and_check(cmd) + else: + sys.exit(-1) + tries = 0 + print("Setting up bridge mode") -execute_and_check(b'AT+UBMCONF=2\r') +execute_and_check(b'AT+UBMCONF=2') print("Setting up USB mode to ECM") -execute_and_check(b'AT+UUSBCONF=2,"ECM",0\r') +execute_and_check(b'AT+UUSBCONF=2,"ECM",0') print("Resetting modem")