江南体育最新官方链接

江南体育最新官方链接

  • 查找并打开设备

    本文内容

    ● 发现已连接设备数

    ● 打开设备

    ● 识别特定设备

    ● 打开默认设备

    ● 后续步骤

    本文介绍如何查找然后打开 Femto Bolt。 本文将解释如何处理有多个设备连接到计算机的情况。

    你还可以参考 ,其中演示了如何使用本文所述的函数。


    本文将介绍以下函数:

    ● 

    ● 

    ● 

    ● 


    发现已连接的设备数

    首先使用  获取当前已连接的 Femto Bolt 设备数。

     

    打开设备

    若要获取设备的相关信息或从中读取数据,首先需要使用  打开该设备的句柄。

    k4a_device_t device = NULL;
    for (uint8_t deviceIndex = 0; deviceIndex < device_count; deviceIndex++)
    {
        if (K4A_RESULT_SUCCEEDED != k4a_device_open(deviceIndex, &device))
        {
            printf("%d: Failed to open device\n", deviceIndex);
            continue;
        }
        ...
        k4a_device_close(device);
    }

     的 index&nbsp;参数指示当连接了多个设备时要打开哪个设备。 如果你预期只会连接一个设备,可以传递 K4A_DEVICE_DEFAULT 的参数或 0 来指示第一台设备。

    用完句柄后,每当打开设备时,都需要调用 。 在关闭句柄之前,无法打开同一设备的其他句柄。


    识别特定的设备

    在附加或分离设备之前,设备按索引枚举的顺序不会更改。 若要识别物理设备,应使用设备的序列号。

    若要读取设备中的序列号,请在打开句柄后使用  函数。此示例演示如何分配适量内存来存储序列号。

    char *serial_number = NULL;
    size_t serial_number_length = 0;
    if (K4A_BUFFER_RESULT_TOO_SMALL != k4a_device_get_serialnum(device, NULL, &serial_number_length))
    {
        printf("%d: Failed to get serial number length\n", deviceIndex);
        k4a_device_close(device);
        device = NULL;
        continue;
    }
    serial_number = malloc(serial_number_length);
    if (serial_number == NULL)
    {
        printf("%d: Failed to allocate memory for serial number (%zu bytes)\n", deviceIndex, serial_number_length);
        k4a_device_close(device);
        device = NULL;
        continue;
    }
    if (K4A_BUFFER_RESULT_SUCCEEDED != k4a_device_get_serialnum(device, serial_number, &serial_number_length))
    {
        printf("%d: Failed to get serial number\n", deviceIndex);
        free(serial_number);
        serial_number = NULL;
        k4a_device_close(device);
        device = NULL;
        continue;
    }
    printf("%d: Device \"%s\"\n", deviceIndex, serial_number);


    打开默认设备

    在大多数应用程序中,只会将单个Femto Bolt 附加到同一台计算机。 如果预期只需连接单个设备,可以结合 K4A_DEVICE_DEFAULT 的 index 调用  打开第一台设备。

    k4a_device_t device = NULL;
    uint32_t device_count = k4a_device_get_installed_count();
    if (device_count != 1)
    {
        printf("Unexpected number of devices found (%d)\n", device_count);
        goto Exit;
    }
    if (K4A_RESULT_SUCCEEDED != k4a_device_open(K4A_DEVICE_DEFAULT, &device))
    {
        printf("Failed to open device\n");
        goto Exit;
    }


    后续步骤

    获取图像数据