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

Support communication via stdin/stderr rather than serial port #16

Merged
merged 7 commits into from
Nov 21, 2019

Conversation

sdt
Copy link
Contributor

@sdt sdt commented Nov 7, 2019

My ideal workflow with micropython would be to editing source files in my text editor, with mpy-watch syncing the changes to the microcontroller, but also to have the repl open so that I could manually try out functions or whatever.

Having the repl and mpy-watch connected at the same time isn't really an option, so this is an attempt at a workaround.

picocom has a --send-cmd option which is intended for use with a file-send program such as sx or sz. The specified command is spawned with picocom's serial port attached to stdin and stdout.

This PR adds a --pipe option to each of the mpy-utils programs, which will use the stdin/stdout filehandles instead of using the serial port directly, allowing these to be spawned from picocom.

eg. picocom -b 115200 -s "mpy-sync --pipe --reset src/"

From with picocom, hitting C-a C-s enter will run mpy-sync, and then return to the repl.

The serial port handling code in replcontrol.py has been factored out into a ReplIOSerial class, and a ReplIOFileHandle class has been added.

All four mpy-utils have been converted. I don't quite see a use-case for spawning mpy-fuse from the repl, but it got added for completeness.

These can be tested directly from the Linux command-line by redirecting the serial device file to both stdin and stdout.

eg. mpy-watch --pipe --debug < /dev/ttyUSB0 > /dev/ttyUSB0

All logging and trace messages have been changed to use stderr.

We're going to need stdout for something else real soon
The intention is that the mpy-utils can be used in place of sx/sy/sz in
a terminal program, which typically means the serial port is mapped to
the stdin and stdout.
This will enable ReplIOFileHandle on stdin/stdout
@sdt
Copy link
Contributor Author

sdt commented Nov 7, 2019

Creating this as a draft PR so you can take a look, but I'd like to give it a bit more testing first.

@nickzoic
Copy link
Owner

nickzoic commented Nov 7, 2019

Thanks Steve, yeah I think this is a useful addition, and it makes sense to have the same options available across all the utils even if we don't have an immediate need for it in mpy-fuse.
It looks like it'll be pretty easy to expand it to hand TCP ports (eg: WebREPL or Telnet) in the future too.
I do wonder if we should somehow move off the --port --baud --pipe (and potentially --addr) options into their own ReplIoManager or something so that that code can be shared between utils.

@sdt sdt marked this pull request as ready for review November 17, 2019 00:57
@sdt
Copy link
Contributor Author

sdt commented Nov 17, 2019

I've given this quite a bit of use now, and it seems to be working well for me.

@nickzoic nickzoic merged commit b67ae26 into nickzoic:master Nov 21, 2019
@nickzoic
Copy link
Owner

Accepted, with many thanks!

@sdt sdt deleted the repl-io-filehandle branch November 21, 2019 23:10
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.

2 participants