Skip to content
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

device monitor: more graceful exit on disconnect #4268

Closed
wants to merge 3 commits into from

Conversation

belm0
Copy link
Contributor

@belm0 belm0 commented May 15, 2022

Fixes #3939

$ pio device monitor
--- Available filters and text transformations: colorize, debug, default, direct, nocontrol, printable
--- More details at https://bit.ly/pio-monitor-filters
--- Miniterm on /dev/cu.wchusbserial51850172701  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
fps:  64.4,  render:  1.0 ms
fps:  64.4,  render:  1.0 ms
fps:  64.4,  render:  1.0 ms
fps:  64.4,  render:  1.0 ms
--- receive exception ---

--- exit ---

@belm0
Copy link
Contributor Author

belm0 commented May 15, 2022

I'll make a small change to honor --quiet

@ivankravets
Copy link
Member

Sorry, I don't think we will be able to merge it. We support multiple versions of PySerial. We don't plan to maintain this part of 3rd party code in future PlatformIO releases.

If we can import the original miniterm code and "mock" some parts, it could make sense.

@belm0
Copy link
Contributor Author

belm0 commented May 15, 2022

This PR doesn't constrain the version of pyserial used by platformio. As long as the API used by the miniterm module is available, it's fine.

miniterm is a stand-alone application or example. It's not tightly coupled to the pyserial implementation, and it only uses the public pyserial API.

@ivankravets
Copy link
Member

How about importing the existing miniterm module and mocking only specific functions? Python allows this.

from serial  import Miniterm

Miniterm.dump_port_settings = mocked_func

@belm0
Copy link
Contributor Author

belm0 commented Jun 9, 2022

How about importing the existing miniterm module and mocking only specific functions?

That would be contrary to the goal you stated. By monkey-patching the library's miniterm, the result will be tightly bound to a specific version range of pyserial, and likely to break in the future. It's better to copy the code that is using the public API. (I don't expect the API to be broken trivially, given the number of pyserial users.)

Imagine if the pyserial author had never put miniterm into the library, and just left it in the examples directory. Wouldn't platformio have just used that as a reference point to get the job done?

@ivankravets ivankravets added this to the 6.0.3 milestone Jun 10, 2022
@ivankravets
Copy link
Member

Thanks again for the PR! I've finally found time and refactored the device monitor module. See 7f351bc

Please re-test with pio upgrade --dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serial Monitor should handle disconnects more gracefully
2 participants