Olical / conjure

Interactive evaluation for Neovim (Clojure, Fennel, Janet, Racket, Hy, MIT Scheme, Guile, Python and more!)
https://conjure.oli.me.uk
The Unlicense
1.79k stars 110 forks source link

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

Open rej696 opened 1 year ago

rej696 commented 1 year ago

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 commented 1 year ago

So some clients already have config to change their startup command: https://github.com/Olical/conjure/blob/2482871cbe0d1b85d331465cf7f065d5d2a7e2ac/doc/conjure-client-python-stdio.txt#L60-L63

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 https://github.com/Olical/conjure/discussions/500#discussioncomment-6061774

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 commented 1 year ago

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 commented 1 year ago

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:

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

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

russtoku commented 2 months ago

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.