micropython / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
19.18k stars 7.68k forks source link

pyboard.py: add "delay" argument in CLI #5456

Open ShenTengTu opened 4 years ago

ShenTengTu commented 4 years ago

I used ampy to interact with ESP32 before. In my case, I need to give a delay (3 sencods) to enter raw REPL successfully.

ampy --port com14 --delay 3 ls

If I use pyboard.py CLI, I can't enter raw REPL, even if I set the --wait argument to 3.

pyboard.py --device com14 -w 3 -f ls

In ampy source code, --delay parameter is applied to the top of the enter_raw_repl () function to control the delay before enter raw REPL:

ampy/pyboard.py#L175

    def enter_raw_repl(self):
        # Brief delay before sending RAW MODE char if requests
        if _rawdelay > 0:
            time.sleep(_rawdelay)
       # ...

I use a simple script to test orginal pyboard.py, and it is work:

import pyboard
import time
pyb = pyboard.Pyboard('COM14')
time.sleep(3) # delay before enter
pyb.enter_raw_repl()
ret = pyb.exec_('print(1+1)')
print(ret)
pyb.exit_raw_repl()

I hope pyboard.py CLI can provide a parameter to control the delay.

IveJ commented 4 years ago

Hi Issuer,

You should enter python env in shell or run via python interpreter.

ampy is builtin cli.

On Wed, Dec 25, 2019, 14:46 涂紳騰(Shen-Teng Tu) notifications@github.com wrote:

I used ampy to interact with ESP32 before. In my case, I need to give a delay (3 sencods) to enter raw REPL successfully.

ampy --port com14 --delay 3 ls

If I use pyboard.py CLI, I can't enter raw REPL, even if I set the --wait argument to 3.

pyboard.py --device com14 -w 3 -f ls

In ampy source code, --delay parameter is applied to the top of the enter_raw_repl () function to control the delay before enter raw REPL:

ampy/pyboard.py#L175 https://github.com/scientifichackers/ampy/blob/c0b568cf12b017bd9dfd7d61a7132b7d760278a0/ampy/pyboard.py#L175

def enter_raw_repl(self):
    # Brief delay before sending RAW MODE char if requests
    if _rawdelay > 0:
        time.sleep(_rawdelay)
   # ...

I use a simple script to test orginal pyboard.py, and it is work:

import pyboardimport time pyb = pyboard.Pyboard('COM14') time.sleep(3) # delay before enter pyb.enter_rawrepl() ret = pyb.exec('print(1+1)')print(ret) pyb.exit_raw_repl()

I hope pyboard.py CLI can provide a parameter to control the delay.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/micropython/micropython/issues/5456?email_source=notifications&email_token=AEYAML5B5MDMRTCKM6HK24DQ2MFXFA5CNFSM4J7DFYX2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICSS2LQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYAML3KQI2ZKAELZ5ZRLJDQ2MFXFANCNFSM4J7DFYXQ .