conjure icon indicating copy to clipboard operation
conjure copied to clipboard

Support for sending text to serial device over stdio?

Open rej696 opened this issue 1 year ago • 4 comments

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.

rej696 avatar Jul 31 '23 16:07 rej696

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.

Olical avatar Aug 02 '23 13:08 Olical

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 :)

rej696 avatar Aug 03 '23 10:08 rej696

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 avatar Aug 04 '23 19:08 russtoku