From c7769ce50284c1da910da23663a27555b90abc18 Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Fri, 6 May 2022 16:26:00 +0200 Subject: [PATCH] pyluos-bootloader reset send a reset message even if detection fail. fix #138 --- pyluos/tools/bootloader.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/pyluos/tools/bootloader.py b/pyluos/tools/bootloader.py index fed4790..5c57932 100644 --- a/pyluos/tools/bootloader.py +++ b/pyluos/tools/bootloader.py @@ -15,6 +15,9 @@ import math import crc8 import os +from ..io.serial_io import Serial +import serial +import struct # ******************************************************************************* # Global Variables @@ -570,17 +573,35 @@ def luos_detect(args): # @return None # ******************************************************************************* def luos_reset(args): - print('Luos detect subcommand on port : ', args.port) + print('Luos discover subcommand on port : ', args.port) if not (args.port): - args.port= serial_discover()[0] + try: + args.port= serial_discover()[0] + except: + sys.exit("Can't find any Gate interface") + return + + + # send rescue command + print('Send reset command.') + port = serial.Serial(args.port, 1000000, timeout=0.05) + rst_cmd = { + 'bootloader': { + 'command': { + 'type': BOOTLOADER_RESET, + 'node': 0, + 'size': 0 + }, + } + } + s = json.dumps(rst_cmd).encode() + port.write(b'\x7E' + struct.pack('