DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
此页面由 AI 自动翻译。查看英文原版
DepthAI 教程
DepthAI API 参考

本页目录

  • Demo
  • Setup
  • Source code

Flash User Bootloader

此脚本将用户引导加载程序刷入连接的 OAK 相机。只能刷入具有板载闪存的设备。

Demo

示例脚本输出
Command Line
1~/depthai-python/examples/bootloader$ python3 flash_user_bootloader.py
2    [0] 1844301041C83D0E00 [X_LINK_USB_VSC] current bootloader: 0.0.26
3    Which DepthAI device to flash User Bootloader for (Note: Only NETWORK supported) [0..0]: 0
4    User Bootloader version to flash: 0.0.26
5    Flashing User Bootloader...
6    Flashing progress: 0.0%
7    Flashing progress: 18.8%
8    Flashing progress: 31.2%
9    Flashing progress: 48.2%
10    Flashing progress: 94.2%
11    Flashing progress: 100.0%
12    Flashing successful. Took 7.55600329185836 seconds

Setup

请运行 安装脚本 以下载所有必需的依赖项。请注意,此脚本必须在 git 上下文中运行,因此您必须先下载 depthai-python 存储库,然后运行脚本
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
有关更多信息,请遵循 安装指南

Source code

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import depthai as dai
4import sys
5import time
6
7deviceInfos = dai.DeviceBootloader.getAllAvailableDevices()
8if len(deviceInfos) == 0:
9    print("No device found to flash. Exiting.")
10    exit(-1)
11else:
12    for i, di in enumerate(deviceInfos):
13        print(f'[{i}] {di.getMxId()} [{di.protocol.name}]', end='')
14        if di.state == dai.XLinkDeviceState.X_LINK_BOOTLOADER:
15            with dai.DeviceBootloader(di) as bl:
16                print(f' current bootloader: {bl.getVersion()}', end='')
17        print()
18    selected = input(f'Which DepthAI device to flash User Bootloader for (Note: Only NETWORK supported) [0..{len(deviceInfos)-1}]: ')
19    info = deviceInfos[int(selected)]
20
21# Open DeviceBootloader and allow flashing bootloader
22with dai.DeviceBootloader(info) as bl:
23    print("User Bootloader version to flash:", bl.getVersion())
24
25    # Create a progress callback lambda
26    progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')
27
28    print(f"Flashing User Bootloader...")
29    startTime = time.monotonic()
30    (res, message) = bl.flashUserBootloader(progress)
31    if res:
32        print("Flashing successful. Took", time.monotonic() - startTime, "seconds")
33    else:
34        print("Flashing failed:", message)

C++

1#include <chrono>
2#include <string>
3
4#include "XLink/XLink.h"
5#include "depthai/depthai.hpp"
6#include "depthai/xlink/XLinkConnection.hpp"
7
8static const char* ProtocolToStr(XLinkProtocol_t val) {
9    switch(val) {
10        case X_LINK_USB_VSC:
11            return "X_LINK_USB_VSC";
12        case X_LINK_USB_CDC:
13            return "X_LINK_USB_CDC";
14        case X_LINK_PCIE:
15            return "X_LINK_PCIE";
16        case X_LINK_IPC:
17            return "X_LINK_IPC";
18        case X_LINK_TCP_IP:
19            return "X_LINK_TCP_IP";
20        case X_LINK_NMB_OF_PROTOCOLS:
21            return "X_LINK_NMB_OF_PROTOCOLS";
22        case X_LINK_ANY_PROTOCOL:
23            return "X_LINK_ANY_PROTOCOL";
24        default:
25            return "INVALID_ENUM_VALUE";
26            break;
27    }
28}
29
30int main(int argc, char** argv) try {
31    using namespace std::chrono;
32
33    dai::DeviceInfo info;
34    auto deviceInfos = dai::DeviceBootloader::getAllAvailableDevices();
35    if(deviceInfos.empty()) {
36        std::cout << "No device found to flash. Exiting." << std::endl;
37        return -1;
38    } else {
39        for(int i = 0; i < deviceInfos.size(); i++) {
40            const auto& devInfo = deviceInfos[i];
41            std::cout << "[" << i << "] " << devInfo.getMxId() << "[" << ProtocolToStr(devInfo.protocol) << "]";
42            if(devInfo.state == X_LINK_BOOTLOADER) {
43                dai::DeviceBootloader bl(devInfo);
44                std::cout << " current bootloader: " << bl.getVersion();
45            }
46            std::cout << std::endl;
47        }
48        int selected = 0;
49        std::cout << "Which DepthAI device to flash bootloader for (Note: Only NETWORK supported) [0.." << deviceInfos.size() - 1 << "]\n";
50        std::cin >> selected;
51        info = deviceInfos[selected];
52    }
53
54    dai::DeviceBootloader bl(info);
55
56    // Create a progress callback lambda
57    auto progress = [](float p) { std::cout << "Flashing Progress..." << p * 100 << "%" << std::endl; };
58
59    std::cout << "Flashing User Bootloader..." << std::endl;
60    auto t1 = steady_clock::now();
61    bool success = false;
62    std::string message;
63    std::tie(success, message) = bl.flashUserBootloader(progress);
64    if(success) {
65        std::cout << "Flashing successful. Took " << duration_cast<milliseconds>(steady_clock::now() - t1).count() << "ms" << std::endl;
66    } else {
67        std::cout << "Flashing failed: " << message << std::endl;
68    }
69    return 0;
70} catch(const std::exception& ex) {
71    std::cout << "Exception: " << ex.what() << std::endl;
72}

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。