I don't need echo when using repl

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
Meekdai
Posts: 45
Joined: Mon Jan 29, 2018 12:45 pm

I don't need echo when using repl

Post by Meekdai » Wed Jul 04, 2018 10:41 am

Hi everyone ,

when I using REPL, I found that it has the function of echo.
This problem does not exist when I use secureCRT, but when I receive serial port data by Serial debugging assistant, echo is appeared.
I guess secureCRT should hide echo which I was send.

Is there any way to cancel it? :?: :?:

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: I don't need echo when using repl

Post by Damien » Thu Jul 05, 2018 9:35 am

There's no way to turn off echo from the pyboard for the REPL because it's a fundamental part of how it works. Usually you will configure your serial terminal so it doesn't echo characters you type.

You might also like to try out raw REPL mode (ctrl-A at the prompt) which is a way to programmatically send code to the device.

User avatar
Meekdai
Posts: 45
Joined: Mon Jan 29, 2018 12:45 pm

Re: I don't need echo when using repl

Post by Meekdai » Fri Jul 06, 2018 1:31 am

Thank you Damien , I have a project that wants to communicate with the host computer through the REPL. But echo and ">>>" are not needed. I view the source code and made some modifications (pyexec.c readline.c) to implement my current functionality.
Before modification:
serial send:

Code: Select all

GetVersion()\r\n
serial receive:

Code: Select all

GetVersion()
REG08_V0.1
>>> 
After modification:
serial send:

Code: Select all

GetVersion()\r\n
serial receive:

Code: Select all

REG08_V0.1
I made a PC software to control the motion of the multiple stepper motors..
I know this should not be the best solution. Is there any other way to communicate between pyboard and PC software?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: I don't need echo when using repl

Post by dhylands » Fri Jul 06, 2018 3:59 am

If enter the raw REPL (see: http://docs.micropython.org/en/latest/p ... l#raw-mode) then the data which is sent to the pyboard is not echoed.

You could also use something like json-ipc which you can find over here:
https://github.com/dhylands/json-ipc

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: I don't need echo when using repl

Post by pythoncoder » Fri Jul 06, 2018 6:35 am

Is there any other way to communicate between pyboard and PC software?
You might use a UART and an FTDI USB adaptor. That way you could use the REPL normally while having a separate channel for data.
Peter Hinch
Index to my micropython libraries.

User avatar
Meekdai
Posts: 45
Joined: Mon Jan 29, 2018 12:45 pm

Re: I don't need echo when using repl

Post by Meekdai » Mon Jul 09, 2018 1:32 am

dhylands wrote:
Fri Jul 06, 2018 3:59 am
If enter the raw REPL (see: http://docs.micropython.org/en/latest/p ... l#raw-mode) then the data which is sent to the pyboard is not echoed.

You could also use something like json-ipc which you can find over here:
https://github.com/dhylands/json-ipc
I rewrote a custom REPL with reference to raw REPL. It works well.
json-ipc is not what I want,Because I need the parse and compile function like REPL.
pythoncoder wrote:
Fri Jul 06, 2018 6:35 am
Is there any other way to communicate between pyboard and PC software?
You might use a UART and an FTDI USB adaptor. That way you could use the REPL normally while having a separate channel for data.
If using serial communication, I need to define the communication protocol myself. I can rely on it completely through REPL.
Is there a similar REPL ready-to-use protocol that can be used on UART?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Serial communications protocols

Post by pythoncoder » Mon Jul 09, 2018 7:54 am

I don't know your level of experience but designing communication protocols in Python is easy if your communications link is reliable. This is thanks to its object serialisation libraries ujson and pickle. Aim for a half-duplex protocol: one end is the master. The slave never sends unsolicited messages. Usually all that's needed is to exchange Python dictionaries. The master sends a master dictionary to the slave, which responds with a response dictionary. The following gives a glimpse of this. To try it on a Pyboard link pins X1 and X2:

Code: Select all

import ujson
u = pyb.UART(4, baudrate=9600)

d = {1:'one', 2:'two'}
line = ''.join((ujson.dumps(d), '\n'))
u.write(line)

l2 = u.readline()
drec = ujson.loads(l2)
print(drec)
The dictionaries can be arbitrarily complex without altering a line of code.

If your communications link is unreliable (e.g. over a radio link) then protocol design becomes decidedly involved, but this won't arise with an FTDI adaptor connected to the Pyboard with short wires.
Peter Hinch
Index to my micropython libraries.

toybuilder
Posts: 1
Joined: Sun May 02, 2021 12:49 am

Re: I don't need echo when using repl

Post by toybuilder » Sun May 02, 2021 1:13 am

As someone that's just recently started the climb up the learning curve on micropython and python, I can appreciate the original question of this topic, as I've spend some time looking into it myself and have landed here a few times during my Google searches.

The answer pythoncoder provides is the correct one -- if you want to read a line of text without echo, readline() will process incoming bytes until the new-line and then return that result in a string.

I think what may be a bit unclear for people new to the micropython world is the distinction between when you are interacting with the REPL and when you're interacting with (user-created) code running on the board. When the user's code is running (either through booting up the board and running main.py, or by calling a function from the REPL and thus running in the code), the input/outputs are with the code, and no longer involves the REPL until the program is exited (either through a keyboard interrupt or via a sys.exit() call) and control passes back to the REPL.

Related to this (at least for my own purposes), you might have a desire to read data from stdin when there is data, but not block while that is happening. The post at viewtopic.php?t=7325 is helpful -- but only talks about the case of reading one byte at a time with read(1). read(1) can be replaced with readline() for a blocking read to the newline once characters start arriving.

Post Reply