diff --git a/configs/LZ-MobileNetV3_large_x1_0.yaml b/configs/LZ-MobileNetV3.yaml similarity index 100% rename from configs/LZ-MobileNetV3_large_x1_0.yaml rename to configs/LZ-MobileNetV3.yaml diff --git a/example/periphery/adc/python/test_adc.py b/example/periphery/adc/python/test_adc.py index 7a2d3f2fb509d2b34f195cab35e2be1beae7e3f6..7a04502858147b1c3a3a3e1785725d73ecb81e36 100644 --- a/example/periphery/adc/python/test_adc.py +++ b/example/periphery/adc/python/test_adc.py @@ -1,6 +1,5 @@ from lockzhiner_vision_module.periphery import ADCIN1 - if __name__ == "__main__": adc = ADCIN1() - print(f"adc_data is {adc.read()} mV") \ No newline at end of file + print(f"adc_data is {adc.read()} mV") diff --git a/example/periphery/capture/README.md b/example/periphery/capture/README.md index f8a5a5f2997785ddfabed41a06fa057c6a49a0a6..a1be3798eb53fc0544eb744623dbd6ece4d2191c 100644 --- a/example/periphery/capture/README.md +++ b/example/periphery/capture/README.md @@ -1,4 +1,4 @@ -

摄像头使用指南

+

凌智视觉模块摄像头使用指南

