125 lines
3.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// FindCamera.cpp
/* @brief本示例向用户演示如何搜索可用相机设备。
*
* @briefThis example shows users how to find available cameras. */
#include <Windows.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include "IKapC.h"
#pragma comment(lib, "IKapC.lib")
/* @brief判断函数是否成功调用。
* @param[in] errc函数返回值。
*
* @briefDetermine whether the function is called successfully.
* @param[in] errcFunction return value. */
#define CHECK(errc) \
if (ITKSTATUS_OK != errc) \
printErrorAndExit(errc)
/* @brief用户输入回车键后退出程序。
*
* @briefUsers enter Enter to exit the program. */
void pressEnterToExit(void);
/* @brief打印错误信息后退出程序。
* @param[in] errc函数返回值。
*
* @briefPrint error message and exit the program.
* @param[in] errcFunction return value. */
void printErrorAndExit(ITKSTATUS errc);
int main(void)
{
// IKapC 函数返回值。
//
// Return value of IKapC functions.
ITKSTATUS res = ITKSTATUS_OK;
// 可用设备的数量。
//
// The number of available devices.
uint32_t numDevices = 0;
printf("Itek Console Find Camera Example (C version)\n");
// 初始化 IKapC 运行环境。
//
// Initialize IKapC runtime environment.
res = ItkManInitialize();
CHECK(res);
// 枚举可用设备的数量。在打开设备前,必须调用 ItkManGetDeviceCount() 函数。
//
// Enumerate the number of available devices. Before opening the device, ItkManGetDeviceCount() function must be called.
res = ItkManGetDeviceCount(&numDevices);
CHECK(res);
// 当没有连接的设备时。
//
// When there is no connected devices.
if (numDevices == 0) {
fprintf(stderr, "No device.\n");
ItkManTerminate();
pressEnterToExit();
exit(EXIT_FAILURE);
}
// 打印连接的相机设备的信息。
//
// Print information of connected cameras.
uint32_t i = 0;
for (; i < numDevices; ++i) {
// 相机信息结构体。
//
// Camera information structure.
ITKDEV_INFO di;
// 获取设备信息。
//
// Get device information.
ItkManGetDeviceInfo(i, &di);
// 打印设备信息
//
// Print information.
printf(
"Device Full Name:%s\n Friendly Name:%s\n Vendor Name:%s\n Model Name:%s\n Serial Name:%s\n Device Class:%s\n "
"Device Version:%s\n User Defined Name:%s\n\n",
di.FullName, di.FriendlyName, di.VendorName, di.ModelName, di.SerialNumber, di.DeviceClass, di.DeviceVersion,
di.UserDefinedName);
}
// 释放 IKapC 运行环境。
//
// Release IKapC runtime environment.
ItkManTerminate();
pressEnterToExit();
return EXIT_SUCCESS;
}
// 打印错误信息后退出程序。
//
// Print error message and exit the program.
void printErrorAndExit(ITKSTATUS errc)
{
fprintf(stderr, "Error Code:%08x\n", errc);
ItkManTerminate();
pressEnterToExit();
exit(EXIT_FAILURE);
}
// 用户输入回车键后退出程序。
//
// Users enter Enter to exit the program.
void pressEnterToExit(void)
{
fprintf(stderr, "\nPress enter to exit.\n");
while (getchar() != '\n')
;
}