arduino / arduino-ide

Arduino IDE 2.x
https://www.arduino.cc/en/software
GNU Affero General Public License v3.0
2.35k stars 395 forks source link

Port left open after closing Serial Plotter #1423

Open per1234 opened 2 years ago

per1234 commented 2 years ago

Describe the problem

If one process has a serial port open, another can not access it. Arduino IDE is designed to automatically manage access to ports by the various operations and components that use them:

The user may also use the port from an external application during sketch development in Arduino IDE. They will be responsible for managing the access of the port by the IDE and the external application. This means that the IDE must always relinquish port access when the user closes a component using the port

🐛 The port is left open after closing the Serial Plotter window.

To reproduce

  1. Select a serial port in the Arduino IDE.
  2. Select Tools > Serial Plotter from the Arduino IDE menus to open the "Serial Plotter".
  3. Close the "Serial Plotter" window.
  4. Open the port in an external application.

🐛 Opening the port fails.

Expected behavior

Port is closed when Serial Plotter window is closed.

Arduino IDE version

2.0.0-rc9.4

Operating system

Windows, Linux

Operating system version

Windows 10, Ubuntu 20.04

Additional context

From Windows Task Manager and GNOME System Monitor, I can see that the serial-monitor process is not being closed when the Serial Plotter window is closed.


I bisected the introduction of the issue to df8658e


The problem does not occur if the procedure described above is performed using Serial Monitor instead of Serial Plotter (in fact cycling Serial Monitor open and then closed again closes the port after it was left open by Serial Plotter).


The issue does not occur when using Arduino IDE 1.8.19 Serial Monitor


Some options for external applications that can be used for the final step in the demo:

$ arduino-cli upload --fqbn arduino:avr:uno --port COM7
avrdude: ser_open(): can't open device "\\.\COM7": Access is denied.
$ arduino-cli upload --fqbn arduino:samd:mkrzero --port COM47
TOUCH: error during reset: opening port at 1200bps: Serial port busy
No device found on COM47
Error during Upload: Failed uploading: uploading error: exit status 1
$ arduino-cli monitor --port COM7
Port monitor error: command 'open' failed: Serial port busy

Opening the port in Arduino IDE 1.x Serial Monitor

Error opening serial port 'COM7'. (Port busy)

Additional reports

Issue checklist

zvonler commented 1 year ago

@per1234 I just noticed this issue with the 2.x IDE I have installed. Using the Serial Plotter always leaves the serial port busy, no matter how I close the Plotter. If I then start/stop the Serial Monitor in the IDE, the port is released.