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 for sending text to serial device over stdio? #521

Open
rej696 opened this issue Jul 31, 2023 · 4 comments
Open

Support for sending text to serial device over stdio? #521

rej696 opened this issue Jul 31, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@rej696
Copy link

rej696 commented Jul 31, 2023

Hi, I really like your plugin! I definitely think its the best way to do repl driven development in neovim!

I would like to be able to use your plugin to develop/execute code on serial devices (microcontrollers) for example a microcontroller running micropython, ulisp, or some forth.

I'm not sure the best/most compatible way to do this. It would be great to be able to send data to a program, like minicom or tio, running in a different tmux split/terminal. Or perhaps provide some interface for starting repls in conjure with user provided repl programs/commands, so you could do something like :Start-stdio "tio /dev/ttyUSB0" (https://github.com/tio/tio). something like this could maybe allow people to start repls for a currently unsupported language as well (like gforth)?

I'm not sure if this would be an easy thing to do or not. I had a look at some of the fennel code for python over stdio, but I'm not really familiar with fennel.

@Olical Olical added the enhancement New feature or request label Aug 2, 2023
@Olical
Copy link
Owner

Olical commented Aug 2, 2023

So some clients already have config to change their startup command:

`g:conjure#client#python#stdio#command`
Command used to start the Python REPL, you can modify this to add
arguments or change the command entirely.
Default: `"python3 -iq"`

Maybe that could be used to instead start some other CLI program that redirects output over the network into Conjure. This is kind of a hack though really, ideally this would be built off the back of #500 (comment)

Where we could write some sort of remote layer that can be plugged into any client. Orrr we do what currently works with the system, create a new client (either in this repo or outside of it, that doesn't matter, they're just Lua modules) that works in the way you need with the language you need.

The last option is the thing that's actionable now, and possibly just configuring an existing client with a different startup command. Sorry that I don't have any snippets or quick answers to this, it's a tricky interesting problem.

Do you think configuring an existing client would be enough? If not maybe we can copy/paste/edit another existing one and hack it into doing what you want.

@rej696
Copy link
Author

rej696 commented Aug 3, 2023

Ah ok. I was thinking of having a "serial" client, but it seems that the functionality for sending forms etc. is quite specific to the language being used.

So using the example of micropython on a pi pico, you should be able to just copy the existing python-stdio lua/fennel code, and change the command from "python -iq" to "tio /dev/ttyUSB0" or "python3 -m serial /dev/ttyUSB0" to use the serial console instead? Is it easy enough to get it so you can specify which python client to connect to, and what port to use (:ConjureConnect /dev/ttyUSB0). I am guessing the lisp client could be copied/modified in a similar way to be able to use ulisp on a micro controller.

And the other usecase of using forth would then require a new language client then? forth is pretty easy to parse, so maybe this wouldn't be too difficult? You could have it as a stdio one like the default python client, but using gforth, and then have a second "serial" client?

I might have a go at hacking the python one to work like you suggested, thanks :)

@russtoku
Copy link
Contributor

russtoku commented Aug 4, 2023

Ah ok. I was thinking of having a "serial" client, but it seems that the functionality for sending forms etc. is quite specific to the language being used.

If you want to do a "proof-of-concept" without worrying about sending forms or language being used, you can try using the SQL client.

To do so:

  • Set these variables in your Neovim configuration file and restart Neovim:
    • :let g:conjure#client_on_load = v:false so that a REPL isn't automatically started.
    • :let g:conjure#client#sql#stdio#command = "tio /dev/ttyUSB0" so that tio will be your REPL.
    • :let g:conjure#log#hud#enabled = v:false so that the HUD (heads-up display) window doesn't pop up.
  • Edit an SQL file. Let's say "tio.sql" as an example. It should be empty.
  • Open the Conjure log buffer in a horizontal split window with <LocalLeader>ls or a vertical split with <LocalLeader>lv.
  • Start the REPL using <LocalLeader>cs.
  • Add some commands or whatever you want to send to tio in the "tio.sql" file that you're editing. You don't have to format things like SQL code. Just any arbitrary stuff line by line should be fine.
  • Select what you want to send to tio and then send it using <LocalLeader>E.
  • Stop the REPL using <LocalLeader>cS.

I don't think you'll need to change the prompt pattern but if you want to try use:

  • let g:conjure#client#sql#stdio#prompt_pattern = "\<fill this in\>"

I haven't tried this but I'm imagining that it should help.

@russtoku
Copy link
Contributor

I just finished programming a Dune Worm Thumper which uses the amazing Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier device. CircuitPython is used as the programming language.

The Adafruit guides use screen to access the device's console via the USB connection. After I did that to make sure that things are working correctly, I decided to try using Conjure to access the device's CircuitPython. The short answer is it doesn't work.

I didn't use the sql client because it will add a semi-colon (";") to the end of what you're sending to the REPL. That would mess things up with CircuitPython.

So, I used the snd-s7 client to see if what I suggested would work but it didn't. I got an error about eval-str not being implemented. I wrote the first implementation of thesnd-s7 and sql clients so I'll need to see what that's about. Which then means that I should implement a "serial" client. The first pass would be more of a tio specific one.

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

No branches or pull requests

3 participants