发布版本:V0.0.0 @@ -60,17 +60,21 @@ Lockzhiner Vision Module 上自带了一个摄像头,该摄像头可以支持 在开始这个章节前,请确保: - 你已经按照 [开发环境搭建指南](../../../docs/introductory_tutorial/development_environment.md) 正确配置了开发环境。 -- 点击 [Lockzhiner Vision Module 图片获取助手下载地址](https://gitee.com/LockzhinerAI/LockzhinerVisionModule/releases/download/v0.0.0/LockzhinerVisionModuleImageFetcher_v0.0.0.exe) 下载 Lockzhiner Vision Module 图片获取助手。 +- 点击 [凌智视觉模块图片传输助手下载地址](https://gitee.com/LockzhinerAI/LockzhinerVisionModule/releases/download/v0.0.0/LockzhinerVisionModuleImageFetcher_v0.0.0.exe) 下载凌智视觉模块图片传输助手。 ## 4 API 文档 -关于摄像头读取,请参考传统的 OpenCV 摄像头 API 来实现,需要注意的是: +### 4.1 读取摄像头文档 + +凌智视觉模块使用 opencv-mobile 来读取摄像头数据。关于摄像头读取,请参考传统的 OpenCV 摄像头 API 来实现,需要注意的是: - 受限于运行内存,请使用我们编译的 [OpenCV Mobile](https://gitee.com/LockzhinerAI/opencv-mobile) 库来代替传统的 OpenCV 库 - LockzhinerVisionModule 只有一个摄像头,因此在打开摄像头时,不管输入什么参数,都只会打开这个摄像头 - 配置摄像头长宽时,请保证长和宽都是 8 的倍数 -关于 Lockzhiner Vision Module 中的图片获取 API,请参考以下文档: +### 4.2 传输摄像头数据文档 + +为了让大家直观的看到摄像头获取的数据,我们编写了凌智视觉模块图片传输助手。关于 Lockzhiner Vision Module 中的图片发送 API,请参考以下文档: ```cpp /** diff --git a/example/periphery/gpio/python/test_gpio_read.py b/example/periphery/gpio/python/test_gpio_read.py index 7160507ee6f345c7f41f238908124a0282b57fe1..ca6812d2ecaba1a92967981e6aa66680cf7b3ddf 100644 --- a/example/periphery/gpio/python/test_gpio_read.py +++ b/example/periphery/gpio/python/test_gpio_read.py @@ -2,16 +2,17 @@ from lockzhiner_vision_module.periphery import GPIO0A0 from lockzhiner_vision_module.periphery import GPIOMode from lockzhiner_vision_module.periphery import GPIOState + if __name__ == "__main__": gpio = GPIO0A0() - + if gpio.config(GPIOMode.IN) is False: print("Failed to config gpio mode") exit(1) - + state = gpio.read() if state == GPIOState.ERROR: print("Failed to read gpio mode") exit(1) - - print(f"state is {state}") \ No newline at end of file + + print(f"state is {state}") diff --git a/example/periphery/gpio/python/test_gpio_write.py b/example/periphery/gpio/python/test_gpio_write.py index 3faf1912da3280c724d311a9626e9f5dba33cd4c..1bfcc8d8c60a7dfda1d459fb64280b60e43d7336 100644 --- a/example/periphery/gpio/python/test_gpio_write.py +++ b/example/periphery/gpio/python/test_gpio_write.py @@ -1,27 +1,26 @@ from lockzhiner_vision_module.periphery import GPIO0A0 from lockzhiner_vision_module.periphery import GPIOMode from lockzhiner_vision_module.periphery import GPIOState - import time if __name__ == "__main__": gpio = GPIO0A0() - + if gpio.config(GPIOMode.OUT) is False: print("Failed to config gpio mode") exit(1) - + if gpio.write(GPIOState.HIGH) is False: print("Failed to write gpio state") exit(1) - + time_index = 0 total_time = 10 while time_index < total_time: print(f"Wait: {time_index}/{total_time}") time_index += 1 time.sleep(1) - + if gpio.write(GPIOState.LOW) is False: print("Failed to write gpio state") - exit(1) \ No newline at end of file + exit(1) diff --git a/example/periphery/usart/README.md b/example/periphery/usart/README.md index 1c4a51e1d2de2895ebd764ce0a5e3da1d36e98db..bd0f7e7e06e730b2a5a7eda402c3ea049a2257d4 100644 --- a/example/periphery/usart/README.md +++ b/example/periphery/usart/README.md @@ -1,8 +1,8 @@ -

串口使用指南

+

凌智视觉模块串口使用指南

-发布版本:V0.0.2 +发布版本:V0.0.0 -日期:2024-08-30 +日期:2024-09-21 文件密级:□绝密 □秘密 □内部资料 ■公开 @@ -25,177 +25,15 @@ | **日期** | **版本** | **作者** | **修改说明** | | :--------- | -------- | -------- | ------------ | -| 2024/08/29 | 0.0.0 | 郑必城 | 初始版本 | -| 2024/08/29 | 0.0.1 | 郑必城 | 修补缺失的内容 | -| 2024/08/30 | 0.0.2 | 郑必城 | 更新到最新的 串口 SDK | +| 2024/09/21 | 0.0.0 | 郑必城 | 初始版本 | ## 1 简介 串口,也称为串行接口或串行通信接口,是一种用于连接计算机与外部设备并进行数据传输的接口技术。它使用较少的导线(通常只需要几根线),并且可以在较长的距离上可靠地传输数据,尽管速度相对较慢。本章节中,我们将教会你如何使用 Lockzhiner Vision Module 上的串口进行传输数据。 -## 2 前期准备 -在开始这个章节前,请确保你已经按照 [开发环境搭建指南](../../../docs/introductory_tutorial/development_environment.md) 正确配置了开发环境。 - -## 3 API 文档 - -```c++ -/// \class USART -/// \brief 串口控制类,用于串口通信的数据发送和接收。 -/// -/// 该类封装了串口的基本操作,包括打开串口、关闭串口、发送数据和接收数据。 -class USART { - public: - USART() = default; - ~USART(); - - /// \brief 打开串口。 - /// - /// \param baud_rate 波特率,用于设置串口通信速率,默认为 115200。 - /// \return 成功打开串口返回 true,否则返回 false。 - bool Open(uint32_t baud_rate = 115200); - - /// \brief 关闭串口。 - /// - /// \return 成功关闭串口返回 true,否则返回 false。 - bool Close(); - - /// \brief 发送数据。 - /// - /// \param data 要发送的数据字符串。 - /// \return 成功发送数据返回 true,否则返回 false。 - bool Write(const std::string& data); - - /// \brief 接收数据。 - /// - /// \param buffer 用于存储接收到的数据的缓冲区。 - /// \param size 缓冲区的大小。 - /// \return 成功接收数据返回 true,否则返回 false。 - bool Read(std::string& buffer, size_t size); - - private: - int serial_port_ = -1; - uint32_t GetBaudRate(int baud_rate); -}; -``` - -## 3 项目介绍 - -为了方便大家入手,我们将项目拆分为串口接受数据和串口发送数据两个部分,他们共用一个 CMake 文件。 - -```cmake -# CMake最低版本要求 -cmake_minimum_required(VERSION 3.10) - -project(test_usart) - -# 定义项目根目录路径 -set(PROJECT_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../..") -# 定义 LockzhinerVisionModule SDK 路径 -set(LockzhinerVisionModule_ROOT_PATH "${PROJECT_ROOT_PATH}/third_party/lockzhiner_vision_module_sdk") -set(LockzhinerVisionModule_DIR "${LockzhinerVisionModule_ROOT_PATH}/lib/cmake/lockzhiner_vision_module") -find_package(LockzhinerVisionModule REQUIRED) - -# 配置串口输出 Demo -add_executable(Test-USART-Write test_usart_write.cc) -target_include_directories(Test-USART-Write PRIVATE ${LOCKZHINER_VISION_MODULE_INCLUDE_DIRS}) -target_link_libraries(Test-USART-Write PRIVATE ${LOCKZHINER_VISION_MODULE_LIBRARIES}) - -# 配置串口读取 Demo -add_executable(Test-USART-Read test_usart_read.cc) -target_include_directories(Test-USART-Read PRIVATE ${LOCKZHINER_VISION_MODULE_INCLUDE_DIRS}) -target_link_libraries(Test-USART-Read PRIVATE ${LOCKZHINER_VISION_MODULE_LIBRARIES}) -``` - -串口接受数据的核心代码如下: - -```cpp -#include // 串口类头文件 - -#include // 引入标准输入输出流库 - -int main() { - // 创建串口类对象 - lockzhiner_vision_module::periphery::USART usart; - - // 尝试以115200的波特率打开串口 - if (!usart.Open(115200)) { - // 如果打开失败,则输出错误信息并返回1 - std::cout << "Failed to open usart." << std::endl; - return 1; - } - - // 输出开始接收串口数据的提示信息 - std::cout << "Start receiving serial port data." << std::endl; - - // 无限循环,持续接收串口数据 - while (1) { - std::string buffer; // 用于存储接收到的串口数据 - // 从串口读取数据到buffer中,最多读取1024字节 - usart.Read(buffer, 1024); - // 如果buffer不为空,则输出接收到的数据 - if (!buffer.empty()) { - std::cout << buffer << std::endl; - } - } - return 0; -} -``` - -串口发送数据的核心代码如下: - -```cpp -#include // 引入串口类头文件 - -#include // 引入标准输入输出流库 - -int main() { - // 创建串口类对象 - lockzhiner_vision_module::periphery::USART usart; - - // 尝试以115200的波特率打开串口 - if (!usart.Open(115200)) { - // 如果打开失败,则输出错误信息并返回1 - std::cout << "Failed to open usart." << std::endl; - return 1; - } - - // 尝试发送字符串"Hello World\n" - if (!usart.Write("Hello World\n")) { - // 如果发送失败,则输出错误信息 - std::cout << "Failed to send data." << std::endl; - } - return 0; -} -``` - -## 4 编译项目 - -使用 Docker Destop 打开 LockzhinerVisionModule 容器并执行以下命令来编译项目 - -```bash -# 进入 Demo 目录 -cd /LockzhinerVisionModuleWorkSpace/LockzhinerVisionModule/example/periphery/usart - -# 创建编译目录 -rm -rf build && mkdir build && cd build - -# 配置交叉编译工具链 -export TOOLCHAIN_ROOT_PATH=${PWD}/../../../../../arm-rockchip830-linux-uclibcgnueabihf - -# 使用 cmake 配置项目 -cmake -DCMAKE_TOOLCHAIN_FILE=../../../../toolchains/arm-rockchip830-linux-uclibcgnueabihf.toolchain.cmake \ - -DCMAKE_BUILD_TYPE=Release \ - .. - -# 执行编译 -make -j8 -``` - -![](images/build_example.png) - -## 5 正确连接设备 +## 2 正确连接设备 为了方便调试,我们这里使用 **CH340 USB 转串口模块(以下简称 CH340)**进行调试,请正确的将模型的引脚按照以下方式连接 @@ -205,53 +43,13 @@ make -j8 > Lockzhiner 也提供官方的 [CH340 USB 转串口模块](http://e.tb.cn/h.gMbjEDBRiaOutkO?tk=kBlS35jFQOE),如果有需要可以前往购买。 -## 6 执行串口测试程序 - -参考 [连接设备指南](../../../docs/introductory_tutorial/connect_device_using_ssh.md) 正确连接 Lockzhiner Vision Module 设备。 - -![](../../../docs/introductory_tutorial/images/connect_device_using_ssh/ssh_success.png) - -使用 SFTP 功能将软件上传到 Lockzhiner Vision Module - -![](images/sftp.png) - 打开串口工具,我这里选择的是 [vofa+](https://www.vofa.plus/),配置波特率为 115200 并打开串口 ![](images/vofa.png) -### 6.1 测试串口发送程序 - -在 Lockzhiner Vision Module 上运行以下代码来执行串口发送程序 - -```bash -export LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH -chmod +x ./Test-USART-Write -./Test-USART-Write -``` - -![](images/usart_wirte_electerm.png) - -vofa+ 上显示发送的字符串(Hello World) - -![](images/usart_write_voft.png) - -### 6.2 测试串口接收程序 - -在 Lockzhiner Vision Module 上运行以下代码来执行串口接收程序 - -```bash -export LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH -chmod +x ./Test-USART-Read -./Test-USART-Read -``` - -![](images/usart_send_wait_electerm.png) - - -vofa+ 点击发送字符串(Hello World) - -![](images/usart_send_voft.png) +## 3 在凌智视觉模块上部署串口例程 -Lockzhiner Vision Module 打印接受到的字符串(Hello World) +请参考以下教程使用 C++ 或 Python 在凌智视觉模块上部署串口例程: -![](images/usart_send_show_electerm.png) \ No newline at end of file +- [凌智视觉模块串口 C++ 部署指南](./cpp/README.md) +- [凌智视觉模块串口 Python 部署指南](./python/README.md) \ No newline at end of file diff --git a/example/periphery/usart/CMakeLists.txt b/example/periphery/usart/cpp/CMakeLists.txt similarity index 93% rename from example/periphery/usart/CMakeLists.txt rename to example/periphery/usart/cpp/CMakeLists.txt index 8b74045729ec95fb1f8b5108113a53f33932e609..7b047c6540d1493541692f67ee9eeac595393fe0 100644 --- a/example/periphery/usart/CMakeLists.txt +++ b/example/periphery/usart/cpp/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.10) project(test_usart) # 定义项目根目录路径 -set(PROJECT_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../..") +set(PROJECT_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../..") # 定义 LockzhinerVisionModule SDK 路径 set(LockzhinerVisionModule_ROOT_PATH "${PROJECT_ROOT_PATH}/third_party/lockzhiner_vision_module_sdk") set(LockzhinerVisionModule_DIR "${LockzhinerVisionModule_ROOT_PATH}/lib/cmake/lockzhiner_vision_module") diff --git a/example/periphery/usart/cpp/README.md b/example/periphery/usart/cpp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..17a7b9192da37fbe481fd559dcdaba2a45358c9a --- /dev/null +++ b/example/periphery/usart/cpp/README.md @@ -0,0 +1,244 @@ +

凌智视觉模块串口 C++ 部署指南

+ +发布版本:V0.0.0 + +日期:2024-09-21 + +文件密级:□绝密 □秘密 □内部资料 ■公开 + +--- + +**免责声明** + +本文档按**现状**提供,福州凌睿智捷电子有限公司(以下简称**本公司**)不对本文档中的任何陈述、信息和内容的准确性、可靠性、完整性、适销性、适用性及非侵权性提供任何明示或暗示的声明或保证。本文档仅作为使用指导的参考。 + +由于产品版本升级或其他原因,本文档可能在未经任何通知的情况下不定期更新或修改。 + +**读者对象** + +本教程适用于以下工程师: + +- 技术支持工程师 +- 软件开发工程师 + +**修订记录** + +| **日期** | **版本** | **作者** | **修改说明** | +| :--------- | -------- | -------- | ------------ | +| 2024/09/21 | 0.0.0 | 郑必城 | 初始版本 | + + +## 1 简介 + +串口,也称为串行接口或串行通信接口,是一种用于连接计算机与外部设备并进行数据传输的接口技术。它使用较少的导线(通常只需要几根线),并且可以在较长的距离上可靠地传输数据,尽管速度相对较慢。本章节中,我们将教会你如何使用 Lockzhiner Vision Module 上的串口进行传输数据。 + +## 2 前期准备 + +接下来让我们基于串口来部署 GPIO 例程。在开始本章节前: + +- 在开始这个章节前,请确保你已经按照 [开发环境搭建指南](../../../../docs/introductory_tutorial/cpp_development_environment.md) 正确配置了开发环境。 +- 请确保你已经按照 [凌智视觉模块 GPIO 使用指南](../README.md) 正确将信号连接到开发板并打开了串口工具。 + +## 3 API 文档 + +```c++ +/// \class USART +/// \brief 串口控制类,用于串口通信的数据发送和接收。 +/// +/// 该类封装了串口的基本操作,包括打开串口、关闭串口、发送数据和接收数据。 +class USART { + public: + USART() = default; + ~USART(); + + /// \brief 打开串口。 + /// + /// \param baud_rate 波特率,用于设置串口通信速率,默认为 115200。 + /// \return 成功打开串口返回 true,否则返回 false。 + bool Open(uint32_t baud_rate = 115200); + + /// \brief 关闭串口。 + /// + /// \return 成功关闭串口返回 true,否则返回 false。 + bool Close(); + + /// \brief 发送数据。 + /// + /// \param data 要发送的数据字符串。 + /// \return 成功发送数据返回 true,否则返回 false。 + bool Write(const std::string& data); + + /// \brief 接收数据。 + /// + /// \param buffer 用于存储接收到的数据的缓冲区。 + /// \param size 缓冲区的大小。 + /// \return 成功接收数据返回 true,否则返回 false。 + bool Read(std::string& buffer, size_t size); + + private: + int serial_port_ = -1; + uint32_t GetBaudRate(int baud_rate); +}; +``` + +## 4 项目介绍 + +为了方便大家入手,我们将项目拆分为串口接受数据和串口发送数据两个例程,他们共用一个 CMake 文件。 + +```cmake +# CMake最低版本要求 +cmake_minimum_required(VERSION 3.10) + +project(test_usart) + +# 定义项目根目录路径 +set(PROJECT_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../..") +# 定义 LockzhinerVisionModule SDK 路径 +set(LockzhinerVisionModule_ROOT_PATH "${PROJECT_ROOT_PATH}/third_party/lockzhiner_vision_module_sdk") +set(LockzhinerVisionModule_DIR "${LockzhinerVisionModule_ROOT_PATH}/lib/cmake/lockzhiner_vision_module") +find_package(LockzhinerVisionModule REQUIRED) + +# 配置串口输出 Demo +add_executable(Test-USART-Write test_usart_write.cc) +target_include_directories(Test-USART-Write PRIVATE ${LOCKZHINER_VISION_MODULE_INCLUDE_DIRS}) +target_link_libraries(Test-USART-Write PRIVATE ${LOCKZHINER_VISION_MODULE_LIBRARIES}) + +# 配置串口读取 Demo +add_executable(Test-USART-Read test_usart_read.cc) +target_include_directories(Test-USART-Read PRIVATE ${LOCKZHINER_VISION_MODULE_INCLUDE_DIRS}) +target_link_libraries(Test-USART-Read PRIVATE ${LOCKZHINER_VISION_MODULE_LIBRARIES}) +``` + +串口接受例程的核心代码如下: + +```cpp +#include // 串口类头文件 + +#include // 引入标准输入输出流库 + +int main() { + // 创建串口类对象 + lockzhiner_vision_module::periphery::USART usart; + + // 尝试以115200的波特率打开串口 + if (!usart.Open(115200)) { + // 如果打开失败,则输出错误信息并返回1 + std::cout << "Failed to open usart." << std::endl; + return 1; + } + + // 输出开始接收串口数据的提示信息 + std::cout << "Start receiving serial port data." << std::endl; + + // 无限循环,持续接收串口数据 + while (1) { + std::string buffer; // 用于存储接收到的串口数据 + // 从串口读取数据到buffer中,最多读取1024字节 + usart.Read(buffer, 1024); + // 如果buffer不为空,则输出接收到的数据 + if (!buffer.empty()) { + std::cout << buffer << std::endl; + } + } + return 0; +} +``` + +串口发送例程的核心代码如下: + +```cpp +#include // 引入串口类头文件 + +#include // 引入标准输入输出流库 + +int main() { + // 创建串口类对象 + lockzhiner_vision_module::periphery::USART usart; + + // 尝试以115200的波特率打开串口 + if (!usart.Open(115200)) { + // 如果打开失败,则输出错误信息并返回1 + std::cout << "Failed to open usart." << std::endl; + return 1; + } + + // 尝试发送字符串"Hello World\n" + if (!usart.Write("Hello World\n")) { + // 如果发送失败,则输出错误信息 + std::cout << "Failed to send data." << std::endl; + } + return 0; +} +``` + +## 5 编译项目 + +使用 Docker Destop 打开 LockzhinerVisionModule 容器并执行以下命令来编译项目 + +```bash +# 进入 Demo 目录 +cd /LockzhinerVisionModuleWorkSpace/LockzhinerVisionModule/example/periphery/cpp/usart + +# 创建编译目录 +rm -rf build && mkdir build && cd build + +# 配置交叉编译工具链 +export TOOLCHAIN_ROOT_PATH=${PWD}/../../../../../arm-rockchip830-linux-uclibcgnueabihf + +# 使用 cmake 配置项目 +cmake -DCMAKE_TOOLCHAIN_FILE=../../../../toolchains/arm-rockchip830-linux-uclibcgnueabihf.toolchain.cmake \ + -DCMAKE_BUILD_TYPE=Release \ + .. + +# 执行编译 +make -j8 +``` + +![](images/build_example.png) + +## 6 执行串口测试程序 + +参考 [连接设备指南](../../../../docs/introductory_tutorial/connect_device_using_ssh.md) 正确连接 Lockzhiner Vision Module 设备。 + +![](../../../../docs/introductory_tutorial/images/connect_device_using_ssh/ssh_success.png) + +使用 SFTP 功能将软件上传到 Lockzhiner Vision Module + +![](images/sftp.png) + +### 6.1 测试串口发送例程 + +在 Lockzhiner Vision Module 上运行以下代码来执行串口发送程序 + +```bash +export LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH +chmod +x ./Test-USART-Write +./Test-USART-Write +``` + +![](images/usart_wirte_electerm.png) + +vofa+ 上显示发送的字符串(Hello World) + +![](../images/usart_write_voft.png) + +### 6.2 测试串口接收例程 + +在 Lockzhiner Vision Module 上运行以下代码来执行串口接收程序 + +```bash +export LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH +chmod +x ./Test-USART-Read +./Test-USART-Read +``` + +![](images/usart_send_wait_electerm.png) + + +vofa+ 点击发送字符串(Hello World) + +![](../images/usart_send_voft.png) + +Lockzhiner Vision Module 打印接受到的字符串(Hello World) + +![](images/usart_send_show_electerm.png) \ No newline at end of file diff --git a/example/periphery/usart/images/build_example.png b/example/periphery/usart/cpp/images/build_example.png similarity index 100% rename from example/periphery/usart/images/build_example.png rename to example/periphery/usart/cpp/images/build_example.png diff --git a/example/periphery/usart/images/sftp.png b/example/periphery/usart/cpp/images/sftp.png similarity index 100% rename from example/periphery/usart/images/sftp.png rename to example/periphery/usart/cpp/images/sftp.png diff --git a/example/periphery/usart/images/usart_send_show_electerm.png b/example/periphery/usart/cpp/images/usart_send_show_electerm.png similarity index 100% rename from example/periphery/usart/images/usart_send_show_electerm.png rename to example/periphery/usart/cpp/images/usart_send_show_electerm.png diff --git a/example/periphery/usart/images/usart_send_wait_electerm.png b/example/periphery/usart/cpp/images/usart_send_wait_electerm.png similarity index 100% rename from example/periphery/usart/images/usart_send_wait_electerm.png rename to example/periphery/usart/cpp/images/usart_send_wait_electerm.png diff --git a/example/periphery/usart/images/usart_wirte_electerm.png b/example/periphery/usart/cpp/images/usart_wirte_electerm.png similarity index 100% rename from example/periphery/usart/images/usart_wirte_electerm.png rename to example/periphery/usart/cpp/images/usart_wirte_electerm.png diff --git a/example/periphery/usart/test_usart_read.cc b/example/periphery/usart/cpp/test_usart_read.cc similarity index 100% rename from example/periphery/usart/test_usart_read.cc rename to example/periphery/usart/cpp/test_usart_read.cc diff --git a/example/periphery/usart/test_usart_write.cc b/example/periphery/usart/cpp/test_usart_write.cc similarity index 100% rename from example/periphery/usart/test_usart_write.cc rename to example/periphery/usart/cpp/test_usart_write.cc diff --git a/example/periphery/usart/python/README.md b/example/periphery/usart/python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ea70cafd406bd3cb374b486bea0bfbc17494762b --- /dev/null +++ b/example/periphery/usart/python/README.md @@ -0,0 +1,178 @@ +

凌智视觉模块串口 Python 部署指南

+ +发布版本:V0.0.0 + +日期:2024-09-21 + +文件密级:□绝密 □秘密 □内部资料 ■公开 + +--- + +**免责声明** + +本文档按**现状**提供,福州凌睿智捷电子有限公司(以下简称**本公司**)不对本文档中的任何陈述、信息和内容的准确性、可靠性、完整性、适销性、适用性及非侵权性提供任何明示或暗示的声明或保证。本文档仅作为使用指导的参考。 + +由于产品版本升级或其他原因,本文档可能在未经任何通知的情况下不定期更新或修改。 + +**读者对象** + +本教程适用于以下工程师: + +- 技术支持工程师 +- 软件开发工程师 + +**修订记录** + +| **日期** | **版本** | **作者** | **修改说明** | +| :--------- | -------- | -------- | ------------ | +| 2024/09/21 | 0.0.0 | 郑必城 | 初始版本 | + + +## 1 简介 + +串口,也称为串行接口或串行通信接口,是一种用于连接计算机与外部设备并进行数据传输的接口技术。它使用较少的导线(通常只需要几根线),并且可以在较长的距离上可靠地传输数据,尽管速度相对较慢。本章节中,我们将教会你如何使用 Lockzhiner Vision Module 上的串口进行传输数据。 + +## 2 前期准备 + +接下来让我们基于串口来部署 GPIO 例程。在开始本章节前: + +- 在开始这个章节前,请确保你已经按照 [开发环境搭建指南](../../../../docs/introductory_tutorial/python_development_environment.md) 正确配置了开发环境。 +- 请确保你已经按照 [凌智视觉模块 GPIO 使用指南](../README.md) 正确将信号连接到开发板并打开了串口工具。 + +## 3 API 文档 + +```python +class USARTBase: + """ + @class USARTBase + @brief USART 基础类,用于管理 USART (串行通信)模块的初始化和基本操作。 + + 此类提供了一个接口来打开、关闭、写入和读取USART模块。它依赖于一个具体的USART类实例来实现这些操作。 + """ + + def __init__(self, usart_class): + """ + @fn __init__(self, usart_class) + @brief 构造函数,初始化 USARTBase 对象。 + + @param usart_class 一个 USART 类,用于实际的 USART 模块操作。 + """ + self.usart = usart_class() + + def open(self, baud_rate=115200): + """ + @fn open(self, baud_rate=115200) + @brief 打开 USART 模块,设置波特率。 + + @param baud_rate 波特率,默认为 115200。 + + @return 打开操作的结果,通常由具体的 USART 类决定。 + """ + return self.usart.open(baud_rate) + + def close(self): + """ + @fn close(self) + @brief 关闭 USART 模块。 + + @return 关闭操作的结果,通常由具体的 USART 类决定。 + """ + return self.usart.close() + + def write(self, data): + """ + @fn write(self, data) + @brief 向 USART 模块写入数据。 + + @param data 要写入的数据。 + + @return 写入操作的结果,通常由具体的 USART 类决定。 + """ + return self.usart.write(data) + + def read(self, data_size): + """ + @fn read(self, data_size) + @brief 从 USART 模块读取数据。 + + @param data_size 要读取的数据大小。 + + @return 读取到的数据,通常由具体的 USART 类决定。 + """ + return self.usart.read(data_size) +``` + +## 4 项目介绍 + +为了方便大家入手,我们将项目拆分为串口接受数据和串口发送数据两个部分。 + +串口接受例程的核心代码如下: + +```python +from lockzhiner_vision_module.periphery import USART1 + + +if __name__ == "__main__": + usart = USART1() + if usart.open(115200) is False: + print("Failed to open usart.") + exit(1) + + print("Start receiving serial port data.") + + while True: + print(usart.read(1024)) +``` + +串口发送例程的核心代码如下: + +```python +from lockzhiner_vision_module.periphery import USART1 + + +if __name__ == "__main__": + usart = USART1() + if usart.open(115200) is False: + print("Failed to open usart.") + exit(1) + + if usart.write("Hello World") is False: + print("Failed to send data.") + exit(0) +``` + +## 5 执行串口测试程序 + +参考 [连接设备指南](../../../../docs/introductory_tutorial/connect_device_using_ssh.md) 正确连接 Lockzhiner Vision Module 设备。 + +![](../../../../docs/introductory_tutorial/images/connect_device_using_ssh/ssh_success.png) + +使用 SFTP 功能将软件上传到 Lockzhiner Vision Module + +![](images/sftp.png) + +### 5.1 测试串口发送例程 + +```bash +python test_usart_write.py +``` + +![](images/usart_wirte_electerm.png) + +vofa+ 上显示发送的字符串(Hello World) + +![](../images/usart_write_voft.png) + +### 5.2 测试串口接收例程 + +```bash +python test_usart_read.py +``` + +vofa+ 点击发送字符串(Hello World) + +![](../images/usart_send_voft.png) + +Lockzhiner Vision Module 打印接受到的字符串(Hello World) + +![](images/usart_send_show_electerm.png) \ No newline at end of file diff --git a/example/periphery/usart/python/images/sftp.png b/example/periphery/usart/python/images/sftp.png new file mode 100644 index 0000000000000000000000000000000000000000..7090c6f245fce7d4c695eb8d05dd0ba4e949d423 Binary files /dev/null and b/example/periphery/usart/python/images/sftp.png differ diff --git a/example/periphery/usart/python/images/usart_send_show_electerm.png b/example/periphery/usart/python/images/usart_send_show_electerm.png new file mode 100644 index 0000000000000000000000000000000000000000..b039b467eb99e295027745d5728eda0eb271a70c Binary files /dev/null and b/example/periphery/usart/python/images/usart_send_show_electerm.png differ diff --git a/example/periphery/usart/python/images/usart_wirte_electerm.png b/example/periphery/usart/python/images/usart_wirte_electerm.png new file mode 100644 index 0000000000000000000000000000000000000000..6552563d41c76f5467522c034b1345f2f4444a71 Binary files /dev/null and b/example/periphery/usart/python/images/usart_wirte_electerm.png differ diff --git a/example/periphery/usart/python/test_usart_read.py b/example/periphery/usart/python/test_usart_read.py new file mode 100644 index 0000000000000000000000000000000000000000..d80c972d6b89a426436dd1fc9ff8d25a36f614fa --- /dev/null +++ b/example/periphery/usart/python/test_usart_read.py @@ -0,0 +1,13 @@ +from lockzhiner_vision_module.periphery import USART1 + + +if __name__ == "__main__": + usart = USART1() + if usart.open(115200) is False: + print("Failed to open usart.") + exit(1) + + print("Start receiving serial port data.") + + while True: + print(usart.read(1024)) diff --git a/example/periphery/usart/python/test_usart_write.py b/example/periphery/usart/python/test_usart_write.py new file mode 100644 index 0000000000000000000000000000000000000000..cc5905c5362e8bf475471eeccbac95e767c43d02 --- /dev/null +++ b/example/periphery/usart/python/test_usart_write.py @@ -0,0 +1,12 @@ +from lockzhiner_vision_module.periphery import USART1 + + +if __name__ == "__main__": + usart = USART1() + if usart.open(115200) is False: + print("Failed to open usart.") + exit(1) + + if usart.write("Hello World") is False: + print("Failed to send data.") + exit(0) diff --git a/example/vision/classification/cpp/README.md b/example/vision/classification/cpp/README.md index fdbfdbb79e51658f26fe2d47684d8e65cd5f0e5f..1b0ca794a63d4e993333f223b23462a953b5384f 100644 --- a/example/vision/classification/cpp/README.md +++ b/example/vision/classification/cpp/README.md @@ -292,9 +292,9 @@ make -j8 ```bash chmod +x ./Test-PaddleClas # ./Test-PaddleClas 模型路径 FPS -> 测试模型运行 FPS -./Test-PaddleClas ./LZ-MobileNetV2_x0_25.rknn FPS +./Test-PaddleClas ./LZ-MobileNetV3.rknn FPS # ./Test-PaddleClas 模型路径 Capture -> 测试摄像头获取数据时的模型运行 FPS -./Test-PaddleClas ./LZ-MobileNetV2_x0_25.rknn Capture +./Test-PaddleClas ./LZ-MobileNetV3.rknn Capture ``` 程序将读取摄像头数据,使用神经网络检测后输出置信度和类别: diff --git a/example/vision/classification/python/README.md b/example/vision/classification/python/README.md index eb83aa3b8a3917ce95a8cc261ed7b080f23029e8..708452d4333dcd50864dbc884e6a1cf2441195b4 100644 --- a/example/vision/classification/python/README.md +++ b/example/vision/classification/python/README.md @@ -169,7 +169,7 @@ if __name__ == "__main__": 请使用 Electerm Ssh 并在命令行中执行以下命令: ```bash -python test_paddleclas.py +python test_paddleclas.py LZ-MobileNetV3.rknn ``` 运行程序后,屏幕上开始打印标签索引,分类置信度,并在一段时间后输出 FPS 值 diff --git a/example/vision/classification/python/test_paddleclas.py b/example/vision/classification/python/test_paddleclas.py index 25dc77f2fe7c369a4f8a56a4d07cd2988d2f76a8..c24bf9063d414d06e145a6a6c91859499bbc9cd7 100644 --- a/example/vision/classification/python/test_paddleclas.py +++ b/example/vision/classification/python/test_paddleclas.py @@ -1,10 +1,16 @@ from lockzhiner_vision_module.cv2 import VideoCapture from lockzhiner_vision_module.vision import PaddleClas import time +import sys if __name__ == "__main__": + args = sys.argv + if len(args) != 2: + print("Need model path. Example: python test_paddleclas.py LZ-MobileNetV3.rknn") + exit(1) + model = PaddleClas() - if model.initialize("LZ-MobileNetV2_x0_25.rknn") is False: + if model.initialize(args[1]) is False: print("Failed to initialize PaddleClas") exit(1) @@ -24,7 +30,7 @@ if __name__ == "__main__": result = model.predict(mat) end_time = time.time() - total_time_ms += (end_time - start_time) + total_time_ms += end_time - start_time read_index += 1 print(result.label_id, result.confidence) - print(f"FPS is {1.0 / (total_time_ms/read_index)}") \ No newline at end of file + print(f"FPS is {1.0 / (total_time_ms/read_index)}")