// CameraFeature.c /* @brief: This example shows users how to access camera features. * @note: The program demonstrates feature list retrieval function, access mode, data type, feature value getting function, and feature value setting function. */ #include #include #include "IKapC.h" /* @brief: Determine whether the function is called successfully. * @param[in] errc: Function return value. */ #define CHECK(errc) if (ITKSTATUS_OK != errc) printErrorAndExit(errc) // Camera device handle. ITKDEVICE g_hCamera; /* @brief: Users enter Enter to exit the program. */ void pressEnterToExit(void); /* @brief: Print error message and exit the program. * @param[in] errc: Function return value. */ void printErrorAndExit(ITKSTATUS errc); /* @brief: Enumerate all camera device features. */ void enumAllFeatures(); /* @brief: Set Int32 type feature value. * @param[in] featureName: Feature name. * @param[in] nValue: Feature value. */ void setFeatureInt32(const char *featureName, int32_t nValue); /* @brief: Get Int32 type feature value. * @param[in] featureName: Feature name. * @param[out] pValue: Feature value. */ void getFeatureInt32(const char *featureName, int32_t *pValue); /* @brief: Set Int64 type feature value. * @param[in] featureName: Feature name. * @param[in] nValue: Feature value. */ void setFeatureInt64(const char *featureName, int64_t nValue); /* @brief: Get Int64 type feature value. * @param[in] featureName: Feature name. * @param[out] pValue: Feature value. */ void getFeatureInt64(const char *featureName, int64_t *pValue); /* @brief: Set double type feature value. * @param[in] featureName: Feature name. * @param[in] fValue: Feature value. */ void setFeatureDouble(const char *featureName, double fValue); /* @brief: Get double type feature value. * @param[in] featureName: Feature name. * @param[out] pValue: Feature value. */ void getFeatureDouble(const char *featureName, double *pValue); /* @brief: Set boolean type feature value. * @param[in] featureName: Feature name. * @param[in] bValue: Feature value. */ void setFeatureBool(const char *featureName, uint8_t bValue); /* @brief: Get boolean type feature value. * @param[in] featureName: Feature name. * @param[out] pValue: Feature value. */ void getFeatureBool(const char *featureName, uint8_t *pValue); /* @brief: Set string type feature value. * @param[in] featureName: Feature name. * @param[in] strValue: Feature value. */ void setFeatureStr(const char *featureName, const char *strValue); /* @brief: Get string type feature value. * @param[in] featureName: Feature name. * @param[out] strValue: Feature value. * @param[in,out] pValueLen: The length of feature value. */ void getFeatureStr(const char *featureName, char *strValue, uint32_t *pValueLen); /* @brief: Set enum type feature value. * @param[in] featureName: Feature name. * @param[in] strValue: Feature value. */ void setFeatureEnum(const char *featureName, const char *strValue); /* @brief: Get enum type feature value. * @param[in] featureName: Feature name. * @param[out] strValue: Feature value. * @param[in,out] pValueLen: The length of feature value. */ void getFeatureEnum(const char *featureName, char *strValue, uint32_t *pValueLen); /* @brief: Set command type feature value. * @param[in] featureName: Feature name. */ void setFeatureCommand(const char *featureName); /* @brief: This function is registered as a callback function. When feature value is changed, the function will be called. * @param[in] hDev: Device handle. */ void demonstrateFeatureValueChanged(ITKDEVICE hDev); /* @brief: This function is registered as a callback function. When feature value is changed, the function will be called. * @param[in] context: Input parameter. * @param[in] eventInfo: Event information handle. */ void IKAPC_CC featureValueChangeCallback(void *context, ITKEVENTINFO eventInfo); /* @brief: This function is registered as a callback function. When the connected device goes offline, the function will be called. * @param[in] hDev: Device handle. */ void demonstrateCameraRemove(ITKDEVICE hDev); /* @brief: This function is registered as a callback function. When the connected device goes offline, the function will be called. * @param[in] context: Input parameter. * @param[in] eventInfo: Event information handle. */ void IKAPC_CC removalCallbackFunction(void *context, ITKEVENTINFO eventInfo); int main(void) { // Return value of IKapC functions. ITKSTATUS res; // The number of available devices. uint32_t numDevices = 0; // The index of device to be opened. uint32_t devIndex = 0; // Initialize IKapC runtime environment. res = ItkManInitialize(); CHECK(res); // 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); } // Open the device and get the handle of the device. res = ItkDevOpen(devIndex, ITKDEV_VAL_ACCESS_MODE_CONTROL, &g_hCamera); CHECK(res); // Enumerate all camera device features. enumAllFeatures(); // This function is registered as a callback function. When feature value is changed, the function will be called. demonstrateFeatureValueChanged(g_hCamera); // This function is registered as a callback function. When the connected device goes offline, the function will be called. demonstrateCameraRemove(g_hCamera); getchar(); // 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'); } // Enumerate all camera device features. void enumAllFeatures() { ITKSTATUS res = ITKSTATUS_OK; // The number of device features. uint32_t nFeatureCount = 0; // Feature name. char featureName[128]; // The length of feature name. uint32_t featureNameLen = 128; // Feature handle. ITKFEATURE hFeature = NULL; // The type of feature. uint32_t featureType = ITKFEATURE_VAL_TYPE_UNDEFINED; // Get the number of device features. res = ItkDevGetFeatureCount(g_hCamera, &nFeatureCount); CHECK(res); for (uint32_t i = 0;i < nFeatureCount;i++) { featureNameLen = 128; // Get the name of feature. res = ItkDevGetFeatureName(g_hCamera, i, featureName, &featureNameLen); CHECK(res); // Allocate feature handle. res = ItkDevAllocFeature(g_hCamera, featureName, &hFeature); CHECK(res); // Get the type of feature. res = ItkFeatureGetType(hFeature, &featureType); CHECK(res); printf("Feature Name : %s feature type : %d\n", featureName, featureType); // Free feature handle. res = ItkDevFreeFeature(hFeature); CHECK(res); } } // Set Int32 type feature value. void setFeatureInt32(const char *featureName, int32_t nValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevSetInt32(g_hCamera, featureName, nValue); CHECK(res); } // Get Int32 type feature value. void getFeatureInt32(const char *featureName, int32_t *pValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevGetInt32(g_hCamera, featureName, pValue); CHECK(res); } // Set Int64 type feature value. void setFeatureInt64(const char *featureName, int64_t nValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevSetInt64(g_hCamera, featureName, nValue); CHECK(res); } // Get Int64 type feature value. void getFeatureInt64(const char *featureName, int64_t *pValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevGetInt64(g_hCamera, featureName, pValue); CHECK(res); } // Set double type feature value. void setFeatureDouble(const char *featureName, double fValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevSetDouble(g_hCamera, featureName, fValue); CHECK(res); } // Get double type feature value. void getFeatureDouble(const char *featureName, double *pValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevGetDouble(g_hCamera, featureName, pValue); CHECK(res); } // Set boolean type feature value. void setFeatureBool(const char *featureName, uint8_t bValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevSetBool(g_hCamera, featureName, bValue); CHECK(res); } // Get boolean type feature value. void getFeatureBool(const char *featureName, uint8_t *pValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevGetBool(g_hCamera, featureName, pValue); CHECK(res); } // Set string type feature value. void setFeatureStr(const char *featureName, const char *strValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevFromString(g_hCamera, featureName, strValue); CHECK(res); } // Get string type feature value. void getFeatureStr(const char *featureName, char *strValue, uint32_t *pValueLen) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevToString(g_hCamera, featureName, strValue, pValueLen); CHECK(res); } // Set enum type feature value. void setFeatureEnum(const char *featureName, const char *strValue) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevFromString(g_hCamera, featureName, strValue); CHECK(res); } // Get enum type feature value. void getFeatureEnum(const char *featureName, char *strValue, uint32_t *pValueLen) { ITKSTATUS res = ITKSTATUS_OK; // Enumeration name. char enumName[128]; // Enumeration name length. uint32_t enumNameLen = 128; // The number of enumeration. uint32_t featureValueCount = 0; // Get the number enumerations. res = ItkDevGetEnumCount(g_hCamera, featureName, &featureValueCount); CHECK(res); for (uint32_t i = 0; i < featureValueCount; i++) { enumNameLen = 128; // Get the name enumeration. res = ItkDevGetEnumString(g_hCamera, featureName, i, enumName, &enumNameLen); CHECK(res); printf("Enum string %d value %s\n",i,enumName); } // Set enum type feature value. res = ItkDevFromString(g_hCamera, featureName, strValue); CHECK(res); } // Set command type feature value. void setFeatureCommand(const char *featureName) { ITKSTATUS res = ITKSTATUS_OK; res = ItkDevExecuteCommand(g_hCamera, featureName); CHECK(res); } // This function is registered as a callback function. When feature value is changed, the function will be called. void demonstrateFeatureValueChanged(ITKDEVICE hDev) { ITKSTATUS res; // Register callback function. res = ItkDevRegisterCallback(hDev, "FeatureValueChanged", featureValueChangeCallback, hDev); CHECK(res); } // This function is registered as a callback function. When the connected device goes offline, the function will be called. void demonstrateCameraRemove(ITKDEVICE hDev) { ITKSTATUS res; // Register callback function. res = ItkDevRegisterCallback(hDev, "DeviceRemove", removalCallbackFunction, hDev); CHECK(res); } // This function is registered as a callback function. When feature value is changed, the function will be called. void IKAPC_CC featureValueChangeCallback(void *context, ITKEVENTINFO eventInfo) { uint32_t type = 0, feature_name_length = 128; uint64_t countstamp = 0; char feature_name[128] = { 0 }; ITKDEVICE hDev = (ITKDEVICE)context; // Get the event type parameter value. ITKSTATUS res = ItkEventInfoGetPrm(eventInfo, ITKEVENTINFO_PRM_TYPE, &type); CHECK(res); // Get the event name parameter value. res = ItkEventInfoGetPrm(eventInfo, ITKEVENTINFO_PRM_FEATURE_NAME, feature_name); CHECK(res); int nType = strlen(feature_name); // Get the event time stamp parameter value. res = ItkEventInfoGetPrm(eventInfo, ITKEVENTINFO_PRM_HOST_TIME_STAMP, &countstamp); CHECK(res); // Determine the type bit and print information. #if __STDC_VERSION__ >= 199901L printf("OnFeatureValueChangeCallback, feature: %s, type: %0d, time: %lld.\n",feature_name, nType, countstamp); #else printf("OnFeatureValueChangeCallback, feature: %s, type: %0d, time: %I64d.\n",feature_name, nType, countstamp); #endif } // This function is registered as a callback function. When the connected device goes offline, the function will be called. void IKAPC_CC removalCallbackFunction(void *context, ITKEVENTINFO eventInfo) { uint32_t type = 0; uint64_t countstamp = 0; ITKDEVICE hDev = (ITKDEVICE)context; // Get the event type parameter value. ITKSTATUS res = ItkEventInfoGetPrm(eventInfo, ITKEVENTINFO_PRM_TYPE, &type); CHECK(res); // Get the event time stamp parameter value. res = ItkEventInfoGetPrm(eventInfo, ITKEVENTINFO_PRM_HOST_TIME_STAMP, &countstamp); CHECK(res); // Determine the type bit and print information. #if __STDC_VERSION__ >= 199901L printf("removalCallbackFunction, type: %08X, time: %lld.\n",type, countstamp); #else printf("\nremovalCallbackFunction, type: %08X, time: %I64d.\n",type, countstamp); #endif }