# 设备信息

此示例展示如何查询设备信息。

代码的第一部分查询所有可用的设备，而不实际启动任何设备。对于每个找到的设备，它会打印以下信息：

 * 设备名称：如果是 OAK PoE 相机，则为 IP；如果是 OAK USB 相机，则为 USB 路径
 * MxId：唯一的 Mx (芯片) 识别码
 * 状态：设备的状态。注意，OAK PoE 相机具有已刷新的引导加载程序，用于初始化网络堆栈

之后，示例启动第一个找到的设备，打印可用的相机传感器，并读取存储产品和板名称的校准和 eeprom 数据。

## 演示

```bash
Searching for all available devices...

Found device '1.3', MxId: '18443010D116631200', State: 'UNBOOTED'
Found device '192.168.33.201', MxId: '184430102163DB0F00', State: 'BOOTLOADER'
Found device '192.168.33.192', MxId: '1844301011F4C51200', State: 'BOOTLOADER'

Booting the first available camera (1.3)...
Available camera sensors:  {<CameraBoardSocket.CAM_C: 2>: 'OV9282', <CameraBoardSocket.CAM_A: 0>: 'IMX378', <CameraBoardSocket.CAM_B: 1>: 'OV9282'}
Product name: OAK-D Pro AF, board name DM9098
```

## 设置

请运行[安装脚本](https://github.com/luxonis/depthai-python/blob/main/examples/install_requirements.py)以下载所有必需的依赖项。请注意，此脚本必须在 git
上下文中运行，因此您需要先下载 [depthai-python](https://github.com/luxonis/depthai-python) 仓库，然后运行该脚本。

```bash
git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py
```

更多信息，请参考[安装指南](https://docs.luxonis.com/software/depthai/manual-install.md)。

## 源代码

#### Python

```python
import depthai as dai
from typing import List

print('Searching for all available devices...\n')
# Query all available devices (USB and POE OAK cameras)
infos: List[dai.DeviceInfo] = dai.DeviceBootloader.getAllAvailableDevices()

if len(infos) == 0:
    print("Couldn't find any available devices.")
    exit(-1)

for info in infos:
    # Converts enum eg. 'XLinkDeviceState.X_LINK_UNBOOTED' to 'UNBOOTED'
    state = str(info.state).split('X_LINK_')[1]

    print(f"Found device '{info.name}', MxId: '{info.mxid}', State: '{state}'")

# Connect to a specific device. We will just take the first one
print(f"\nBooting the first available camera ({infos[0].name})...")
with dai.Device(dai.Pipeline(), infos[0], usb2Mode=False) as device:
    print("Available camera sensors: ", device.getCameraSensorNames())
    calib = device.readCalibration()
    eeprom = calib.getEepromData()
    print(f"Product name: {eeprom.productName}, board name {eeprom.boardName}")
```

#### C++

```cpp
#include <iostream>

// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"

int main() {
    std::cout << "Searching for all available devices...\n\n";
    auto infos = dai::Device::getAllAvailableDevices();

    if(infos.size() <= 0) {
        std::cout << "Couldn't find any available devices.\n";
        return -1;
    }

    for(auto& info : infos) {
        std::cout << "Found device: " << info.name << " mxid: " << info.mxid << " state: " << info.state << std::endl;
    }

    // Connect to device and start pipeline
    std::cout << "\nBooting the first available camera (" << infos[0].name << ")...\n";
    dai::Device device(dai::Pipeline(), infos[0]);
    std::cout << "Available camera sensors: ";
    for(auto& sensor : device.getCameraSensorNames()) {
        std::cout << "Socket: " << sensor.first << " - " << sensor.second << ", ";
    }
    std::cout << std::endl;

    auto eeprom = device.readCalibration2().getEepromData();
    std::cout << "Product name: " << eeprom.productName << ", board name: " << eeprom.boardName << std::endl;

    return 0;
}
```

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
