Close serial terminal when uploading in VS Code


It would be awesome if the serial terminal were automatically closed when uploading a build. Currently my process looks something like:

  • watch some output on the serial monitor
  • make code changes
  • build
  • upload
  • upload fails, so I remember I left the serial monitor open
  • hunt for the serial monitor window to close it
  • re-upload

:slight_smile: It would be awesome if the middle steps could be skipped.


If you open serial monitor via Serial Monitor button on the bottom toolbar, PIO IDE should close it automatically.
Nevertheless, we depend on VSCode API from Microsoft


This doesn’t seem to work for me – I still have to manually close the serial monitor in VS Code when I upload new code.


If you use buttons on PIO Toolbar, all should work. I’ve just pressed “monitor” button, then “upload” and VSCode asked me to terminate existing task. This is a temporary workaround while VSCode does not have proper API to terminate particular task.


Hi all,
New to this tool. I too am struggling with what I surmise to be a monitor serial connection blocking uploads to the device.

error: Failed to open COM7
error: espcomm_open failed
error: espcomm_upload_mem failed
*** [upload] Error 2

The behaviour is very unpredictable and slowing me down quite a bit! My process is write a bit of code. Build (tick icon). Upload (arrow icon). Monitor (plug icon). But if I repeat this, I get the error above… Sometimes… 1 out of 4 times it succeeds. Success through repeated clicking; not changing anything. Is there a secret process running inside VS Code that rolls a dice and perhaps another few processes laughing at me?

I waited a couple of hours before posting this. But it still persists. And I now also have the following error, which fails every time:

espcomm_sync failed

Any chance this is a known error, and a solution is possible. Would love to continue working in this environment all the way to production, but I’m currently feeling very anxious!


  • Made sure no tasks running by checking the little spanner&screwdriver icon.
  • Slowed the baud down to 9600.
  • Checked with a different cable.
  • Checked with a different USB port (windows actually still set it as COM7)
  • Opened port OK in teraTerm just to check it wasn’t in use. It wasn’t!
  • My design puts the ESP8266 into Deep Sleep. Interestingly, I was getting intermittent failures when I was sleeping for 5 or 10 seconds. Now I’ve upped that to 60 seconds, I can’t seem to get it to work hardly at all. Can anyone confirm whether the device being in deep sleep has anything to do with this?


Anyone, anyone??? …


We can’t closed an opened port from another application. Could you close all tools that use serial ports and start uploading? Does it work now?


I was careful to close the Teraterm port after using it. I only opened it to test whether there was another unknown application holding it, which there was not. I could connect over teraterm fine. Then closed it. And back to not connecting.