Description
Describe the problem
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
🐛 It does not currently handle the reverse, where the Serial Monitor is opened while an upload is in progress. This results in a confusing upload failure.
To reproduce
- Close Serial Monitor if it is already open.
- Start an upload to an Arduino board.
NOTE: because it is timing sensitive, the issue will be difficult to reproduce with a minimal sketch that compiles very quickly, especially on a subsequent compilation when the libraries have already been cached. Use a larger sketch to accurately simulate real world conditions. - While the compilation process that occurs before the actual upload starts is still in progress, select Tools > Serial Monitor from the Arduino IDE windows.
The board's port is now opened in Serial Monitor. - Wait for the upload process to finish.
🐛 Note that the upload has failed with an error something like:avrdude: ser_open(): can't open device "\\.\COM7": Access is denied.
Expected behavior
Don't allow user to break upload by opening Serial Monitor.
Arduino IDE 1.x allows Serial Monitor to be opened during upload, but it is in a disabled state where the opening of the port is deferred until after the upload finishes, behaving just the same as when an upload is started with Serial Monitor already open:
Arduino IDE version
2.0.0-beta.12-nightly.20211028
Operating system
Windows
Operating system version
10
Additional context
Originally reported at #271 (comment)
Issue checklist
- I searched for previous reports in the issue tracker
- I verified the problem still occurs when using the latest nightly build
- My report contains all necessary details