Automate command lines that use rshell

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Alqx
Posts: 4
Joined: Fri Jan 08, 2021 3:13 pm

Automate command lines that use rshell

Post by Alqx » Wed Mar 10, 2021 1:03 pm

Hi the micropython community,
I encountered a problem using rshell :( . In fact, I am on windows 10 and I am using a batch file to automate command lines (4 lines in all). The 3 rd line involves the rshell. Only here, once I am correctly connected to the rshell, the last line is not carried out.
Do you know why ? If yes, how to fix it?
I leave you a screenshot attached.
Here are the command line:

d: #in order to connect to the correct disk
python CAMERA.py #run a python script using the webcam
rshell #in order to connect to the pyboard
repl ~ exec(open('motor.py').read()) ~ #run a script on the pyboard allowing to run motors

Thank you in advance for your help!
Best regards,
TROESTLER Grégoire, student in preparatory class for engineering schools.
Attachments
Screenshot.PNG
Screenshot.PNG (13.81 KiB) Viewed 2624 times

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

Re: Automate command lines that use rshell

Post by dhylands » Wed Mar 10, 2021 11:32 pm

You should be putting the repl command on the same line as the rshell commnad. So:

Code: Select all

d: #in order to connect to the correct disk
python CAMERA.py #run a python script using the webcam
rshell repl "~ exec(open('motor.py').read()) ~"
Normally, I would use import rather than exec. i.e. use:

Code: Select all

rshell repl "~ import motor ~"
I'm not exactly sure about the quotes when using windows, but they're definitely need on Mac/Linux.

The way you've show things, rshell will be launched and once you press Control-D to exit, it will then resume running the script and probably produce an error because it doesn't know what the repl command is. For example, I created hello.py with the following contents:

Code: Select all

import time

print('Hello World')
print('Sleeping for 10 seconds')

time.sleep(10)

print('After sleep')
and running this shows:

Code: Select all

$ rshell 'repl ~ import hello ~'
Connecting to /dev/cu.usbmodem3389337E34332 (buffer-size 512)...
Trying to connect to REPL  connected
Retrieving sysname ... pyboard
Testing if sys.stdin.buffer exists ... Y
Retrieving root directories ... /flash/
Setting time ... Mar 10, 2021 15:35:27
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
/Users/davehylands/micropython/upy-examples> Entering REPL. Use Control-X to exit.
>
MicroPython v1.12-210-g1993c8c-dirty on 2020-02-29; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
>>> import hello 
Hello World
Sleeping for 10 seconds
$

Alqx
Posts: 4
Joined: Fri Jan 08, 2021 3:13 pm

Re: Automate command lines that use rshell

Post by Alqx » Thu Mar 11, 2021 6:09 pm

Hi Dave,
Thanks a million !! :D
It works !
(And just to let you know: the command works also without quotes on windows )

Post Reply