mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
099bcf9f42
@ -0,0 +1,67 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12450-1.html)
|
||||
[#]: subject: (Customizing my Linux terminal with tmux and Git)
|
||||
[#]: via: (https://opensource.com/article/20/7/tmux-git)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
使用 tmux 和 Git 自定义我的 Linux 终端
|
||||
======
|
||||
|
||||
> 设置你的控制台,以便你能知道身处哪个目录和该做什么
|
||||
|
||||

|
||||
|
||||
我使用 GNOME 终端,主要是因为它是我的发行版的默认设置。但是我终端内远非“默认值”。在我开始解释如何自定义它之前,它现在是这个样子:
|
||||
|
||||
![Moshe Zadka's terminal][2]
|
||||
|
||||
### 从底部开始
|
||||
|
||||
我使用终端多路复用技术 [tmux][4] 管理我的终端体验。
|
||||
|
||||
在上图的底部,你可以看到我的绿色 tmux 栏。底部的 `[3]` 表示它是第三个终端:每个终端都运行自己的 tmux 会话。(我创建了一个新会话来放大字体,这样可在截图中更容易看到;这是它与其他终端之间的唯一区别。)
|
||||
|
||||
提示符看起来也很有趣,对吧?在提示符中塞入了太多信息后,我喜欢插上一个换行符,这样一来,如果我想即兴进行 shell 编程或编写一个传递了五次的管道,也不会超出屏幕界限。这样做的代价是简单的命令序列(新建、复制、移动)会更快地滚动出我的屏幕。
|
||||
|
||||
行末是 <ruby>[阿列夫零][5]<rt>Aleph null</rt></ruby> 字符,它是最小的[无穷基数][6]。我希望内容行的结束很明显,并且当我意识到“阿列夫”和下标 0 都是 Unicode 字符时,我无法抗拒使用“阿列夫零”作为提示符的一部分的诱惑。(数学极客们,团结起来!)
|
||||
|
||||
在此之前是我的用户名。由于我在不同用户名的多台计算机上使用相同的[点文件][7](保存在 Git 中),因此这个还算有用。
|
||||
|
||||
在我的用户名之前,是我所在目录的最后一部分。完整路径通常太长且无用,而当前目录对于像我这样的经常忘记在做什么人来说是很有用的。在此之前是机器的名称。我所有的机器都以我喜欢的电视节目命名。我的旧笔记本是 `mcgyver`。
|
||||
|
||||
提示符中的第一位是我最喜欢的:一个让我知道目录的 Git 状态的字母。如果目录为“不在 Git 中”,那么是 `G`。如果目录为“没有问题”(OK),且无需任何操作,那么是 `K`。如果有 Git 未知的文件需要添加或忽略,那么是 `!`。如果需要提交,那么是 `C`。如果没有上游,那么是 `U`。如果存在上游,但我没有推送,那么是 `P`。该方案不是基于当前状态,而是描述了我要做的*下一个动作*。(要回顾 Git 术语,请阅读[本文][8]。)
|
||||
|
||||
终端功能是通过一个有趣的 Python 程序完成的。它运行 `python -m howsit`(在我把 [howsit][9] 安装在虚拟环境中之后)。
|
||||
|
||||
你可以在上图中看到渲染效果,但是为了完整起见,这是我的 `PS1`:
|
||||
|
||||
```
|
||||
[$(~/.virtualenvs/howsit/bin/python -m howsit)]\h:\W \u ℵ₀
|
||||
$
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/7/tmux-git
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lenovo-thinkpad-laptop-window-focus.png?itok=g0xPm2kD (young woman working on a laptop)
|
||||
[2]: https://opensource.com/sites/default/files/uploads/terminal-tmux-moshezadka.png (Moshe Zadka's terminal)
|
||||
[3]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[4]: https://opensource.com/article/20/1/tmux-console
|
||||
[5]: https://simple.wikipedia.org/wiki/Aleph_null
|
||||
[6]: https://gizmodo.com/a-brief-introduction-to-infinity-5809689
|
||||
[7]: https://opensource.com/article/19/3/move-your-dotfiles-version-control
|
||||
[8]: https://opensource.com/article/19/2/git-terminology
|
||||
[9]: https://pypi.org/project/howsit/
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (JunJie957)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,168 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Program IoT systems using Python with this VSCode plugin for RTOS)
|
||||
[#]: via: (https://opensource.com/article/20/7/python-rt-thread)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Program IoT systems using Python with this VSCode plugin for RTOS
|
||||
======
|
||||
A real-time embedded OS like RTOS makes programming embedded systems
|
||||
easier.
|
||||
![Parts, modules, containers for software][1]
|
||||
|
||||
The pervasiveness of the Internet of Things (IoT) means nearly every product, from refrigerators to pocket watches, can connect to a network. For that to happen, all these products must have an embedded computer running a networking stack, and some of these products are almost impossibly small. That's where embedded software comes in: modern technology provides a tiny computer, hard-coded into a hardware chip, without any need for offboard CPU, RAM, or hard drive.
|
||||
|
||||
Traditionally, that meant there was no operating system (OS), but [for many reasons][2], developers find a real-time embedded OS like [RT-Thread][3] makes programming embedded systems much easier.
|
||||
|
||||
The RT-Thread embedded operating system aims to encourage new programmers to get into IoT, but not everyone can hard-code a microchip in C. Luckily, MicroPython is filling that niche by enabling developers to create software in Python that runs on embedded systems. To make it even easier, RT-Thread has a plugin for VSCode and [VSCodium][4] that provides a development environment developers can use to get started with IoT. Some of its features include:
|
||||
|
||||
* A convenient connection mode, so you can easily connect to your development board over a serial port, over the network, or over USB (if you've used an Arduino, you'll be familiar with the workflow)
|
||||
* Support for uploading files or folders to your development board
|
||||
* Support for MicroPython-based code, with intelligent code completion and linting (syntax checking)
|
||||
* Support for the MicroPython REPL interactive environment
|
||||
* Many code examples and demo programs
|
||||
* Full project synchronization
|
||||
* Fast-running code files stored in memory
|
||||
* Code snippets to run functions
|
||||
* Support for several major MicroPython development boards
|
||||
* Support for and tested on Linux and Windows
|
||||
|
||||
|
||||
|
||||
### Requirements
|
||||
|
||||
Before getting started, if you're using Windows, you must ensure that your default VSCode terminal is set to [PowerShell][5]. Launch VSCodium and start a terminal from the **Terminal** menu. In the terminal that appears at the bottom of your VSCodium window, select **PowerShell** from the drop-down menu in the top bar.
|
||||
|
||||
Whether you're [on Windows][6] or Linux, you must have Python 3 installed. (On Linux, it's probably already installed or available in your software repository.)
|
||||
|
||||
You should also install the general Python plugin for VSCode from Microsoft. To install it, click the **File** menu and find the **Preferences** submenu. Open the **Extensions** panel from the **Preferences** menu. In **Extensions**, search for Python, and install the Microsoft plugin.
|
||||
|
||||
![VSCodium Python plugin][7]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
Finally, you must have [VSCodium][9] or [VSCode][10] installed.
|
||||
|
||||
### Install the plugin
|
||||
|
||||
Installing the MicroPython development plugin follows the same process as installing the Python plugin. Click the **File** menu, find the **Preferences** submenu, and select **Extensions**.
|
||||
|
||||
In **Extensions**, search for **MicroPython**, and install the RT-Thread plugin.
|
||||
|
||||
![MicroPython plugin for RT-Thread][11]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
### Use the plugin
|
||||
|
||||
Your board must have access to a serial port, which it gets through your group permissions. You probably need to add yourself to this group, because it's not usually set by default. First, verify that you're not already a member of `dialout`:
|
||||
|
||||
|
||||
```
|
||||
$ groups
|
||||
tux users
|
||||
```
|
||||
|
||||
In this example, the user `tux` is only a member of `tux` and `users`, so it needs to be added to `dialout`:
|
||||
|
||||
|
||||
```
|
||||
`$ sudo usermod --append --groups dialout tux`
|
||||
```
|
||||
|
||||
Log out or reboot to load your new group permissions.
|
||||
|
||||
### Create a MicroPython project
|
||||
|
||||
The first step in MicroPython development is to create a MicroPython project to write and run your code. To create a MicroPython project using the plugin, click the **Create MicroPython project** button in the bottom bar (on the left).
|
||||
|
||||
![Create MicroPython project][12]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
This leads you through a few prompts, letting you choose either an empty project structure or a project containing example code.
|
||||
|
||||
### Connect your dev board
|
||||
|
||||
You can connect from VSCodium to your physical development board by clicking the **Connection** button in the lower-left corner of VSCodium. Select the device you want to connect to in the pop-up list of devices.
|
||||
|
||||
### Review sample code
|
||||
|
||||
The MicroPython plugin offers a lot of sample code and library files you can use and learn from. These are available from new icons, visible when the MicroPython plugin is active, in VSCodium's left button bar. The **Document** icon lists example code files, and the **Folder** icon lists example libraries.
|
||||
|
||||
![MicroPython examples][13]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
### Run MicroPython files directly on your development board
|
||||
|
||||
You can debug a single file quickly and easily by running code on your board within VSCodium. The shortcut **Alt**+**Q** triggers a special plugin function to upload your current Python file to the memory of your connected development board. Alternatively, you can right-click on your current Python file and select **Run the MicroPython file directly on the device**.
|
||||
|
||||
![Running code on your device][14]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
If you want to debug a small amount of code without loading files to your board, you can use the code-snippet function. To run selected code in the MicroPython REPL environment, select the snippet you want to run in the editor, and select **Execute the selected MicroPython code on the device** option from the right-click menu (or just press **Alt**+**Q** on your keyboard).
|
||||
|
||||
### Load files and folders to your dev board
|
||||
|
||||
If you want to load individual files or folders to your development board, there's a handy function for that. First, select the file or folder you want to upload in the project. Next, right-click on one of your selections and choose **Download the file/folder to the device**.
|
||||
|
||||
Note that if there are files or folders with the same name on the development board, the download overwrites the existing ones.
|
||||
|
||||
By entering the command `os.listdir()` in REPL, you can check whether the corresponding file or folder has been downloaded successfully. Similarly, you can also use the corresponding command to delete the file or folder in REPL.
|
||||
|
||||
To remove a file:
|
||||
|
||||
|
||||
```
|
||||
`os.remove('file_to_delete')`
|
||||
```
|
||||
|
||||
To remove a folder:
|
||||
|
||||
|
||||
```
|
||||
`os.rmdir('folder_to_delete')`
|
||||
```
|
||||
|
||||
### Project synchronization
|
||||
|
||||
Click the **Synchronization** button in the lower-left corner to start the project synchronization function. This feature synchronizes all directory files in the local project to the development board's filesystem. This feature is recommended to be used after the code is debugged, without the need to synchronize the project frequently during debugging.
|
||||
|
||||
After the project synchronization completes, the list of files in the device can be seen in the **Device Files List** column.
|
||||
|
||||
### Try it yourself
|
||||
|
||||
RT-Thread released the MicroPython plugin as an open source extension in hopes that it will be useful for new and experienced coders alike. It has many features and leverages others (like code completion and linting) from open source plugins. If you're interested in coding for embedded and IoT devices, there's no easier way to get started.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/7/python-rt-thread
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/containers_modules_networking_hardware_parts.png?itok=rPpVj92- (Parts, modules, containers for software)
|
||||
[2]: https://opensource.com/article/20/6/open-source-rtos
|
||||
[3]: https://www.rt-thread.io/
|
||||
[4]: https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
[5]: https://opensource.com/article/18/2/powershell-people
|
||||
[6]: https://opensource.com/article/19/8/how-install-python-windows
|
||||
[7]: https://opensource.com/sites/default/files/uploads/vscodium-python-plugin.jpg (VSCodium Python plugin)
|
||||
[8]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[9]: http://vscodium.com
|
||||
[10]: https://github.com/microsoft/vscode
|
||||
[11]: https://opensource.com/sites/default/files/uploads/vscodium-micropython.jpg (MicroPython plugin for RT-Thread)
|
||||
[12]: https://opensource.com/sites/default/files/uploads/vscodium-micropython-create.jpg (Create MicroPython project)
|
||||
[13]: https://opensource.com/sites/default/files/uploads/vscodium-micropython-examples.jpg (MicroPython examples)
|
||||
[14]: https://opensource.com/sites/default/files/uploads/vscodium-micropython-run.jpg (Running code on your device)
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (Yufei-Yan)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,68 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Customizing my Linux terminal with tmux and Git)
|
||||
[#]: via: (https://opensource.com/article/20/7/tmux-git)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
使用 tmux 和 Git 自定义我的 Linux 终端
|
||||
======
|
||||
设置你的控制台,以便你能知道你在哪里和接下来该做什么
|
||||
![woman on laptop sitting at the window][1]
|
||||
|
||||
我使用 GNOME Terminal,主要是因为它是我的发行版的默认设置。但是我终端内远非“默认值”。在开始自定义它之前,它是这个样子:
|
||||
|
||||
![Moshe Zadka's terminal][2]
|
||||
|
||||
(Moshe Zadka, [CC BY-SA 4.0][3])
|
||||
|
||||
### 从底部开始
|
||||
|
||||
我使用终端多路复用技术 [tmux][4] 管理我的终端体验。
|
||||
|
||||
在上图的底部,你可以看到我的绿色 tmux 栏。底部的 `[3]` 表示它是第三个终端:每个终端都运行自己的 tmux 会话。 (我创建了一个新会话来放大字体,这样可在截图中更容易看到;这是它与其他终端之间的唯一区别。)
|
||||
|
||||
提示看起来也很有趣,对吧?在提示中塞入了太多信息后,我想插在换行符中,这样一来,如果我想即兴 shell 编程或编写五步流水线,就可以不会溢出而做到这点。折衷方案是简单的命令序列(新建、复制、移动),可以更快地滚动到我的屏幕之外。
|
||||
|
||||
一行的最后是 [Aleph null][5],它是最小的[无限基数][6]。我喜欢它在一行的最后很明显,并且当我意识到 Aleph 和下标 0 都是 Unicode 字符时,我忍不住要使用 Aleph null 作为提示的一部分的诱惑。(数学呆子,团结起来!)
|
||||
|
||||
在此之前是我的用户名。由于我在不同用户名的多台计算机上使用相同的 [dotfiles][7](保存在 Git 中),因此这个非常有用。
|
||||
|
||||
用户名之前是我所在目录的最后一部分。完整路径通常太长且无用,但是当前目录对于像我这样的经常忘记在做什么人来说是很有用的。在此之前是机器的名称。我所有的机器都以我喜欢的电视节目命名。我的旧笔记本是 `mcgyver`。
|
||||
|
||||
提示中的第一位是我最喜欢的位:一个让我知道目录的 Git 状态的字母。如果目录为”不在 Git 中“,那么是 `G`。如果目录为“没有问题” (OK),且无需任何操作,那么是 `K`。如果有 Git 未知的文件需要添加或忽略,那么是 `!`。如果需要提交,那么是 `C`。如果没有上游,那么是 `U`。如果存在上游,但我没有推送,那么是 `P`。该方案不是基于当前状态,而是描述了我要做的_下一个动作_。 (要回顾 Git 术语,请阅读[本文][8]。)
|
||||
|
||||
终端功能是通过一个有趣的 Python 程序完成的。它运行 `python -m howsit`(在虚拟环境中安装 [howsit][9] 之后)。
|
||||
|
||||
你可以在上图中看到渲染,但是为了完整起见,这是我的 PS1:
|
||||
|
||||
|
||||
```
|
||||
[$(~/.virtualenvs/howsit/bin/python -m howsit)]\h:\W \u ℵ₀
|
||||
$
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/7/tmux-git
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lenovo-thinkpad-laptop-window-focus.png?itok=g0xPm2kD (young woman working on a laptop)
|
||||
[2]: https://opensource.com/sites/default/files/uploads/terminal-tmux-moshezadka.png (Moshe Zadka's terminal)
|
||||
[3]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[4]: https://opensource.com/article/20/1/tmux-console
|
||||
[5]: https://simple.wikipedia.org/wiki/Aleph_null#:~:text=Aleph%20null%20(also%20Aleph%20naught,series%20of%20infinite%20cardinal%20numbers.
|
||||
[6]: https://gizmodo.com/a-brief-introduction-to-infinity-5809689
|
||||
[7]: https://opensource.com/article/19/3/move-your-dotfiles-version-control
|
||||
[8]: https://opensource.com/article/19/2/git-terminology
|
||||
[9]: https://pypi.org/project/howsit/
|
@ -0,0 +1,167 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (silentdawn-zz)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Program IoT systems using Python with this VSCode plugin for RTOS)
|
||||
[#]: via: (https://opensource.com/article/20/7/python-rt-thread)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
使用 VSCode RTOS 插件为物联网系统编写 Python 程序
|
||||
======
|
||||
RTOS 之类的实时嵌入式操作系统使嵌入式系统的编程更简单
|
||||
|
||||
![Parts, modules, containers for software][1]
|
||||
|
||||
物联网( IoT )无处不在,它意味着几乎所有的产品,从冰箱到口袋手表,都可以连网。为了实现这个目标,每个产品都需要拥有一个嵌入式计算机来运行网络栈,有些产品几乎是小的不可思议。这就是嵌入式软件出现的场景:现代科技打造的非常小的计算机,硬编码到硬件芯片,不需要任何板外处理器、内存或者存储盘。
|
||||
|
||||
就传统视角而言,这种场景意味着没有操作系统可用,但是因为种种 [原因][2],开发者发现,类似于 RTOS 之类的实时嵌入式操作系统能让嵌入式系统的编程变得非常简单。
|
||||
|
||||
虽然RT-Thread 嵌入式操作系统致力于鼓励程序员新手进入物联网领域,但并非所有的人都具备使用 C 语言硬编码微芯片的能力。幸运的是,MicroPython 通过让开发者创建运行于嵌入式系统的 Python 代码的方式,逐渐填补了这个鸿沟。为了让整个过程更简单,RT-Thread 有一个可以用于 VSCode 和 [VSCodium][4] 的插件,为开发者提供了物联网方面的开发环境。其部分特性包括:
|
||||
|
||||
* 方便的连接方式,可以很容易的通过串口、网络或者 USB 连接到开发板(如果你使用过 Arduino,肯定会很熟悉这个流程)。
|
||||
* 支持上传文件或目录到开发板。
|
||||
* 支持基于 MicroPython 的代码,而且具有智能的代码补充、语法检查功能。
|
||||
* 支持 MicroPython REPL 交互式环境。
|
||||
* 丰富的示例代码和演示程序。
|
||||
* 完整的工程同步功能。
|
||||
* 快速运行内存中的程序代码。
|
||||
* 函数运行的代码片段。
|
||||
* 支持主流的 MicroPython 开发板。
|
||||
* 支持 Linux 和 Windows 操作系统,并经过充分测试。
|
||||
|
||||
|
||||
|
||||
### 准备
|
||||
|
||||
在开始之前,如果你使用的是 Windows 操作系统,那么必须保证 VSCode 的默认终端是 [PowerShell][5]。运行 VSCodium,从 **Terminal** 菜单项启动一个终端. 在显示在 VSCodium 窗口底部的终端界面,从下拉菜单顶端选择 **PowerShell**。
|
||||
不论你是在 [Windows][6] 还是 Linux 系统下工作,必须保证安装了 Python 3(在 Linux 上,它可能已经安装了,否则可以通过软件库安装它)。
|
||||
|
||||
还要安装的是微软提供的 VSCode Python插件。安装方法是点击 **File** 菜单,找到 **Preferences** 子菜单,从中打开 **Extensions** 面板。在 **Extensions** 中,搜索 Python,找到来自微软的 Python 插件。
|
||||
|
||||
![VSCodium Python plugin][7]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
当软,在上述操作之前,你要先正确安装 [VSCodium][9] 或 [VSCode][10]。
|
||||
|
||||
### 安装插件
|
||||
|
||||
安装 MicroPython 开发插件的方法与安装 Python 插件一样,点击 **File** 菜单,找到 **Preferences** 子菜单,选择 **Extensions**。
|
||||
|
||||
在 **Extensions** 中,搜索 **MicroPython**,安装 RT-Thread 插件。
|
||||
|
||||
![MicroPython plugin for RT-Thread][11]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
### 使用插件
|
||||
|
||||
你的开发板必须能访问串口,这需要组策略的允许。你可能需要将自己的账户加入该组,通常在默认情况下你的账户可能并不在该组。首先,确认你的账户不在 “dialout”组:
|
||||
|
||||
|
||||
```
|
||||
$ groups
|
||||
tux users
|
||||
```
|
||||
|
||||
本例中,用户“tux”只是“tux”组和“users”组的成员,所以需要将用户“tux”添加到“dialout”组:
|
||||
|
||||
|
||||
```
|
||||
$ sudo usermod --append --groups dialout tux
|
||||
```
|
||||
|
||||
Log out or reboot to load your new group permissions.
|
||||
|
||||
### 创建 MicroPython 工程
|
||||
|
||||
MicroPython 开发的第一步是创建 MicroPython 工程用来编写和运行代码。使用 MicroPython 插件创建工程的方法是,点击左下方的 **Create MicroPython project** 按钮。
|
||||
|
||||
![Create MicroPython project][12]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
之后会有一些提示,让你选择创建空白工程还是包含例程的工程。
|
||||
|
||||
### 连接到开发板
|
||||
|
||||
点击 VSCodium 左下方的 **Connection** 按钮,进行 VSCodium 与开发板的连接,在弹出的列表中,选择要连接的物理设备。
|
||||
|
||||
### 查看例程
|
||||
|
||||
MicroPython 插件提供了许多例程和例库,供学习和调用。获取例程的过程是,激活 MicroPython 之后,VSCodium 左侧按钮条会出现“新建”快捷图标,点击该图标就可以了。点击 **Document** 快捷图标,会显示例程文件列表,点击 **Folder** 快捷图标,会显示例库列表。
|
||||
|
||||
![MicroPython examples][13]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
### 直接在开发板上运行 MicroPython 文件
|
||||
|
||||
在 VSCodium 中可以通过在开发板上运行单个程序文件,很方便快捷的进行程序调试。快捷键 **Alt**+**Q** 会触发一个特定的插件,该插件会将当前的 Python 文件上传到开发板内存中。你还可以在当前 Python 文档界面点击右键,然后选择 **Run the MicroPython file directly on the device** 实现同样的功能。
|
||||
|
||||
![Running code on your device][14]
|
||||
|
||||
(Seth Kenlon, [CC BY-SA 4.0][8])
|
||||
|
||||
如果你需要以不上传代码的方式检查一组代码,可以使用“代码片段”功能。要运行 MicroPython REPL 环境中的代码片段,在编辑器中选中要运行的片段,右键菜单中点击 **Execute the selected MicroPython code on the device** (也可以使用 **Alt**+**Q** 快捷键)。
|
||||
|
||||
### 加载文件和目录到开发板
|
||||
|
||||
如果需要加载文件或目录到开发板,有现成的方法可用:选中工程中要加载到开发板的文件或目录,在选中的对象上右键,点击右键菜单中的 **Download the file/folder to the device**。
|
||||
|
||||
注意,如果开发板中已有与要加载的文件或目录同名者,加载操作将导致开发板原有的内容被覆盖。
|
||||
|
||||
在 REPL 环境中运行“os.listdir()”命令,可以检查文件和目录是否成功加载。当然,也可以通过相应的命令删除 REPL 中的文件或目录。
|
||||
|
||||
删除文件的命令如下:
|
||||
|
||||
|
||||
```
|
||||
os.remove('file_to_delete')
|
||||
```
|
||||
|
||||
删除目录的命令如下:
|
||||
|
||||
|
||||
```
|
||||
os.rmdir('folder_to_delete')
|
||||
```
|
||||
|
||||
### 工程的同步
|
||||
|
||||
点击左下角 **Synchronization** 按钮可以启动工程同步,该操作将把本地工程中所有的文件和目录同步到开发板的文件系统。建议在完成程序调试之后进行该操作,调试过程中不需要频繁进行同步操作。
|
||||
|
||||
工程的同步操作完成后,开发板上的文件列表可以在 **Device Files List** 列看到。
|
||||
|
||||
### 放手尝试
|
||||
|
||||
RT-Thread 以开源的方式发布 MicroPython 插件,意在为新老开发者提供帮助,它的很多特性,如代码自动补全等,与开源插件之间互有影响和促进。你如果想为嵌入式系统或物联网系统编写软件,这就是最简单的方式,没有之一。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/7/python-rt-thread
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[silentdawn-zz](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/containers_modules_networking_hardware_parts.png?itok=rPpVj92- (Parts, modules, containers for software)
|
||||
[2]: https://opensource.com/article/20/6/open-source-rtos
|
||||
[3]: https://www.rt-thread.io/
|
||||
[4]: https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
[5]: https://opensource.com/article/18/2/powershell-people
|
||||
[6]: https://opensource.com/article/19/8/how-install-python-windows
|
||||
[7]: https://opensource.com/sites/default/files/uploads/vscodium-python-plugin.jpg (VSCodium Python plugin)
|
||||
[8]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[9]: http://vscodium.com
|
||||
[10]: https://github.com/microsoft/vscode
|
||||
[11]: https://opensource.com/sites/default/files/uploads/vscodium-micropython.jpg (MicroPython plugin for RT-Thread)
|
||||
[12]: https://opensource.com/sites/default/files/uploads/vscodium-micropython-create.jpg (Create MicroPython project)
|
||||
[13]: https://opensource.com/sites/default/files/uploads/vscodium-micropython-examples.jpg (MicroPython examples)
|
||||
[14]: https://opensource.com/sites/default/files/uploads/vscodium-micropython-run.jpg (Running code on your device)
|
Loading…
Reference in New Issue
Block a user