Skip to content

Manually disconnect serial port #1800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
falk-stefan opened this issue Jan 5, 2023 · 6 comments
Closed
3 tasks done

Manually disconnect serial port #1800

falk-stefan opened this issue Jan 5, 2023 · 6 comments
Assignees
Labels
conclusion: invalid Issue/PR not valid topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@falk-stefan
Copy link

Describe the request

I want to be able to manually disconnect the serial port connection using a toggle-button.

At the moment I am using a JavaScript client in order to visualize serial data. However, in order to be able to connect via serial connection, I have to close the Arduino IDE entirely.

It would be nice if we could just close the connection if we want to.

Describe the current behavior

Afaik there is no way to close the serial connection.

Arduino IDE version

2.0.3

Operating system

Windows

Operating system version

10

Additional context

No response

Issue checklist

  • I searched for previous requests in the issue tracker
  • I verified the feature was still missing when using the latest nightly build
  • My request contains all necessary details
@falk-stefan falk-stefan added the type: enhancement Proposed improvement label Jan 5, 2023
@per1234 per1234 self-assigned this Jan 5, 2023
@per1234
Copy link
Contributor

per1234 commented Jan 5, 2023

Hi @falk-stefan. Thanks for your suggestion.

I need to understand how you are using the serial port in Arduino IDE.

Do you have a "Serial Monitor" tab in the bottom panel of your IDE?:

image

Did you use Serial Plotter at any time during the Arduino IDE session?:

image

@per1234 per1234 added topic: code Related to content of the project itself status: waiting for information More information must be provided before work can proceed labels Jan 5, 2023
@falk-stefan
Copy link
Author

Hi!

This has nothing to do with the Serial Monitor as such. I just want to open a web browser and connect to the serial port where the Arduino is connected. However, if the Arduino IDE is open, then the board gets connected automatically for programming the Atmega. In my case e.g. the COM3 port is used and connected. If I now want to use my JavaScript client like so:

const port = await navigator.serial.requestPort();
// Wait for the serial port to open.
await port.open({ baudRate: 9600 });

it won't work because Arduino is occupying the port.

Uncaught (in promise) DOMException: Failed to execute 'open' on 'SerialPort': Failed to open serial port.

The only way around this it seems is to close the IDE.

@per1234
Copy link
Contributor

per1234 commented Jan 5, 2023

@falk-stefan please just give a straightforward answer to the questions I asked:

Is there a "Serial Monitor" tab in the bottom panel of the IDE window? If you don't see the bottom panel, you can open it by clicking this icon at the right side of the status bar:

image

Did you use Serial Plotter at any time during the Arduino IDE session?

What you need to understand is that Arduino IDE itself does not open the selected serial port other than during the upload process. So we are left with three possible causes of the problem you are experiencing:

  • You have Serial Monitor running (which does open the port)
  • You have Serial Plotter running (which does open the port) or you used Serial Plotter at some time during the session (there is a known bug that the port is not closed)
  • There is a bug in Arduino IDE that is causing it to open the port.

We must determine which of these three things is causing the problem. In order to do that, you must answer my questions.

If it is the first, then you simply need to close Serial Monitor.

If it is the second, then we already have an issue tracking the bug of the port not being closed.

If it is the third, then we must investigate the bug and fix it.


You are presenting an XY problem here. You think the solution (X) is to add a GUI element to close the port. But the real problem (Y) is that the serial port is open in the first place.

In the case of Serial Monitor, we already have that GUI element (the X icon on the view tab). In the case of Serial Plotter, we already have that GUI element (the window close control), but it is not working currently. In the case of the IDE itself, there is no point in adding a GUI element because the hypothetical bug should just be fixed instead.

@falk-stefan
Copy link
Author

You were right by suggesting to close the Serial Monitor. I was under the impression that the port is being opened and kept open during the IDE is running.

Closing the Serial Monitor, as you said, fixes the issue. Thanks.

@per1234
Copy link
Contributor

per1234 commented Jan 5, 2023

You are welcome. I'm glad it is working now.

I think the current UI design does not make the need to close Serial Monitor to free the port obvious to the user. That poor user experience should be resolved as a matter of course when Serial Monitor is moved to a dedicated window: #289 (comment)

@per1234 per1234 added conclusion: invalid Issue/PR not valid and removed status: waiting for information More information must be provided before work can proceed labels Jan 5, 2023
@falk-stefan
Copy link
Author

Got it. Looking forward to upcoming upgrades 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: invalid Issue/PR not valid topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

2 participants