Skip to content

Opening Serial Monitor during upload causes it to fail #581

Closed
@per1234

Description

@per1234

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:

  1. Close port in Serial Monitor
  2. Complete upload process
  3. 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

  1. Close Serial Monitor if it is already open.
  2. 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.
  3. 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.
  4. 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:

image

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions