Fix and refactor disconnect
This commit is contained in:
parent
b3230814a8
commit
a1fa53456e
36
stcgal.py
36
stcgal.py
@ -1585,21 +1585,7 @@ class StcGal:
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise NameError("invalid option '%s' (%s)" % (kv[0], e))
|
raise NameError("invalid option '%s' (%s)" % (kv[0], e))
|
||||||
|
|
||||||
def run(self):
|
def program_mcu(self):
|
||||||
try: self.protocol.connect()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("interrupted")
|
|
||||||
return 2
|
|
||||||
except RuntimeError as e:
|
|
||||||
print("Communication error: %s" % e, file=sys.stderr)
|
|
||||||
self.protocol.disconnect()
|
|
||||||
return 1
|
|
||||||
except serial.serialutil.SerialException as e:
|
|
||||||
print("Serial communication error: %s" % e, file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if opts.code_binary:
|
|
||||||
try:
|
|
||||||
code_size = self.protocol.model.code
|
code_size = self.protocol.model.code
|
||||||
ee_size = self.protocol.model.eeprom
|
ee_size = self.protocol.model.eeprom
|
||||||
|
|
||||||
@ -1636,6 +1622,26 @@ class StcGal:
|
|||||||
self.protocol.program_flash(bindata)
|
self.protocol.program_flash(bindata)
|
||||||
self.protocol.program_options()
|
self.protocol.program_options()
|
||||||
self.protocol.disconnect()
|
self.protocol.disconnect()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
try: self.protocol.connect()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("interrupted")
|
||||||
|
return 2
|
||||||
|
except RuntimeError as e:
|
||||||
|
print("Communication error: %s" % e, file=sys.stderr)
|
||||||
|
self.protocol.disconnect()
|
||||||
|
return 1
|
||||||
|
except serial.serialutil.SerialException as e:
|
||||||
|
print("Serial communication error: %s" % e, file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
try:
|
||||||
|
if opts.code_binary:
|
||||||
|
self.program_mcu()
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
self.protocol.disconnect()
|
||||||
return 0
|
return 0
|
||||||
except NameError as e:
|
except NameError as e:
|
||||||
print("Option error: %s" % e, file=sys.stderr)
|
print("Option error: %s" % e, file=sys.stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user