From 0b562b8212eb6cde49de20786fc205d00b0d82cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Sowi=C5=84ski?= Date: Thu, 20 May 2021 13:29:36 +0200 Subject: [PATCH] Updated for Python3 and added retry for sync operation --- nxpprog.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/nxpprog.py b/nxpprog.py index 60d3624..19e0325 100755 --- a/nxpprog.py +++ b/nxpprog.py @@ -447,7 +447,7 @@ def __init__(self, device, baud, xonxoff=False, control=False): # or the device is in the wrong mode. # This timeout is too short for slow baud rates but who wants to # use them? - self._serial.setTimeout(5) + self._serial.timeout = 1 # device wants Xon Xoff flow control if xonxoff: self._serial.setXonXoff(1) @@ -491,8 +491,8 @@ def write(self, data): def readline(self, timeout=None): if timeout: - ot = self._serial.getTimeout() - self._serial.setTimeout(timeout) + ot = self._serial.timeout + self._serial.timeout = timeout line = b'' while True: @@ -512,7 +512,7 @@ def readline(self, timeout=None): line += c if timeout: - self._serial.setTimeout(ot) + self._serial.timeout = ot return line.decode("UTF-8", "ignore") @@ -685,8 +685,11 @@ def isp_command(self, cmd): def sync(self, osc): - self.dev_write(b'?') - s = self.dev_readline() + for _ in range(10): + self.dev_write(b'?') + s = self.dev_readline() + if s: + break if not s: panic("Sync timeout") if s != self.sync_str: @@ -1256,7 +1259,7 @@ def main(argv=None): else: panic("Unhandled option: %s" % o) - if cpu != "autodetect" and not cpu_parms.has_key(cpu): + if cpu != "autodetect" and not cpu in cpu_parms: panic("Unsupported cpu %s" % cpu) if len(args) == 0: