Skip to content
Snippets Groups Projects
Commit 4e43cc35 authored by Julian Oes's avatar Julian Oes Committed by Daniel Agar
Browse files

px_uploader.py fix flashing issue (#9792)

This fixes a problem where the pyserial write call gets stuck.
It happens on a specific Fedora 28 system with internal USB ports as
well as USB hubs.
It is not clear why the problem is resolved but it is clearly
reproducible that with a timeout of 0, the write can get stuck and with
a timeout > 0 it works every time.

The exception added as part of this commit makes sense but has never
been triggered in my testing.
parent 96f47d47
Branches
Tags
No related merge requests found
......@@ -191,8 +191,11 @@ class uploader(object):
MAVLINK_REBOOT_ID0 = bytearray(b'\xfe\x21\x45\xff\x00\x4c\x00\x00\x40\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\x00\x00\x00\x00\xcc\x37')
def __init__(self, portname, baudrate_bootloader, baudrate_flightstack):
# open the port, keep the default timeout short so we can poll quickly
self.port = serial.Serial(portname, baudrate_bootloader, timeout=0.5)
# Open the port, keep the default timeout short so we can poll quickly.
# On some systems writes can suddenly get stuck without having a
# write_timeout > 0 set.
self.port = serial.Serial(portname, baudrate_bootloader, timeout=0.5, write_timeout=0.5)
# self.port.write_timeout = 0.5
self.otp = b''
self.sn = b''
self.baudrate_bootloader = baudrate_bootloader
......@@ -230,7 +233,14 @@ class uploader(object):
def __send(self, c):
# print("send " + binascii.hexlify(c))
while True:
try:
self.port.write(c)
break
except serial.SerialTimeoutException as e:
print("Write timeout (%s), trying again" % e)
time.sleep(0.04)
continue
def __recv(self, count=1):
c = self.port.read(count)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment