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
Meekdai
Posts: 21
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: 581
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.

Meekdai
Posts: 21
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: 2882
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: 3074
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

Meekdai
Posts: 21
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: 3074
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

Post Reply