Explorar el Código

writing to closed port. starting to fix terminal

kmpm hace 8 años
padre
commit
87b5e94aac
Se han modificado 2 ficheros con 18 adiciones y 10 borrados
  1. 12 7
      lib/term.py
  2. 6 3
      lib/uploader.py

+ 12 - 7
lib/term.py

@@ -3,12 +3,17 @@
 
 from .utils import default_port
 try:
-    from serial.tools.miniterm import Miniterm, console, NEWLINE_CONVERISON_MAP
+    from serial.tools.miniterm import Miniterm, NEWLINE_CONVERISON_MAP
     import serial
     MINITERM_AVAILABLE=True
 except ImportError:
-
     MINITERM_AVAILABLE=False
+    
+try:
+    from serial.tools.miniterm import console
+    CONSOLE_AVAILABLE=True
+except ImportError:
+    CONSOLE_AVAILABLE=False
 
 
 class McuMiniterm(Miniterm):
@@ -31,7 +36,7 @@ def terminal(port=default_port()):
         print "Miniterm is not available on this system"
         return False
     sp = serial.Serial(port, 9600)
-
+    
     # Keeps things working, if following conections are made:
     ## RTS = CH_PD (i.e reset)
     ## DTR = GPIO0
@@ -40,12 +45,12 @@ def terminal(port=default_port()):
     miniterm = McuMiniterm(sp)
 
     log.info('Started terminal. Hit ctrl-] to leave terminal')
-
-    console.setup()
+    if CONSOLE_AVAILABLE:
+        console.setup()
     miniterm.start()
     try:
-            miniterm.join(True)
+        miniterm.join(True)
     except KeyboardInterrupt:
-            pass
+        pass
     miniterm.join()
     sp.close()

+ 6 - 3
lib/uploader.py

@@ -120,9 +120,12 @@ class Uploader(object):
 
     def close(self):
         """restores the nodemcu to default baudrate and then closes the port"""
-        self.writeln(UART_SETUP.format(baud=Uploader.BAUD))
-        self._port.flush()
-        self.clear_buffers()
+        try:
+            self.writeln(UART_SETUP.format(baud=Uploader.BAUD))
+            self._port.flush()
+            self.clear_buffers()
+        except serial.serialutil.SerialException:
+            pass
         log.debug('closing port')
         self._port.close()