]> granicus.if.org Git - esp-idf/commitdiff
idf_monitor: Fix issues using Ctrl-F/Ctrl-A/gdb with older pyserial
authorAngus Gratton <angus@espressif.com>
Tue, 21 Mar 2017 08:08:06 +0000 (16:08 +0800)
committerAngus Gratton <angus@espressif.com>
Tue, 21 Mar 2017 08:08:06 +0000 (16:08 +0800)
Previously error was "AttributeError: 'Console' object has no attribute 'cancel'"

tools/idf_monitor.py

index a8ddf77e7962acce9b643a71e34a4cbf3da9a54c..824a2f8e1bb235008dab7b315471d89ea0f0af6d 100644 (file)
@@ -148,7 +148,15 @@ class ConsoleReader(StoppableThread):
             self.console.cleanup()
 
     def _cancel(self):
-        self.console.cancel()
+        if hasattr(self.console, "cancel"):
+            self.console.cancel()
+        elif os.name == 'posix':
+            # this is the way cancel() is implemented in pyserial 3.1 or newer,
+            # older pyserial doesn't have this method, hence this hack.
+            #
+            # on Windows there is a different (also hacky) fix, applied above.
+            import fcntl, termios
+            fcntl.ioctl(self.console.fd, termios.TIOCSTI, b'\0')
 
 class SerialReader(StoppableThread):
     """ Read serial data from the serial port and push to the