Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows compatibility. #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ccooper21
Copy link

This resolves issue #17.

@DancingQuanta
Copy link

This works okay in cmd on Windows 10, however I get some strange characters if I tried to navigate the filesystem of my fipy.
Here is an example

C:\Users\andre> boards
pyboard @ COM3 connected Dirs: /flash /pyboard/flash
C:\Users\andre> cd /flash
/flash> ls
�[1;36mcert�[0m/   �[1;36mlib�[0m/    �[1;36msys�[0m/    �[2;32mboot.py�[0m �[2;32mmain.py�[0m
/flash> cd /pyboard/flash
/pyboard/flash> ls
�[1;36mcert�[0m/   �[1;36mlib�[0m/    �[1;36msys�[0m/    �[2;32mboot.py�[0m �[2;32mmain.py�[0m

Secondly, the backspace in repl mode behaves correctly, as it delete the last character on the line, but it shows up as gibbish on the line.

C:\Users\andre> connect serial COM3
Connecting to COM3 ...
C:\Users\andre> repl
Entering REPL. Use Control-X to exit.
>
MicroPython 2ac6da2 on 2017-12-18; FiPy with ESP32
Type "help()" for more information.
>>>
>>> print("Hello Wrodl")
Hello Wrodl
>>> prin�[�[�[�[�[K
>>> print�[K
<function>
>>> print�[�[�[K
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pri' is not defined

The first print line is shown to be completely deleted with backspace, the second have a space after print which is then deleted with a backspace and shows up the type of function. The last shows partial delete of print which trigger an error as expected.

Lastly I preferred cygwin and so I found that for the navigation, the strange characters are not there which means that there are formatting problems in Windows.

C:\Users\andre> connect serial COM3
Connecting to COM3 ...
C:\Users\andre> boards
pyboard @ COM3 connected Dirs: /flash /pyboard/flash
C:\Users\andre> cd /flash
/flash> ls
cert/   lib/    sys/    boot.py main.py

However in cygwin the repl is not working. Every time Enter is pressed, a new line is generated without any arrows or results of operations.

C:\Users\andre> connect serial COM3
Connecting to COM3 ...
C:\Users\andre> boards
pyboard @ COM3 connected Dirs: /flash /pyboard/flash
C:\Users\andre> repl
>Entering REPL. Use Control-X to exit.

MicroPython 2ac6da2 on 2017-12-18; FiPy with ESP32
Type "help()" for more information.
>>>
>>


print("Hello World!")

@dhylands
Copy link
Owner

The weird characters are the codes to colorization. You can run rshell with the -n or --nocolor command line option to cause the colorization to be disabled.

@DancingQuanta
Copy link

Thank you for pointing out the -n option. However that is only useful for file system navigation. It have no effect on Micropython REPL where I get strange characters from pressing backspace or arrow keys.

@DancingQuanta
Copy link

I think that the getch class does not include any support for the cygwin therefore the REPL will not work. Oh well, this may take some time to remedy.

@dhylands
Copy link
Owner

dhylands commented Jan 2, 2018

I've used rshell under cygwin before with no issues. I was probably using Windows 7 at the time. Which version of WIndows are you using cygwin with ans rshell isn't working?

@jumblies
Copy link

jumblies commented Jun 11, 2018

Hiya, I just started exploring MP and wanted to optimize workflow with rshell.
I am running Win7 ultimate with python 3.6. I was able to create a venv, install rshell, readline, and rlcompleter as alluded to in Issue 17.

The only problem I had entering rshell was as follows:

(mpshell) c:\Python36\mpshell>rshell --port COM3 repl
Connecting to COM3 ...
Entering REPL. Use Control-X to exit.
Exception in thread REPL_serial_to_stdout:
Traceback (most recent call last):
  File "c:\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "c:\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "c:\python36\mpshell\lib\site-packages\rshell\main.py", line 2249, in rep
l_serial_to_stdout
    dev.timeout(1)
TypeError: 'NoneType' object is not callable

and

...
  File "c:\python36\mpshell\lib\site-packages\rshell\main.py", line 2246, in rep
l_serial_to_stdout
    save_timeout = dev.timeout()
TypeError: 'NoneType' object is not callable

but after commenting the dev.timeout() call, was able to run it.

so from line 2240 down now looks like this:

    def repl_serial_to_stdout(self, dev):
        """Runs as a thread which has a sole purpose of readding bytes from
           the seril port and writing them to stdout. Used by do_repl.
        """
        with self.serial_reader_running:
            try:
                # save_timeout = dev.timeout()
                # Set a timeout so that the read returns periodically with no data
                # and allows us to check whether the main thread wants us to quit.
                # dev.timeout(1)
                while not self.quit_serial_reader:
                    try:
                        char = dev.read(1)
                    except serial.serialutil.SerialException:

I'll report back if this causes any unforseen problems and I suspect this is a peculiarity with windows stdout.

Also, same issues with backspace in the REPL but nocolor works like a champ.

@dhylands
Copy link
Owner

I just fixed the issue with dev.timeout in 190d5fc

@jumblies
Copy link

jumblies commented Jun 16, 2018

Thank you for a great tool and your support.

Works like a champ after replacing

'libedit' in readline.__doc__ reference in main.py
with
readline.__doc__ and 'libedit' in readline.__doc__

as described in issue #17

Same problems with what I think is character encoding in the crossover from RSHELL to REPL.

The example below shows what is seen with trying to backspace. Arrow Key output is also wrong. Capital letters. I don't think it's so much a REPL problem as it is the way windows is echoing the input and/or passing it through rshell to REPL. I have tried changing console fonts with no result so it's not that part of it.

Entering REPL. Use Control-X to exit.
repl_serial_to_stdout dev = <rshell.main.DeviceSerial object at 0x030A2550>

>>> print("hello←[K")
hello
>>> print("I'm a bad type←[←[Ktypist")
I'm a bad typtypist
>>>

I found this on SO which I think is a clue to the issue. It's the usual M$ incompatibility with windows terminal. I don't get this at all in PuTTY over a serial connection. I haven't tried in powershell but will. Same output in powershell.

That SO overflow explanation is so thorough, I'd need to set aside an evening for it.

@gregorypruden
Copy link

This works fantastic in Windows 10 and in VS Code's terminal window. If only the up arrow worked in repl it would be ideal!

Windows 10 arrow keys work in rshell but not in it's repl. I get H for up arrow rather than the previous command. I get M for right arrow rather than moving right. I get P for down arrow and K for left arrow. Backspace works fine.

@dhylands dhylands force-pushed the master branch 3 times, most recently from 1861b2d to a28df4c Compare March 20, 2020 23:26
@dhylands dhylands mentioned this pull request Apr 9, 2022
@nznobody
Copy link

nznobody commented Jun 3, 2022

Possibly look a using an updated fork of pyreadline: git+https://github.com/osrf/pyreadline
As done here: ros2/ci#519
Otherwise switch to https://github.com/pyreadline3/pyreadline3

@markkamp
Copy link

Agree, changing dependency pyreadline to pyreadline3 will fix the following error for Python 3.10+ on Windows (because collections.Callable is moved to collections.abc.Callable).

    return isinstance(x, collections.Callable)
                         ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Callable'

Installed pyreadline3 myself as this is available via pip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants