Windows上的Rshell通过rsync或cp将文件发送到运行micropython的ESP32时会随机冻结

时间:2019-12-05 18:22:51

标签: windows esp32 micropython

我无法通过rshell(远程micropython shell)将文件复制到运行micropython的ESP32设备。该问题似乎是随机发生的。有时我设法用rsync成功发送所有文件(例如20个文件),有时甚至不能用cp复制一个文件。没有错误消息,脚本也不会崩溃,它只是停止工作并冻结了控制台。我试过使用-a参数(不发送-py文件)。使用debug进行打印的最后一件事是要在下面的微控制器上运行的代码,它仅在此处停止。我没有找到任何模式。我试过使用其他一些esp32设备和其他Windows PC。结果相同。我什至尝试将默认的32缓冲区降低到16,没有任何改善。最糟糕的是,有时效果很好,但我无法获得稳定的结果(甚至不好)。它会停止在随机文件上,而不总是一个。

Rsync命令(带有--mirror参数)非常有用,我不能只手工复制所有文件。

编辑:刚刚在Mac上进行了测试,效果很好。我想这只是Windows上的问题...

Adding /pyboard/protocol/parser.py
----- About to send 2269 bytes of code to the pyboard -----
def recv_file_from_host(src_file, dst_filename, filesize, dst_mode='wb'):
"""Function which runs on the pyboard. Matches up with send_file_to_remote."""
import sys
import ubinascii
import os
if False:
    try:
        import pyb
        usb = pyb.USB_VCP()
    except:
        try:
            import machine
            usb = machine.USB_VCP()
        except:
            usb = None
    if usb and usb.isconnected():
        # We don't want 0x03 bytes in the data to be interpreted as a Control-C
        # This gets reset each time the REPL runs a line, so we don't need to
        # worry about resetting it ourselves
        usb.setinterrupt(-1)
try:
    with open(dst_filename, dst_mode) as dst_file:
        bytes_remaining = filesize
        if not False:
            bytes_remaining *= 2  # hexlify makes each byte into 2
        buf_size = 32
        write_buf = bytearray(buf_size)
        read_buf = bytearray(buf_size)
        while bytes_remaining > 0:
            # Send back an ack as a form of flow control
            sys.stdout.write('\x06')
            read_size = min(bytes_remaining, buf_size)
            buf_remaining = read_size
            buf_index = 0
            while buf_remaining > 0:
                if False:
                    bytes_read = sys.stdin.buffer.readinto(read_buf, read_size)
                else:
                    bytes_read = sys.stdin.readinto(read_buf, read_size)
                if bytes_read > 0:
                    write_buf[buf_index:bytes_read] = read_buf[0:bytes_read]
                    buf_index += bytes_read
                    buf_remaining -= bytes_read
            if False:
                dst_file.write(write_buf[0:read_size])
            else:
                dst_file.write(ubinascii.unhexlify(write_buf[0:read_size]))
            if hasattr(os, 'sync'):
                os.sync()
            bytes_remaining -= read_size
    return True
except:
    return False
output = recv_file_from_host(None, '/protocol/parser.py', 1467)
if output is None:
print("None")
else:
print(output)

-----

1 个答案:

答案 0 :(得分:0)

我有同样的问题, 尝试

    C:\> cp src\main.py /pyboard/

cmd冻结。 当我使用以下内容复制

    C:\> cp src/main.py /pyboard/

那里没有问题,所以当路径中有“ \”时,rshell可能会出现一些问题