Sun, 26 Feb 2023 18:04:56 +0100
Changed code to clean the serial port buffers before switching to 'paste' mode and sanitize the received output of that mode.
src/eric7/MicroPython/MicroPythonDeviceInterface.py | file | annotate | diff | comparison | revisions |
--- a/src/eric7/MicroPython/MicroPythonDeviceInterface.py Sun Feb 26 18:03:50 2023 +0100 +++ b/src/eric7/MicroPython/MicroPythonDeviceInterface.py Sun Feb 26 18:04:56 2023 +0100 @@ -123,6 +123,8 @@ return False pasteMessage = b"paste mode; Ctrl-C to cancel, Ctrl-D to finish\r\n=== " + + self.__serial.clear() # clear any buffered output before entering paste mode self.__serial.write(b"\x02") # end raw mode if required written = self.__serial.waitForBytesWritten(500) # time out after 500ms if device is not responding @@ -371,12 +373,12 @@ if isinstance(commands, list): commands = "\n".join(commands) - # switch on raw mode + # switch on paste mode self.__blockReadyRead = True ok = self.__pasteOn() if not ok: self.__blockReadyRead = False - return (b"", b"Could not switch to raw mode. Is the device switched on?") + return (b"", b"Could not switch to paste mode. Is the device switched on?") # send commands QThread.msleep(10) @@ -401,17 +403,21 @@ # switch off paste mode causing the commands to be executed self.__pasteOff() QThread.msleep(10) - result = self.__serial.readUntil(b">>> ", timeout=timeout).replace(b">>> ", b"") # read until Python prompt + result = self.__serial.readUntil(b">>> ", timeout=timeout).replace(b">>> ", b"").strip() if self.__serial.hasTimedOut(): self.__blockReadyRead = False return b"", b"Timeout while processing commands." + # get rid of any OSD string + if result.startswith(b"\x1b]0;"): + result = result.split(b"\x1b\\")[-1] + if self.TracebackMarker in result: errorIndex = result.find(self.TracebackMarker) out, err = result[:errorIndex], result[errorIndex:] else: - out = result.strip() + out = result err = b"" self.__blockReadyRead = False