The tool pyboard.py工具 ===================

This is a standalone Python tool that runs on your PC that provides a way to: 这是一个独立的Python工具,运行在您的PC上,提供了一种方式:

  • Quickly run a Python script or command on a MicroPython device. This is useful while developing MicroPython programs to quickly test code without needing to copy files to/from the device.

  • 在MicroPython设备上快速运行Python脚本或命令。这是非常有用的 在开发微python程序时,无需快速测试代码 复制文件到/从设备。

  • Access the filesystem on a device. This allows you to deploy your code to the device (even if the board doesn’t support USB MSC).

  • 访问设备上的文件系统。这允许您将代码部署到 设备(即使董事会不支持USB MSC)。

Despite the name, works on all MicroPython ports that support the raw REPL (including STM32, ESP32, ESP8266, NRF). 尽管名字,````的所有MicroPython端口上都可以工作 原始REPL(包括STM32, ESP32, ESP8266, NRF)。

You can download the latest version from GitHub. The only dependency is the pyserial library which can be installed from PiPy or your system package manager. 你可以从GitHub下载最新版本 <>`_。的 唯一依赖的是``pyserial``库,它可以从PiPy或 您的系统包管理器。

Running --help gives the following output: 运行`` –help``会给出以下输出:

usage: pyboard [-h] [--device DEVICE] [-b BAUDRATE] [-u USER]
               [-p PASSWORD] [-c COMMAND] [-w WAIT] [--follow] [-f]
               [files [files ...]]

Run scripts on the pyboard.

positional arguments:
  files                 input files

optional arguments:
  -h, --help            show this help message and exit
  -h, --help            显示此帮助信息并退出
  --device DEVICE       the serial device or the IP address of the
  --device DEVICE       的串行设备或IP地址
  -b BAUDRATE, --baudrate BAUDRATE
                        the baud rate of the serial device
  -u USER, --user USER  the telnet login username
  -u USER, --user USER  telnet登录用户名
  -p PASSWORD, --password PASSWORD
                        the telnet login password
  -c COMMAND, --command COMMAND
                        program passed in as string
  -w WAIT, --wait WAIT  seconds to wait for USB connected board to become
  -w WAIT, --wait WAIT  秒等待USB连接板成为
  --follow              follow the output after running the scripts
  --follow              运行脚本后按照输出进行操作
                        [default if no scripts given]
  -f, --filesystem      perform a filesystem action
  -f, --filesystem      执行文件系统操作

Running a command on the device 在设备上运行命令 ——————————-

This is useful for testing short snippets of code, or to script an interaction with the device.:: 这对于测试简短的代码片段或编写交互脚本非常有用 与设备。:

$ --device /dev/ttyACM0 -c 'print(1+1)'

Running a script on the device 在设备上运行脚本 ——————————

If you have a script, that you want to run on a device, then use:: 如果你有一个脚本,,然后使用:

$ --device /dev/ttyACM0

Note that this doesn’t actually copy to the device’s filesystem, it just loads the code into RAM and executes it. Any output generated by the program will be displayed. 注意,这实际上并没有将app.py复制到设备的文件系统,它只是 将代码加载到RAM中并执行。程序生成的任何输出 将显示出来。

If the program does not finish then you’ll need to stop, eg with Ctrl-C. The program will still continue to run on the MicroPython device. 如果程序app.py没有完成,那么您需要停止, 例如,ctrl - c。程序的应用````仍将继续运行 MicroPython设备。

Filesystem access 文件系统访问 —————–

Using the -f flag, the following filesystem operations are supported: 使用``-f``标志,支持下列文件系统操作:

  • cp src [src...] dest Copy files to/from the device.

  • cp src [src...] dest 复制文件到/从设备。

  • cat path Print the contents of a file on the device.

  • cat path 打印设备上文件的内容。

  • ls [path] List contents of a directory (defaults to current working directory).

  • ls [path] 列出目录的内容(默认为当前工作目录)。

  • rm path Remove a file.

  • rm path 移动一个文件

  • mkdir path Create a directory.

  • mkdir path 创建一个目录

  • rmdir path Remove a directory.

  • rmdir path 删除一个目录。

The cp command uses a ssh-like convention for referring to local and remote files. Any path starting with a : will be interpreted as on the device, otherwise it will be local. So:: cp 命令使用类似``ssh``的约定来引用本地和 远程文件。任何以``:``开头的路径都将被解释为on 设备,否则将是本地的。所以:

$ --device /dev/ttyACM0 -f cp

will copy from the current directory on the PC to a file named on the device. The filename can be omitted, e.g.:: 是否将main.py从PC上的当前目录复制到名为main.py的文件 在设备上。文件名可以省略,例如:

$ --device /dev/ttyACM0 -f cp :

is equivalent to the above. 等于上面的式子。

Some more examples:: 一些例子:

# Copy from the device to the local PC.
# 将main.py从设备复制到本地PC。
$ --device /dev/ttyACM0 -f cp
# Same, but using . instead.
# 相同,但使用。代替。
$ --device /dev/ttyACM0 -f cp .

# Copy three files to the device, keeping their names
# 复制三个文件到设备上,保留它们的名字
# and paths (note: `lib` must exist on the device)
# 和路径(注意:`lib`必须存在于设备上)
$ --device /dev/ttyACM0 -f cp lib/ :

# Remove a file from the device.
# 从设备中删除一个文件。
$ --device /dev/ttyACM0 -f rm

# Print the contents of a file on the device.
# 在设备上打印文件的内容。
$ --device /dev/ttyACM0 -f cat
...contents of

Using the pyboard library 使用pyboard库 ————————-

You can also use as a library for scripting interactions with a MicroPython board. 你也可以使用````作为一个库,用于脚本化与 MicroPython董事会。