[Patch] Disable serial monitor while uploading

61 views
Skip to first unread message

avishorp

unread,
Feb 23, 2014, 6:09:35 PM2/23/14
to devel...@arduino.cc
Currently, the serial monitor window closes when starting program uploading. I find this behavior very annoying since the monitor window has to be opened over and over again after each upload. The attached patch fixes this issue. When upload starts, the window gets disabled. When the upload process ends the window gets re-enabled and become operational immediately (if it is visible). The user can also now open the serial monitor window while uploading is in progress.

Avishay.


From 6e87fe274fcf225a541970ac01f767ad5259ee28 Mon Sep 17 00:00:00 2001
From: Avishay Orpaz <avis...@gmail.com>
Date: Mon, 24 Feb 2014 01:06:12 +0200
Subject: [PATCH] Allow the serial monitor to stay opened during upload,
 disabling it

---
 app/src/processing/app/Editor.java        |   18 ++++++----
 app/src/processing/app/SerialMonitor.java |   51 ++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java
index 61051f9..7d74af5 100644
--- a/app/src/processing/app/Editor.java
+++ b/app/src/processing/app/Editor.java
@@ -2374,8 +2374,7 @@ public class Editor extends JFrame implements RunnerListener {
     public void run() {
 
       try {
-        serialMonitor.closeSerialPort();
-        serialMonitor.setVisible(false);
+        serialMonitor.suspend();
            
         uploading = true;
          
@@ -2402,6 +2401,14 @@ public class Editor extends JFrame implements RunnerListener {
       uploading = false;
       //toolbar.clear();
       toolbar.deactivate(EditorToolbar.EXPORT);
+     
+      // Return the serial monitor window to its initial state
+      try {
+          serialMonitor.resume();
+      }
+      catch (SerialException e) {
+          statusError(e);
+      }
     }
   }
 
@@ -2476,12 +2483,9 @@ public class Editor extends JFrame implements RunnerListener {
   }
 
 
-  public void handleSerial() {
-    if (uploading) return;
-   
+  public void handleSerial() { 
     try {
-      serialMonitor.openSerialPort();
-      serialMonitor.setVisible(true);
+      serialMonitor.openSerialMonitor();
     } catch (SerialException e) {
       statusError(e);
     }
diff --git a/app/src/processing/app/SerialMonitor.java b/app/src/processing/app/SerialMonitor.java
index 1f34e8f..dff4f5b 100644
--- a/app/src/processing/app/SerialMonitor.java
+++ b/app/src/processing/app/SerialMonitor.java
@@ -40,10 +40,11 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
   private JComboBox lineEndings;
   private JComboBox serialRates;
   private int serialRate;
+  private boolean serialMonitorEnabled;

 
   public SerialMonitor(String port) {
     super(port);

     this.port = port;
  
     addWindowListener(new WindowAdapter() {
@@ -171,6 +172,8 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
         }
       }
     }
+   
+    serialMonitorEnabled = true;
   }
  
   protected void setPlacement(int[] location) {
@@ -228,4 +231,50 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
         }
       }});
   }

+  public void enableWindow(boolean enable)
+  {
+      textArea.setEnabled(enable);
+      scrollPane.setEnabled(enable);
+      textField.setEnabled(enable);
+      sendButton.setEnabled(enable);
+      autoscrollBox.setEnabled(enable);
+      lineEndings.setEnabled(enable);
+      serialRates.setEnabled(enable);
+     
+      serialMonitorEnabled = enable;
+  }

+  // Make the serial monitor window operational
+  public void openSerialMonitor() throws SerialException
+  {
+      // If the serial monitor is not currently disabled, open
+      // the serial port
+      if (serialMonitorEnabled)
+          openSerialPort();
+     
+      // Make the window visible
+      setVisible(true);
+  }
+
+  // Puts the window in suspend state, closing the serial port
+  // to allow other entity (the programmer) to use it
+  public void suspend()
+  {
+      if (serial != null)
+          // Serial is opened. Record this fact and close it
+          closeSerialPort();
+     
+      enableWindow(false);     
+  }

+  public void resume() throws SerialException
+  {
+      // Enable the window
+      enableWindow(true);         
+
+      // If the window is visible, try to open the serial port
+      if (isVisible())
+            openSerialPort();
+  }
 }
--
1.7.9.5

Knight, Dave

unread,
Feb 23, 2014, 6:24:53 PM2/23/14
to avishorp, Arduino Developers
FWIW, I find that to be a convenience when I use the serial monitor.

I am more frustrated by the serial monitor's limitations, hence I use a serial terminal emulator (e.g. minicom), which allows me to capture a complete log file, and supports terminal control chars, etc.

 --

"Why doesn't onomatopoeia sound like what it is, when the word onomatopoeia is spelled just the way it sounds?"

                                                                       A. Conan Drumm




--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.

Paul Stoffregen

unread,
Feb 23, 2014, 8:01:27 PM2/23/14
to devel...@arduino.cc
On 02/23/2014 03:09 PM, avishorp wrote:
Currently, the serial monitor window closes when starting program uploading. I find this behavior very annoying since the monitor window has to be opened over and over again after each upload. The attached patch fixes this issue. When upload starts, the window gets disabled. When the upload process ends the window gets re-enabled and become operational immediately (if it is visible). The user can also now open the serial monitor window while uploading is in progress.

Have you tested this with Arduino Leonardo or Arduino Due's native port?


Mark Jones

unread,
Feb 23, 2014, 9:39:20 PM2/23/14
to avishorp, devel...@arduino.cc

I think this is a great idea.  I have also found having to reopen it each time to be a hassle.

--

Matthijs Kooijman

unread,
Feb 24, 2014, 1:30:47 AM2/24/14
to avishorp, devel...@arduino.cc
Hi Avishay,

> Currently, the serial monitor window closes when starting program
> uploading. I find this behavior very annoying since the monitor window has
> to be opened over and over again after each upload. The attached patch
> fixes this issue. When upload starts, the window gets disabled. When the
> upload process ends the window gets re-enabled and become operational
> immediately (if it is visible). The user can also now open the serial
> monitor window while uploading is in progress.
The patch looks good to me at first glance. Perhaps you should submit it
as a pullrequest on github?

Also note https://github.com/arduino/Arduino/pull/1613, which fixes the
same problem in different way (by re-opening the monitor every time).

Gr.

Matthijs
signature.asc

Matthijs Kooijman

unread,
Feb 24, 2014, 1:32:05 AM2/24/14
to Knight, Dave, avishorp, Arduino Developers
Hey Dave,

> FWIW, I find that to be a convenience when I use the serial monitor.
>
> I am more frustrated by the serial monitor's limitations, hence I use a
> serial terminal emulator (e.g. minicom), which allows me to capture a
> complete log file, and supports terminal control chars, etc.
Huh? You're saying you do not like to use the serial monitor and thus
find it a feature that it automatically closes? That doesn't really
sound like something we should keep into account - if you don't like it,
then just don't use it at all? Or am I misunderstanding?

Gr.

Matthijs
signature.asc
Reply all
Reply to author
Forward
0 new messages