mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add serial disconnect function.
This commit is contained in:
parent
3f0340d103
commit
03eb277aa9
@ -115,6 +115,7 @@ class Bootloader:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def task_connect(self, state):
|
def task_connect(self, state):
|
||||||
|
openmv.disconnect()
|
||||||
try:
|
try:
|
||||||
# Attempt to connect to bootloader
|
# Attempt to connect to bootloader
|
||||||
openmv.init(self.port, self.baud, timeout=0.050)
|
openmv.init(self.port, self.baud, timeout=0.050)
|
||||||
@ -123,12 +124,11 @@ class Bootloader:
|
|||||||
state["bar"].set_text("Erasing...")
|
state["bar"].set_text("Erasing...")
|
||||||
self.cancel_button.set_sensitive(False)
|
self.cancel_button.set_sensitive(False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
openmv.disconnect()
|
||||||
if self.flash_msg:
|
if self.flash_msg:
|
||||||
state["bar"].set_text("Connecting to bootloader...\
|
state["bar"].set_text("Connecting to bootloader...\n ")
|
||||||
\n ")
|
|
||||||
else:
|
else:
|
||||||
state["bar"].set_text("Connecting to bootloader...\
|
state["bar"].set_text("Connecting to bootloader...\nDisconnect and re-connect cam!")
|
||||||
\nDisconnect and re-connect cam!")
|
|
||||||
self.flash_msg = self.flash_msg ^ 1
|
self.flash_msg = self.flash_msg ^ 1
|
||||||
sleep(0.100)
|
sleep(0.100)
|
||||||
|
|
||||||
@ -152,7 +152,6 @@ class Bootloader:
|
|||||||
|
|
||||||
# Send chunk
|
# Send chunk
|
||||||
chunk = min (60, xfer_total-xfer_bytes)
|
chunk = min (60, xfer_total-xfer_bytes)
|
||||||
#openmv.flash_write(buf[xfer_bytes:xfer_bytes+chunk], xfer_bytes)
|
|
||||||
openmv.flash_write(buf[xfer_bytes : xfer_bytes+chunk])
|
openmv.flash_write(buf[xfer_bytes : xfer_bytes+chunk])
|
||||||
|
|
||||||
xfer_bytes += chunk
|
xfer_bytes += chunk
|
||||||
|
|||||||
@ -50,6 +50,13 @@ def init(port, baudrate=921600, timeout=0.3):
|
|||||||
# open CDC port
|
# open CDC port
|
||||||
__serial = serial.Serial(port, baudrate=baudrate, timeout=timeout)
|
__serial = serial.Serial(port, baudrate=baudrate, timeout=timeout)
|
||||||
|
|
||||||
|
def disconnect():
|
||||||
|
try:
|
||||||
|
if (__serial):
|
||||||
|
__serial.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def set_timeout(timeout):
|
def set_timeout(timeout):
|
||||||
__serial.timeout = timeout
|
__serial.timeout = timeout
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user