Description
Describe the bug
The Arduino IDE uses the serial ports of Arduino boards in two different ways:
- Uploading sketches
- Communication via Serial Monitor
The port can not be used for both of these things simultaneously. The IDE handles the condition of Serial Monitor being open when an upload is started automagically like so:
- Close port in Serial Monitor
- Complete upload process
- Reopen port in Serial Monitor
🐛 This works as expected in the first IDE window you open, but it no longer works in subsequent windows.
NOTE: although similar, this is different from #586 because it occurs even when the port is not open in a Serial Monitor/Serial Plotter of another IDE window.
To Reproduce
- Connect an Arduino board to your computer.
- Select the appropriate board and port.
- Select Tools > Serial Monitor from the Arduino IDE menus to open Serial Monitor.
- Select Sketch > Upload from the Arduino IDE menus.
🙂 Upload succeeds as expected. - Select Tools > Serial Monitor from the Arduino IDE menus to close Serial Monitor.
This is necessary to avoid Upload fails if port is open in Serial Monitor of another window #586 - Select File > New from the Arduino IDE menus.
- Select Tools > Serial Monitor from the Arduino IDE menus in the new window.
🐛 Note that there is an unexpected banner in Serial Monitor:Not connected. Select a board and a port to connect automatically.
- Select Sketch > Upload from the Arduino IDE menus.
🐛 Upload fails with an error something like "avrdude: ser_open(): can't open device "\.\COM7": Access is denied."
Expected behavior
Upload with Serial Monitor open in the same IDE window to always be handled automagically.
Desktop
- OS: Windows 10
- Version: 2.0.0-rc3
Date: 2021-12-22T15:46:56.004Z
CLI Version: 0.20.2 [13783819]
Additional context
It is not necessary to leave the original window open to reproduce the bug. It occurs even if that window is closed.
I bisected the issue to 767b09d (it does not occur at 8839793).
Originally reported at https://forum.arduino.cc/t/upload-failed-when-serial-monitor-is-open/940255